Skip to content

Commit bf752f1

Browse files
committed
Add sample/detect_relations
1 parent 80c346f commit bf752f1

21 files changed

+1742
-0
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ db: db_sqlite
2626
usql pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable -f testdata/pg.sql
2727
usql my://root:mypass@localhost:33306/testdb -f testdata/my.sql
2828
usql my://root:mypass@localhost:33308/testdb -f testdata/my.sql
29+
usql my://root:mypass@localhost:33308/testdb -c "CREATE DATABASE IF NOT EXISTS norelation;"
30+
usql my://root:mypass@localhost:33308/norelation -f testdata/no-relation.sql
2931
usql ms://SA:MSSQLServer-Passw0rd@localhost:11433/master -c "IF NOT EXISTS (SELECT * FROM sys.databases WHERE NAME = 'testdb') CREATE DATABASE testdb;"
3032
usql ms://SA:MSSQLServer-Passw0rd@localhost:11433/testdb -f testdata/mssql.sql
3133
./testdata/dynamodb.sh > /dev/null 2>&1
@@ -41,6 +43,7 @@ doc: build doc_sqlite
4143
./tbls doc pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable -c testdata/test_tbls_postgres.yml -f sample/postgres
4244
./tbls doc my://root:mypass@localhost:33306/testdb -c testdata/test_tbls.yml -f sample/mysql
4345
./tbls doc my://root:mypass@localhost:33308/testdb -c testdata/test_tbls.yml -f sample/mysql8
46+
./tbls doc my://root:mypass@localhost:33308/norelation -c testdata/test_tbls_detect_relations.yml -f sample/detect_relations
4447
./tbls doc ms://SA:MSSQLServer-Passw0rd@localhost:11433/testdb -c testdata/test_tbls_mssql.yml -f sample/mssql
4548
env AWS_ENDPOINT_URL=http://localhost:18000 ./tbls doc dynamodb://ap-northeast-1 -c testdata/test_tbls_dynamodb.yml -f sample/dynamodb
4649
./tbls doc pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable -c testdata/test_tbls_postgres.yml -j -f sample/adjust
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# CamelizeTable
2+
3+
## Description
4+
5+
<details>
6+
<summary><strong>Table Definition</strong></summary>
7+
8+
```sql
9+
CREATE TABLE `CamelizeTable` (
10+
`id` bigint NOT NULL AUTO_INCREMENT,
11+
`created` datetime NOT NULL,
12+
PRIMARY KEY (`id`)
13+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
14+
```
15+
16+
</details>
17+
18+
## Columns
19+
20+
| Name | Type | Default | Nullable | Children | Parents | Comment |
21+
| ---- | ---- | ------- | -------- | -------- | ------- | ------- |
22+
| id | bigint | | false | | | |
23+
| created | datetime | | false | | | |
24+
25+
## Constraints
26+
27+
| Name | Type | Definition |
28+
| ---- | ---- | ---------- |
29+
| PRIMARY | PRIMARY KEY | PRIMARY KEY (id) |
30+
31+
## Indexes
32+
33+
| Name | Definition |
34+
| ---- | ---------- |
35+
| PRIMARY | PRIMARY KEY (id) USING BTREE |
36+
37+
## Relations
38+
39+
![er](CamelizeTable.svg)
40+
41+
---
42+
43+
> Generated by [tbls](https://github.com/k1LoW/tbls)
Lines changed: 29 additions & 0 deletions
Loading

sample/detect_relations/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# norelation
2+
3+
## Description
4+
5+
Sample database document.
6+
7+
## Labels
8+
9+
`sample` `tbls`
10+
11+
## Tables
12+
13+
| Name | Columns | Comment | Type |
14+
| ---- | ------- | ------- | ---- |
15+
| [CamelizeTable](CamelizeTable.md) | 2 | | BASE TABLE |
16+
| [comment_stars](comment_stars.md) | 6 | | BASE TABLE |
17+
| [comments](comments.md) | 6 | Comments<br>Multi-line<br>table<br>comment | BASE TABLE |
18+
| [hyphen-table](hyphen-table.md) | 3 | | BASE TABLE |
19+
| [logs](logs.md) | 7 | Auditログ | BASE TABLE |
20+
| [post_comments](post_comments.md) | 7 | post and comments View table | VIEW |
21+
| [posts](posts.md) | 7 | Posts table | BASE TABLE |
22+
| [users](users.md) | 6 | Users table | BASE TABLE |
23+
24+
## Relations
25+
26+
![er](schema.svg)
27+
28+
---
29+
30+
> Generated by [tbls](https://github.com/k1LoW/tbls)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# comment_stars
2+
3+
## Description
4+
5+
<details>
6+
<summary><strong>Table Definition</strong></summary>
7+
8+
```sql
9+
CREATE TABLE `comment_stars` (
10+
`id` bigint NOT NULL AUTO_INCREMENT,
11+
`user_id` int NOT NULL,
12+
`comment_post_id` bigint NOT NULL,
13+
`comment_user_id` int NOT NULL,
14+
`created` timestamp NOT NULL,
15+
`updated` timestamp NULL DEFAULT NULL,
16+
PRIMARY KEY (`id`),
17+
UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`)
18+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
19+
```
20+
21+
</details>
22+
23+
## Columns
24+
25+
| Name | Type | Default | Nullable | Children | Parents | Comment |
26+
| ---- | ---- | ------- | -------- | -------- | ------- | ------- |
27+
| id | bigint | | false | [logs](logs.md) | | |
28+
| user_id | int | | false | | [users](users.md) | |
29+
| comment_post_id | bigint | | false | | | |
30+
| comment_user_id | int | | false | | | |
31+
| created | timestamp | | false | | | |
32+
| updated | timestamp | | true | | | |
33+
34+
## Constraints
35+
36+
| Name | Type | Definition |
37+
| ---- | ---- | ---------- |
38+
| PRIMARY | PRIMARY KEY | PRIMARY KEY (id) |
39+
| user_id | UNIQUE | UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) |
40+
41+
## Indexes
42+
43+
| Name | Definition |
44+
| ---- | ---------- |
45+
| PRIMARY | PRIMARY KEY (id) USING BTREE |
46+
| user_id | UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE |
47+
48+
## Relations
49+
50+
![er](comment_stars.svg)
51+
52+
---
53+
54+
> Generated by [tbls](https://github.com/k1LoW/tbls)
Lines changed: 112 additions & 0 deletions
Loading

sample/detect_relations/comments.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# comments
2+
3+
## Description
4+
5+
Comments
6+
Multi-line
7+
table
8+
comment
9+
10+
<details>
11+
<summary><strong>Table Definition</strong></summary>
12+
13+
```sql
14+
CREATE TABLE `comments` (
15+
`id` bigint NOT NULL AUTO_INCREMENT,
16+
`post_id` bigint NOT NULL,
17+
`user_id` int NOT NULL,
18+
`comment` text NOT NULL COMMENT 'Comment\nMulti-line\r\ncolumn\rcomment',
19+
`created` datetime NOT NULL,
20+
`updated` datetime DEFAULT NULL,
21+
PRIMARY KEY (`id`),
22+
UNIQUE KEY `post_id` (`post_id`,`user_id`),
23+
KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`)
24+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\nMulti-line\r\ntable\rcomment'
25+
```
26+
27+
</details>
28+
29+
## Columns
30+
31+
| Name | Type | Default | Nullable | Children | Parents | Comment |
32+
| ---- | ---- | ------- | -------- | -------- | ------- | ------- |
33+
| id | bigint | | false | [logs](logs.md) | | |
34+
| post_id | bigint | | false | | [posts](posts.md) | |
35+
| user_id | int | | false | | [users](users.md) | |
36+
| comment | text | | false | | | Comment<br>Multi-line<br>column<br>comment |
37+
| created | datetime | | false | | | |
38+
| updated | datetime | | true | | | |
39+
40+
## Constraints
41+
42+
| Name | Type | Definition |
43+
| ---- | ---- | ---------- |
44+
| post_id | UNIQUE | UNIQUE KEY post_id (post_id, user_id) |
45+
| PRIMARY | PRIMARY KEY | PRIMARY KEY (id) |
46+
47+
## Indexes
48+
49+
| Name | Definition |
50+
| ---- | ---------- |
51+
| comments_post_id_user_id_idx | KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE |
52+
| PRIMARY | PRIMARY KEY (id) USING BTREE |
53+
| post_id | UNIQUE KEY post_id (post_id, user_id) USING BTREE |
54+
55+
## Relations
56+
57+
![er](comments.svg)
58+
59+
---
60+
61+
> Generated by [tbls](https://github.com/k1LoW/tbls)

0 commit comments

Comments
 (0)