diff --git a/datasource/datasource_test.go b/datasource/datasource_test.go
index 8f67f6f2c..ca1704ffa 100644
--- a/datasource/datasource_test.go
+++ b/datasource/datasource_test.go
@@ -12,8 +12,8 @@ var tests = []struct {
tableCount int
relationCount int
}{
- {"my://root:mypass@localhost:33306/testdb", 7, 5},
- {"pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable", 8, 6},
+ {"my://root:mypass@localhost:33306/testdb", 8, 6},
+ {"pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable", 9, 7},
{"json://../testdata/testdb.json", 7, 9},
}
diff --git a/drivers/mysql/mysql.go b/drivers/mysql/mysql.go
index 99c4951a7..4f43a2a92 100644
--- a/drivers/mysql/mysql.go
+++ b/drivers/mysql/mysql.go
@@ -150,10 +150,11 @@ LEFT JOIN
kcu.table_name,
kcu.constraint_name,
kcu.column_name,
- (CASE WHEN c.column_key='PRI' THEN 'PRIMARY KEY'
+ (CASE WHEN c.column_key='PRI' AND kcu.referenced_table_name IS NULL THEN 'PRIMARY KEY'
WHEN c.column_key='UNI' THEN 'UNIQUE'
WHEN c.column_key='MUL' AND kcu.referenced_table_name IS NULL THEN 'UNIQUE'
WHEN c.column_key='MUL' AND kcu.referenced_table_name IS NOT NULL THEN 'FOREIGN KEY'
+ WHEN c.column_key='PRI' AND kcu.referenced_table_name IS NOT NULL THEN 'FOREIGN KEY'
ELSE 'UNKNOWN'
END) AS costraint_type
FROM information_schema.key_column_usage AS kcu
diff --git a/sample/adjust/README.md b/sample/adjust/README.md
index ebd19f77c..ab1d0aeb3 100644
--- a/sample/adjust/README.md
+++ b/sample/adjust/README.md
@@ -5,6 +5,7 @@
| Name | Columns | Comment | Type |
| --------------------------------------------- | ------- | ------------------------------------------ | ---------- |
| [users](users.md) | 6 | Users table | BASE TABLE |
+| [user_options](user_options.md) | 4 | User options table | BASE TABLE |
| [posts](posts.md) | 8 | Posts table | BASE TABLE |
| [comments](comments.md) | 6 | Comments
Multi-line
table
comment | BASE TABLE |
| [comment_stars](comment_stars.md) | 6 | | BASE TABLE |
diff --git a/sample/adjust/schema.png b/sample/adjust/schema.png
index 3ab873ea2..a64ef4645 100644
Binary files a/sample/adjust/schema.png and b/sample/adjust/schema.png differ
diff --git a/sample/adjust/user_options.md b/sample/adjust/user_options.md
new file mode 100644
index 000000000..dcbb175a6
--- /dev/null
+++ b/sample/adjust/user_options.md
@@ -0,0 +1,35 @@
+# user_options
+
+## Description
+
+User options table
+
+## Columns
+
+| Name | Type | Default | Nullable | Children | Parents | Comment |
+| ---------- | --------------------------- | ------- | -------- | -------- | ----------------- | ------- |
+| user_id | integer | | false | | [users](users.md) | |
+| show_email | boolean | false | false | | | |
+| created | timestamp without time zone | | false | | | |
+| updated | timestamp without time zone | | true | | | |
+
+## Constraints
+
+| Name | Type | Definition |
+| ----------------------- | ----------- | ------------------------------------------------------------ |
+| user_options_user_id_fk | FOREIGN KEY | FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE |
+| user_options_pkey | PRIMARY KEY | PRIMARY KEY (user_id) |
+
+## Indexes
+
+| Name | Definition |
+| ----------------- | ---------------------------------------------------------------------------------- |
+| user_options_pkey | CREATE UNIQUE INDEX user_options_pkey ON public.user_options USING btree (user_id) |
+
+## Relations
+
+
+
+---
+
+> Generated by [tbls](https://github.com/k1LoW/tbls)
diff --git a/sample/adjust/user_options.png b/sample/adjust/user_options.png
new file mode 100644
index 000000000..a57e5507a
Binary files /dev/null and b/sample/adjust/user_options.png differ
diff --git a/sample/adjust/users.md b/sample/adjust/users.md
index 0eefe5d75..cf858b4b7 100644
--- a/sample/adjust/users.md
+++ b/sample/adjust/users.md
@@ -6,14 +6,14 @@ Users table
## Columns
-| Name | Type | Default | Nullable | Children | Parents | Comment |
-| -------- | --------------------------- | --------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------- | ------- | -------------------- |
-| id | integer | nextval('users_id_seq'::regclass) | false | [posts](posts.md) [comments](comments.md) [comment_stars](comment_stars.md) [administrator.blogs](administrator.blogs.md) [logs](logs.md) | | |
-| username | varchar(50) | | false | | | |
-| password | varchar(50) | | false | | | |
-| email | varchar(355) | | false | | | ex. user@example.com |
-| created | timestamp without time zone | | false | | | |
-| updated | timestamp without time zone | | true | | | |
+| Name | Type | Default | Nullable | Children | Parents | Comment |
+| -------- | --------------------------- | --------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | -------------------- |
+| id | integer | nextval('users_id_seq'::regclass) | false | [user_options](user_options.md) [posts](posts.md) [comments](comments.md) [comment_stars](comment_stars.md) [administrator.blogs](administrator.blogs.md) [logs](logs.md) | | |
+| username | varchar(50) | | false | | | |
+| password | varchar(50) | | false | | | |
+| email | varchar(355) | | false | | | ex. user@example.com |
+| created | timestamp without time zone | | false | | | |
+| updated | timestamp without time zone | | true | | | |
## Constraints
diff --git a/sample/adjust/users.png b/sample/adjust/users.png
index 6cd72ffa7..7f9fbec1a 100644
Binary files a/sample/adjust/users.png and b/sample/adjust/users.png differ
diff --git a/sample/mysql/README.md b/sample/mysql/README.md
index 082e99a34..d03dba33b 100644
--- a/sample/mysql/README.md
+++ b/sample/mysql/README.md
@@ -10,6 +10,7 @@
| [logs](logs.md) | 7 | audit log table | BASE TABLE |
| [post_comments](post_comments.md) | 7 | post and comments View table | VIEW |
| [posts](posts.md) | 7 | Posts table | BASE TABLE |
+| [user_options](user_options.md) | 4 | User options table | BASE TABLE |
| [users](users.md) | 6 | Users table | BASE TABLE |
## Relations
diff --git a/sample/mysql/schema.png b/sample/mysql/schema.png
index 3538510c8..a5f9c192e 100644
Binary files a/sample/mysql/schema.png and b/sample/mysql/schema.png differ
diff --git a/sample/mysql/user_options.md b/sample/mysql/user_options.md
new file mode 100644
index 000000000..de0eec216
--- /dev/null
+++ b/sample/mysql/user_options.md
@@ -0,0 +1,51 @@
+# user_options
+
+## Description
+
+User options table
+
+
+Table Definition
+
+```sql
+CREATE TABLE `user_options` (
+ `user_id` int(11) NOT NULL,
+ `show_email` tinyint(1) NOT NULL DEFAULT '0',
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ `updated` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+ PRIMARY KEY (`user_id`),
+ CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='User options table'
+```
+
+
+
+## Columns
+
+| Name | Type | Default | Nullable | Children | Parents | Comment |
+| ---- | ---- | ------- | -------- | -------- | ------- | ------- |
+| user_id | int(11) | | false | | [users](users.md) | |
+| show_email | tinyint(1) | 0 | false | | | |
+| created | timestamp | CURRENT_TIMESTAMP | false | | | |
+| updated | timestamp | 0000-00-00 00:00:00 | false | | | |
+
+## Constraints
+
+| Name | Type | Definition |
+| ---- | ---- | ---------- |
+| PRIMARY | PRIMARY KEY | PRIMARY KEY (user_id) |
+| user_options_user_id_fk | FOREIGN KEY | FOREIGN KEY (user_id) REFERENCES users (id) |
+
+## Indexes
+
+| Name | Definition |
+| ---- | ---------- |
+| PRIMARY | PRIMARY KEY (user_id) USING BTREE |
+
+## Relations
+
+
+
+---
+
+> Generated by [tbls](https://github.com/k1LoW/tbls)
diff --git a/sample/mysql/user_options.png b/sample/mysql/user_options.png
new file mode 100644
index 000000000..cd0bf579d
Binary files /dev/null and b/sample/mysql/user_options.png differ
diff --git a/sample/mysql/users.md b/sample/mysql/users.md
index 6e5d47804..44681bef3 100644
--- a/sample/mysql/users.md
+++ b/sample/mysql/users.md
@@ -27,7 +27,7 @@ CREATE TABLE `users` (
| Name | Type | Default | Nullable | Children | Parents | Comment |
| ---- | ---- | ------- | -------- | -------- | ------- | ------- |
-| id | int(11) | | false | [comment_stars](comment_stars.md) [comments](comments.md) [posts](posts.md) [logs](logs.md) | | |
+| id | int(11) | | false | [comment_stars](comment_stars.md) [comments](comments.md) [posts](posts.md) [user_options](user_options.md) [logs](logs.md) | | |
| username | varchar(50) | | false | | | |
| password | varchar(50) | | false | | | |
| email | varchar(355) | | false | | | ex. user@example.com |
diff --git a/sample/mysql/users.png b/sample/mysql/users.png
index 449cef17c..ee4e8d05c 100644
Binary files a/sample/mysql/users.png and b/sample/mysql/users.png differ
diff --git a/sample/mysql8/README.md b/sample/mysql8/README.md
index 082e99a34..d03dba33b 100644
--- a/sample/mysql8/README.md
+++ b/sample/mysql8/README.md
@@ -10,6 +10,7 @@
| [logs](logs.md) | 7 | audit log table | BASE TABLE |
| [post_comments](post_comments.md) | 7 | post and comments View table | VIEW |
| [posts](posts.md) | 7 | Posts table | BASE TABLE |
+| [user_options](user_options.md) | 4 | User options table | BASE TABLE |
| [users](users.md) | 6 | Users table | BASE TABLE |
## Relations
diff --git a/sample/mysql8/schema.png b/sample/mysql8/schema.png
index 3538510c8..a5f9c192e 100644
Binary files a/sample/mysql8/schema.png and b/sample/mysql8/schema.png differ
diff --git a/sample/mysql8/user_options.md b/sample/mysql8/user_options.md
new file mode 100644
index 000000000..5d4b9323d
--- /dev/null
+++ b/sample/mysql8/user_options.md
@@ -0,0 +1,51 @@
+# user_options
+
+## Description
+
+User options table
+
+
+Table Definition
+
+```sql
+CREATE TABLE `user_options` (
+ `user_id` int(11) NOT NULL,
+ `show_email` tinyint(1) NOT NULL DEFAULT '0',
+ `created` timestamp NOT NULL,
+ `updated` timestamp NULL DEFAULT NULL,
+ PRIMARY KEY (`user_id`),
+ CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'
+```
+
+
+
+## Columns
+
+| Name | Type | Default | Nullable | Children | Parents | Comment |
+| ---- | ---- | ------- | -------- | -------- | ------- | ------- |
+| user_id | int(11) | | false | | [users](users.md) | |
+| show_email | tinyint(1) | 0 | false | | | |
+| created | timestamp | | false | | | |
+| updated | timestamp | | true | | | |
+
+## Constraints
+
+| Name | Type | Definition |
+| ---- | ---- | ---------- |
+| PRIMARY | PRIMARY KEY | PRIMARY KEY (user_id) |
+| user_options_user_id_fk | FOREIGN KEY | FOREIGN KEY (user_id) REFERENCES users (id) |
+
+## Indexes
+
+| Name | Definition |
+| ---- | ---------- |
+| PRIMARY | PRIMARY KEY (user_id) USING BTREE |
+
+## Relations
+
+
+
+---
+
+> Generated by [tbls](https://github.com/k1LoW/tbls)
diff --git a/sample/mysql8/user_options.png b/sample/mysql8/user_options.png
new file mode 100644
index 000000000..cd0bf579d
Binary files /dev/null and b/sample/mysql8/user_options.png differ
diff --git a/sample/mysql8/users.md b/sample/mysql8/users.md
index 83655b3f0..74045c5a2 100644
--- a/sample/mysql8/users.md
+++ b/sample/mysql8/users.md
@@ -27,7 +27,7 @@ CREATE TABLE `users` (
| Name | Type | Default | Nullable | Children | Parents | Comment |
| ---- | ---- | ------- | -------- | -------- | ------- | ------- |
-| id | int(11) | | false | [comment_stars](comment_stars.md) [comments](comments.md) [posts](posts.md) [logs](logs.md) | | |
+| id | int(11) | | false | [comment_stars](comment_stars.md) [comments](comments.md) [posts](posts.md) [user_options](user_options.md) [logs](logs.md) | | |
| username | varchar(50) | | false | | | |
| password | varchar(50) | | false | | | |
| email | varchar(355) | | false | | | ex. user@example.com |
diff --git a/sample/mysql8/users.png b/sample/mysql8/users.png
index 449cef17c..ee4e8d05c 100644
Binary files a/sample/mysql8/users.png and b/sample/mysql8/users.png differ
diff --git a/sample/postgres/README.md b/sample/postgres/README.md
index 1fcc1678b..1326c4704 100644
--- a/sample/postgres/README.md
+++ b/sample/postgres/README.md
@@ -5,6 +5,7 @@
| Name | Columns | Comment | Type |
| ---- | ------- | ------- | ---- |
| [users](users.md) | 6 | Users table | BASE TABLE |
+| [user_options](user_options.md) | 4 | User options table | BASE TABLE |
| [posts](posts.md) | 8 | Posts table | BASE TABLE |
| [comments](comments.md) | 6 | Comments
Multi-line
table
comment | BASE TABLE |
| [comment_stars](comment_stars.md) | 6 | | BASE TABLE |
diff --git a/sample/postgres/schema.png b/sample/postgres/schema.png
index 3ab873ea2..a64ef4645 100644
Binary files a/sample/postgres/schema.png and b/sample/postgres/schema.png differ
diff --git a/sample/postgres/user_options.md b/sample/postgres/user_options.md
new file mode 100644
index 000000000..acf0be76e
--- /dev/null
+++ b/sample/postgres/user_options.md
@@ -0,0 +1,35 @@
+# user_options
+
+## Description
+
+User options table
+
+## Columns
+
+| Name | Type | Default | Nullable | Children | Parents | Comment |
+| ---- | ---- | ------- | -------- | -------- | ------- | ------- |
+| user_id | integer | | false | | [users](users.md) | |
+| show_email | boolean | false | false | | | |
+| created | timestamp without time zone | | false | | | |
+| updated | timestamp without time zone | | true | | | |
+
+## Constraints
+
+| Name | Type | Definition |
+| ---- | ---- | ---------- |
+| user_options_user_id_fk | FOREIGN KEY | FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE |
+| user_options_pkey | PRIMARY KEY | PRIMARY KEY (user_id) |
+
+## Indexes
+
+| Name | Definition |
+| ---- | ---------- |
+| user_options_pkey | CREATE UNIQUE INDEX user_options_pkey ON public.user_options USING btree (user_id) |
+
+## Relations
+
+
+
+---
+
+> Generated by [tbls](https://github.com/k1LoW/tbls)
diff --git a/sample/postgres/user_options.png b/sample/postgres/user_options.png
new file mode 100644
index 000000000..a57e5507a
Binary files /dev/null and b/sample/postgres/user_options.png differ
diff --git a/sample/postgres/users.md b/sample/postgres/users.md
index 9892cc522..8689a87d5 100644
--- a/sample/postgres/users.md
+++ b/sample/postgres/users.md
@@ -8,7 +8,7 @@ Users table
| Name | Type | Default | Nullable | Children | Parents | Comment |
| ---- | ---- | ------- | -------- | -------- | ------- | ------- |
-| id | integer | nextval('users_id_seq'::regclass) | false | [posts](posts.md) [comments](comments.md) [comment_stars](comment_stars.md) [administrator.blogs](administrator.blogs.md) [logs](logs.md) | | |
+| id | integer | nextval('users_id_seq'::regclass) | false | [user_options](user_options.md) [posts](posts.md) [comments](comments.md) [comment_stars](comment_stars.md) [administrator.blogs](administrator.blogs.md) [logs](logs.md) | | |
| username | varchar(50) | | false | | | |
| password | varchar(50) | | false | | | |
| email | varchar(355) | | false | | | ex. user@example.com |
diff --git a/sample/postgres/users.png b/sample/postgres/users.png
index 6cd72ffa7..7f9fbec1a 100644
Binary files a/sample/postgres/users.png and b/sample/postgres/users.png differ
diff --git a/sample/sqlite/README.md b/sample/sqlite/README.md
index 943f94fff..a02e7386e 100644
--- a/sample/sqlite/README.md
+++ b/sample/sqlite/README.md
@@ -5,6 +5,7 @@
| Name | Columns | Comment | Type |
| ---- | ------- | ------- | ---- |
| [users](users.md) | 6 | | table |
+| [user_options](user_options.md) | 4 | | table |
| [posts](posts.md) | 6 | | table |
| [comments](comments.md) | 6 | | table |
| [comment_stars](comment_stars.md) | 6 | | table |
diff --git a/sample/sqlite/schema.png b/sample/sqlite/schema.png
index 4d279be4c..170c14fff 100644
Binary files a/sample/sqlite/schema.png and b/sample/sqlite/schema.png differ
diff --git a/sample/sqlite/user_options.md b/sample/sqlite/user_options.md
new file mode 100644
index 000000000..ff513ae25
--- /dev/null
+++ b/sample/sqlite/user_options.md
@@ -0,0 +1,42 @@
+# user_options
+
+## Description
+
+
+Table Definition
+
+```sql
+CREATE TABLE user_options (
+ user_id INTEGER PRIMARY KEY,
+ show_email INTEGER NOT NULL DEFAULT 0,
+ created NUMERIC NOT NULL,
+ updated NUMERIC,
+ CONSTRAINT user_options_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE
+)
+```
+
+
+
+## Columns
+
+| Name | Type | Default | Nullable | Children | Parents | Comment |
+| ---- | ---- | ------- | -------- | -------- | ------- | ------- |
+| user_id | INTEGER | | true | | [users](users.md) | |
+| show_email | INTEGER | 0 | false | | | |
+| created | NUMERIC | | false | | | |
+| updated | NUMERIC | | true | | | |
+
+## Constraints
+
+| Name | Type | Definition |
+| ---- | ---- | ---------- |
+| user_id | PRIMARY KEY | PRIMARY KEY (user_id) |
+| - (Foreign key ID: 0) | FOREIGN KEY | FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE |
+
+## Relations
+
+
+
+---
+
+> Generated by [tbls](https://github.com/k1LoW/tbls)
diff --git a/sample/sqlite/user_options.png b/sample/sqlite/user_options.png
new file mode 100644
index 000000000..dac875058
Binary files /dev/null and b/sample/sqlite/user_options.png differ
diff --git a/sample/sqlite/users.md b/sample/sqlite/users.md
index bf1e473e6..a8196b8c0 100644
--- a/sample/sqlite/users.md
+++ b/sample/sqlite/users.md
@@ -22,7 +22,7 @@ CREATE TABLE users (
| Name | Type | Default | Nullable | Children | Parents | Comment |
| ---- | ---- | ------- | -------- | -------- | ------- | ------- |
-| id | INTEGER | | true | [posts](posts.md) [comments](comments.md) [comment_stars](comment_stars.md) [logs](logs.md) | | |
+| id | INTEGER | | true | [user_options](user_options.md) [posts](posts.md) [comments](comments.md) [comment_stars](comment_stars.md) [logs](logs.md) | | |
| username | TEXT | | false | | | |
| password | TEXT | | false | | | |
| email | TEXT | | false | | | |
diff --git a/sample/sqlite/users.png b/sample/sqlite/users.png
index 7f19cd4eb..a2e305234 100644
Binary files a/sample/sqlite/users.png and b/sample/sqlite/users.png differ
diff --git a/sample/svg/README.md b/sample/svg/README.md
index 3af6ff8dc..5b82fce00 100644
--- a/sample/svg/README.md
+++ b/sample/svg/README.md
@@ -10,6 +10,7 @@
| [logs](logs.md) | 7 | audit log table | BASE TABLE |
| [post_comments](post_comments.md) | 7 | post and comments View table | VIEW |
| [posts](posts.md) | 7 | Posts table | BASE TABLE |
+| [user_options](user_options.md) | 4 | User options table | BASE TABLE |
| [users](users.md) | 6 | Users table | BASE TABLE |
## Relations
diff --git a/sample/svg/schema.svg b/sample/svg/schema.svg
index e44836ed6..6b63d6d53 100644
--- a/sample/svg/schema.svg
+++ b/sample/svg/schema.svg
@@ -4,11 +4,11 @@
-