From 36fcbb4e25c7b24f503be62e8f49a3a675e14c31 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Sun, 26 Jan 2025 21:06:25 +0900 Subject: [PATCH 1/6] fix: Trim end newline --- scripts/jsonschema/main.go | 3 +-- spec/tbls.schema.json_schema.json | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/jsonschema/main.go b/scripts/jsonschema/main.go index c60baaaf..46de322f 100644 --- a/scripts/jsonschema/main.go +++ b/scripts/jsonschema/main.go @@ -31,7 +31,6 @@ func _main() error { if err != nil { return err } - fmt.Println(string(b)) - fmt.Println() + fmt.Print(string(b)) return nil } diff --git a/spec/tbls.schema.json_schema.json b/spec/tbls.schema.json_schema.json index c2a16923..6ce9d037 100644 --- a/spec/tbls.schema.json_schema.json +++ b/spec/tbls.schema.json_schema.json @@ -475,5 +475,4 @@ "type": "array" } } -} - +} \ No newline at end of file From 5e5266cfbd4897f54ec4eb215b18ddba5b46f2c2 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Sun, 26 Jan 2025 21:14:56 +0900 Subject: [PATCH 2/6] test: Add tests for JSON Schema --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index b8bb306e..842295f6 100644 --- a/Makefile +++ b/Makefile @@ -149,6 +149,8 @@ test_ext_subcommand: build test_jsonschema: cd scripts/jsonschema && go run main.go | diff -u ../../spec/tbls.schema.json_schema.json - + jv spec/tbls.schema.json_schema.json --assert-content sample/mysql/schema.json + jv spec/tbls.schema.json_schema.json --assert-content sample/postgres/schema.json generate_jsonschema: cd scripts/jsonschema && go run main.go > ../../spec/tbls.schema.json_schema.json @@ -169,6 +171,7 @@ depsdev: go install github.com/xo/usql@latest go install github.com/Songmu/gocredits/cmd/gocredits@latest go install github.com/securego/gosec/v2/cmd/gosec@latest + go install go install github.com/santhosh-tekuri/jsonschema/cmd/jv@latest prerelease: git pull origin --tag From ef4f1a8b1bef52ccf511875a009807efef1a9f32 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Sun, 26 Jan 2025 21:15:19 +0900 Subject: [PATCH 3/6] fix: constraints.columns can be empty --- sample/dict/schema.json | 2 +- sample/exclude/schema.json | 2 +- sample/font/schema.json | 2 +- sample/hide/schema.json | 2 +- sample/hide_not_related_column/schema.json | 2 +- sample/mermaid/schema.json | 2 +- sample/mssql/schema.json | 2 +- sample/mysql/schema.json | 2 +- sample/number/schema.json | 2 +- sample/png/schema.json | 2 +- sample/viewpoints/schema.json | 2 +- schema/schema.go | 2 +- spec/tbls.schema.json_schema.json | 3 +-- 13 files changed, 13 insertions(+), 14 deletions(-) diff --git a/sample/dict/schema.json b/sample/dict/schema.json index b30dd01d..ae2afa8f 100644 --- a/sample/dict/schema.json +++ b/sample/dict/schema.json @@ -1 +1 @@ -{"name":"testdb","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"VIEW","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"post_user","type":"varchar(50)","nullable":true},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"created","type":"datetime","nullable":true},{"name":"updated","type":"datetime","nullable":true}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'"},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} +{"name":"testdb","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"VIEW","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"post_user","type":"varchar(50)","nullable":true},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"created","type":"datetime","nullable":true},{"name":"updated","type":"datetime","nullable":true}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'"},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users"}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} diff --git a/sample/exclude/schema.json b/sample/exclude/schema.json index da578d6c..bda27049 100644 --- a/sample/exclude/schema.json +++ b/sample/exclude/schema.json @@ -1 +1 @@ -{"name":"testdb","tables":[{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'"},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} +{"name":"testdb","tables":[{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'"},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users"}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} diff --git a/sample/font/schema.json b/sample/font/schema.json index 9117a437..0492c23d 100644 --- a/sample/font/schema.json +++ b/sample/font/schema.json @@ -1 +1 @@ -{"name":"testdb","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"エントリ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"本文"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'"},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"サンプル","virtual":true},{"name":"tbls","virtual":true}]} +{"name":"testdb","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"エントリ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"本文"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'"},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users"}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"サンプル","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/hide/schema.json b/sample/hide/schema.json index f1d7ca61..0a41c333 100644 --- a/sample/hide/schema.json +++ b/sample/hide/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users"}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} diff --git a/sample/hide_not_related_column/schema.json b/sample/hide_not_related_column/schema.json index bb6d1a87..2467e79f 100644 --- a/sample/hide_not_related_column/schema.json +++ b/sample/hide_not_related_column/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"zero_or_more","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users"}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"zero_or_more","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/mermaid/schema.json b/sample/mermaid/schema.json index 5c731a00..02c5182a 100644 --- a/sample/mermaid/schema.json +++ b/sample/mermaid/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"exactly_one","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users"}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"exactly_one","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/mssql/schema.json b/sample/mssql/schema.json index fd81a10c..27c7af97 100644 --- a/sample/mssql/schema.json +++ b/sample/mssql/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"users","type":"BASIC TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"comment":"long long long long long long long long long long long long long long long long long long long long long description"},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"PK__users_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"users","columns":["id"]},{"name":"UQ__users_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ email ]","table":"users","columns":["email"]},{"name":"UQ__users_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ username ]","table":"users","columns":["username"]}],"constraints":[{"name":"PK__users_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"users","columns":["id"]},{"name":"UQ__users_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ email ]","table":"users","columns":["email"]},{"name":"UQ__users_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ username ]","table":"users","columns":["username"]},{"name":"CK__users__username_*","type":"CHECK","def":"CHECK(len([username])\u003e(4))","table":"users","columns":null}],"triggers":[{"name":"update_users_updated","def":"CREATE TRIGGER update_users_updated\nON users\nAFTER UPDATE\nAS\nBEGIN\n UPDATE users SET updated = GETDATE()\n WHERE id = ( SELECT id FROM deleted)\nEND;"}]},{"name":"user_options","type":"BASIC TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"bit","nullable":false,"default":"((0))"},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"PK__user_opt_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ user_id ]","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PK__user_opt_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ user_id ]","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE CASCADE","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}]},{"name":"posts","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"posts","columns":["id"]},{"name":"UQ__posts_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, title ]","table":"posts","columns":["user_id","title"]},{"name":"posts_user_id_idx","def":"NONCLUSTERED, [ user_id ]","table":"posts","columns":["user_id"]}],"constraints":[{"name":"posts_id_pk","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"posts","columns":["id"]},{"name":"UQ__posts_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, title ]","table":"posts","columns":["user_id","title"]},{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE CASCADE","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated\nON posts\nAFTER UPDATE\nAS\nBEGIN\n UPDATE users SET updated = GETDATE()\n WHERE id = ( SELECT user_id FROM deleted)\nEND;"}],"labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"comments","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"post_id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"comments","columns":["id"]},{"name":"UQ__comments_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"]},{"name":"comments_post_id_user_id_idx","def":"NONCLUSTERED, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_id_pk","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"comments","columns":["id"]},{"name":"UQ__comments_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"]},{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(post_id) REFERENCES posts(id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}]},{"name":"comment_stars","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"int","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"UQ__comment__*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, comment_post_id, comment_user_id ]","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"UQ__comment__*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, comment_post_id, comment_user_id ]","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]},{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(comment_user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]}]},{"name":"logs","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"int","nullable":true},{"name":"comment_id","type":"int","nullable":true},{"name":"comment_star_id","type":"int","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"date","nullable":false}]},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"int","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"date","nullable":true,"comment":"comments.created"},{"name":"updated","type":"date","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (\n SELECT c.id, p.title, u2.username AS post_user, c.comment, u2.username AS comment_user, c.created, c.updated\n FROM posts AS p\n LEFT JOIN comments AS c on p.id = c.post_id\n LEFT JOIN users AS u on u.id = p.user_id\n LEFT JOIN users AS u2 on u2.id = c.user_id\n);","referenced_tables":["posts","comments","users"]},{"name":"CamelizeTable","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"created","type":"date","nullable":false}]},{"name":"hyphen-table","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"date","nullable":false}]},{"name":"administrator.blogs","type":"BASIC TABLE","comment":"admin blogs","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"PK__blogs_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"administrator.blogs","columns":["id"]}],"constraints":[{"name":"PK__blogs_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"administrator.blogs","columns":["id"]},{"name":"blogs_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE CASCADE","table":"administrator.blogs","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}]},{"name":"name with spaces","type":"VIEW","columns":[{"name":"title","type":"varchar(255)","nullable":false}],"def":"CREATE VIEW \"name with spaces\" AS (\n SELECT TOP 1 p.title\n FROM posts AS p\n);","referenced_tables":["posts"]},{"name":"Sales.Product","type":"BASIC TABLE","columns":[{"name":"ProductID","type":"int","nullable":false},{"name":"SalesPersonID","type":"int","nullable":true}],"indexes":[{"name":"PK__Product_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ ProductID ]","table":"Sales.Product","columns":["ProductID"]},{"name":"UQ__Product_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ SalesPersonID ]","table":"Sales.Product","columns":["SalesPersonID"]}],"constraints":[{"name":"PK__Product_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ ProductID ]","table":"Sales.Product","columns":["ProductID"]},{"name":"UQ__Product_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ SalesPersonID ]","table":"Sales.Product","columns":["SalesPersonID"]}]},{"name":"Rabbits.Running","type":"BASIC TABLE","columns":[{"name":"LocationID","type":"int","nullable":false},{"name":"ProductID","type":"int","nullable":true},{"name":"EmployeeID","type":"int","nullable":true}],"indexes":[{"name":"PK__Running_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ LocationID ]","table":"Rabbits.Running","columns":["LocationID"]},{"name":"UQ__Running_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ EmployeeID ]","table":"Rabbits.Running","columns":["EmployeeID"]},{"name":"UQ__Running_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ ProductID ]","table":"Rabbits.Running","columns":["ProductID"]}],"constraints":[{"name":"PK__Running_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ LocationID ]","table":"Rabbits.Running","columns":["LocationID"]},{"name":"UQ__Running_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ EmployeeID ]","table":"Rabbits.Running","columns":["EmployeeID"]},{"name":"UQ__Running_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ ProductID ]","table":"Rabbits.Running","columns":["ProductID"]},{"name":"FK_TempSales_SalesReason","type":"FOREIGN KEY","def":"FOREIGN KEY(ProductID) REFERENCES Sales.Product(SalesPersonID) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"Rabbits.Running","referenced_table":"Sales.Product","columns":["ProductID"],"referenced_columns":["SalesPersonID"]}]}],"relations":[{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":""},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":""},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":""},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":""},{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":""},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":""},{"table":"administrator.blogs","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":""},{"table":"Rabbits.Running","columns":["ProductID"],"cardinality":"zero_or_one","parent_table":"Sales.Product","parent_columns":["SalesPersonID"],"parent_cardinality":"zero_or_one","def":""},{"table":"logs","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"zero_or_more","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true}],"functions":[{"name":"dbo.get_user","return_type":"","arguments":"@userid int","type":"SQL inline table-valued function"},{"name":"dbo.What_DB_is_that","return_type":"","arguments":"@ID int","type":"SQL Stored Procedure"}],"driver":{"name":"sqlserver","database_version":"Microsoft SQL Server 2019 (RTM-CU30) (KB5049235) - 15.0.4415.2 (X64) \n\tNov 18 2024 17:45:37 \n\tCopyright (C) 2019 Microsoft Corporation\n\tDeveloper Edition (64-bit) on Linux (Ubuntu 20.04.6 LTS) \u003cX64\u003e","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"users","type":"BASIC TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"comment":"long long long long long long long long long long long long long long long long long long long long long description"},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"PK__users_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"users","columns":["id"]},{"name":"UQ__users_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ email ]","table":"users","columns":["email"]},{"name":"UQ__users_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ username ]","table":"users","columns":["username"]}],"constraints":[{"name":"PK__users_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"users","columns":["id"]},{"name":"UQ__users_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ email ]","table":"users","columns":["email"]},{"name":"UQ__users_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ username ]","table":"users","columns":["username"]},{"name":"CK__users__username_*","type":"CHECK","def":"CHECK(len([username])\u003e(4))","table":"users"}],"triggers":[{"name":"update_users_updated","def":"CREATE TRIGGER update_users_updated\nON users\nAFTER UPDATE\nAS\nBEGIN\n UPDATE users SET updated = GETDATE()\n WHERE id = ( SELECT id FROM deleted)\nEND;"}]},{"name":"user_options","type":"BASIC TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"bit","nullable":false,"default":"((0))"},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"PK__user_opt_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ user_id ]","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PK__user_opt_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ user_id ]","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE CASCADE","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}]},{"name":"posts","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"posts","columns":["id"]},{"name":"UQ__posts_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, title ]","table":"posts","columns":["user_id","title"]},{"name":"posts_user_id_idx","def":"NONCLUSTERED, [ user_id ]","table":"posts","columns":["user_id"]}],"constraints":[{"name":"posts_id_pk","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"posts","columns":["id"]},{"name":"UQ__posts_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, title ]","table":"posts","columns":["user_id","title"]},{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE CASCADE","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated\nON posts\nAFTER UPDATE\nAS\nBEGIN\n UPDATE users SET updated = GETDATE()\n WHERE id = ( SELECT user_id FROM deleted)\nEND;"}],"labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"comments","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"post_id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"comments","columns":["id"]},{"name":"UQ__comments_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"]},{"name":"comments_post_id_user_id_idx","def":"NONCLUSTERED, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_id_pk","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"comments","columns":["id"]},{"name":"UQ__comments_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"]},{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(post_id) REFERENCES posts(id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}]},{"name":"comment_stars","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"int","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"UQ__comment__*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, comment_post_id, comment_user_id ]","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"UQ__comment__*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, comment_post_id, comment_user_id ]","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]},{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(comment_user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]}]},{"name":"logs","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"int","nullable":true},{"name":"comment_id","type":"int","nullable":true},{"name":"comment_star_id","type":"int","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"date","nullable":false}]},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"int","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"date","nullable":true,"comment":"comments.created"},{"name":"updated","type":"date","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (\n SELECT c.id, p.title, u2.username AS post_user, c.comment, u2.username AS comment_user, c.created, c.updated\n FROM posts AS p\n LEFT JOIN comments AS c on p.id = c.post_id\n LEFT JOIN users AS u on u.id = p.user_id\n LEFT JOIN users AS u2 on u2.id = c.user_id\n);","referenced_tables":["posts","comments","users"]},{"name":"CamelizeTable","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"created","type":"date","nullable":false}]},{"name":"hyphen-table","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"date","nullable":false}]},{"name":"administrator.blogs","type":"BASIC TABLE","comment":"admin blogs","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"PK__blogs_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"administrator.blogs","columns":["id"]}],"constraints":[{"name":"PK__blogs_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"administrator.blogs","columns":["id"]},{"name":"blogs_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE CASCADE","table":"administrator.blogs","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}]},{"name":"name with spaces","type":"VIEW","columns":[{"name":"title","type":"varchar(255)","nullable":false}],"def":"CREATE VIEW \"name with spaces\" AS (\n SELECT TOP 1 p.title\n FROM posts AS p\n);","referenced_tables":["posts"]},{"name":"Sales.Product","type":"BASIC TABLE","columns":[{"name":"ProductID","type":"int","nullable":false},{"name":"SalesPersonID","type":"int","nullable":true}],"indexes":[{"name":"PK__Product_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ ProductID ]","table":"Sales.Product","columns":["ProductID"]},{"name":"UQ__Product_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ SalesPersonID ]","table":"Sales.Product","columns":["SalesPersonID"]}],"constraints":[{"name":"PK__Product_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ ProductID ]","table":"Sales.Product","columns":["ProductID"]},{"name":"UQ__Product_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ SalesPersonID ]","table":"Sales.Product","columns":["SalesPersonID"]}]},{"name":"Rabbits.Running","type":"BASIC TABLE","columns":[{"name":"LocationID","type":"int","nullable":false},{"name":"ProductID","type":"int","nullable":true},{"name":"EmployeeID","type":"int","nullable":true}],"indexes":[{"name":"PK__Running_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ LocationID ]","table":"Rabbits.Running","columns":["LocationID"]},{"name":"UQ__Running_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ EmployeeID ]","table":"Rabbits.Running","columns":["EmployeeID"]},{"name":"UQ__Running_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ ProductID ]","table":"Rabbits.Running","columns":["ProductID"]}],"constraints":[{"name":"PK__Running_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ LocationID ]","table":"Rabbits.Running","columns":["LocationID"]},{"name":"UQ__Running_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ EmployeeID ]","table":"Rabbits.Running","columns":["EmployeeID"]},{"name":"UQ__Running_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ ProductID ]","table":"Rabbits.Running","columns":["ProductID"]},{"name":"FK_TempSales_SalesReason","type":"FOREIGN KEY","def":"FOREIGN KEY(ProductID) REFERENCES Sales.Product(SalesPersonID) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"Rabbits.Running","referenced_table":"Sales.Product","columns":["ProductID"],"referenced_columns":["SalesPersonID"]}]}],"relations":[{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":""},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":""},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":""},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":""},{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":""},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":""},{"table":"administrator.blogs","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":""},{"table":"Rabbits.Running","columns":["ProductID"],"cardinality":"zero_or_one","parent_table":"Sales.Product","parent_columns":["SalesPersonID"],"parent_cardinality":"zero_or_one","def":""},{"table":"logs","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"zero_or_more","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true}],"functions":[{"name":"dbo.get_user","return_type":"","arguments":"@userid int","type":"SQL inline table-valued function"},{"name":"dbo.What_DB_is_that","return_type":"","arguments":"@ID int","type":"SQL Stored Procedure"}],"driver":{"name":"sqlserver","database_version":"Microsoft SQL Server 2019 (RTM-CU30) (KB5049235) - 15.0.4415.2 (X64) \n\tNov 18 2024 17:45:37 \n\tCopyright (C) 2019 Microsoft Corporation\n\tDeveloper Edition (64-bit) on Linux (Ubuntu 20.04.6 LTS) \u003cX64\u003e","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/mysql/schema.json b/sample/mysql/schema.json index 5c731a00..02c5182a 100644 --- a/sample/mysql/schema.json +++ b/sample/mysql/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"exactly_one","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users"}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"exactly_one","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/number/schema.json b/sample/number/schema.json index 7209b78e..aafacbb8 100644 --- a/sample/number/schema.json +++ b/sample/number/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users"}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/png/schema.json b/sample/png/schema.json index 5c731a00..02c5182a 100644 --- a/sample/png/schema.json +++ b/sample/png/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"exactly_one","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users"}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"exactly_one","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/viewpoints/schema.json b/sample/viewpoints/schema.json index fd66c9ef..2bd26c21 100644 --- a/sample/viewpoints/schema.json +++ b/sample/viewpoints/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"labels":[{"name":"user","virtual":true}]},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci","labels":[{"name":"content","virtual":true}]},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false,"labels":[{"name":"user","virtual":true}]},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'","labels":[{"name":"content","virtual":true}]},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","labels":[{"name":"content","virtual":true}],"referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"labels":[{"name":"user","virtual":true}]},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"content","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'","labels":[{"name":"user","virtual":true}]},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'","labels":[{"name":"user","virtual":true}]}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"zero_or_more","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}],"viewpoints":[{"name":"Content","desc":"Content as an asset for blogging services","labels":["content"]},{"name":"Ops","desc":"Tables to be referenced during operation","tables":["logs","users","posts"]},{"name":"Around the users table","desc":"Tables related to the users table","tables":["users"],"distance":1,"groups":[{"name":"Content","desc":"Content as an asset for blogging services","labels":["content"]}]},{"name":"Secure data","desc":"Tables with secure data","labels":["secure"]}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"labels":[{"name":"user","virtual":true}]},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci","labels":[{"name":"content","virtual":true}]},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false,"labels":[{"name":"user","virtual":true}]},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'","labels":[{"name":"content","virtual":true}]},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","labels":[{"name":"content","virtual":true}],"referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"labels":[{"name":"user","virtual":true}]},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"content","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'","labels":[{"name":"user","virtual":true}]},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users"}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'","labels":[{"name":"user","virtual":true}]}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"zero_or_more","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}],"viewpoints":[{"name":"Content","desc":"Content as an asset for blogging services","labels":["content"]},{"name":"Ops","desc":"Tables to be referenced during operation","tables":["logs","users","posts"]},{"name":"Around the users table","desc":"Tables related to the users table","tables":["users"],"distance":1,"groups":[{"name":"Content","desc":"Content as an asset for blogging services","labels":["content"]}]},{"name":"Secure data","desc":"Tables with secure data","labels":["secure"]}]} diff --git a/schema/schema.go b/schema/schema.go index f2aa1693..1967c0ca 100644 --- a/schema/schema.go +++ b/schema/schema.go @@ -102,7 +102,7 @@ type Constraint struct { Def string `json:"def"` Table *string `json:"table"` ReferencedTable *string `json:"referenced_table,omitempty" yaml:"referencedTable,omitempty"` - Columns []string `json:"columns"` + Columns []string `json:"columns,omitempty"` ReferencedColumns []string `json:"referenced_columns,omitempty" yaml:"referencedColumns,omitempty"` Comment string `json:"comment,omitempty"` } diff --git a/spec/tbls.schema.json_schema.json b/spec/tbls.schema.json_schema.json index 6ce9d037..845a514e 100644 --- a/spec/tbls.schema.json_schema.json +++ b/spec/tbls.schema.json_schema.json @@ -81,8 +81,7 @@ "name", "type", "def", - "table", - "columns" + "table" ] }, "Dict": { From 3c77e92ea5b0743051577aa3e6e4c7403ba9d1ed Mon Sep 17 00:00:00 2001 From: k1LoW Date: Sun, 26 Jan 2025 21:28:35 +0900 Subject: [PATCH 4/6] fix: driver.meta.dict allow empty --- schema/json.go | 38 +++++++++++++++++++++++++++++-- spec/tbls.schema.json_schema.json | 10 ++++---- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/schema/json.go b/schema/json.go index dccca499..251a688e 100644 --- a/schema/json.go +++ b/schema/json.go @@ -12,7 +12,7 @@ type SchemaJSON struct { Relations []*RelationJSON `json:"relations,omitempty"` Functions []*Function `json:"functions,omitempty"` Enums []*Enum `json:"enums,omitempty"` - Driver *Driver `json:"driver,omitempty"` + Driver *DriverJSON `json:"driver,omitempty"` Labels Labels `json:"labels,omitempty"` Viewpoints Viewpoints `json:"viewpoints,omitempty"` } @@ -54,6 +54,18 @@ type RelationJSON struct { Virtual bool `json:"virtual,omitempty"` } +type DriverJSON struct { + Name string `json:"name"` + DatabaseVersion string `json:"database_version,omitempty" yaml:"databaseVersion,omitempty"` + Meta *DriverMetaJSON `json:"meta,omitempty"` +} + +type DriverMetaJSON struct { + CurrentSchema string `json:"current_schema,omitempty" yaml:"currentSchema,omitempty"` + SearchPaths []string `json:"search_paths,omitempty" yaml:"searchPaths,omitempty"` + Dict map[string]string `json:"dict,omitempty"` +} + // ToJSONObjct convert schema.Schema to JSON object func (s Schema) ToJSONObject() SchemaJSON { var tables []*TableJSON @@ -73,7 +85,7 @@ func (s Schema) ToJSONObject() SchemaJSON { Relations: relations, Functions: s.Functions, Enums: s.Enums, - Driver: s.Driver, + Driver: s.Driver.ToJSONObject(), Labels: s.Labels, Viewpoints: s.Viewpoints, } @@ -140,6 +152,28 @@ func (r Relation) ToJSONObject() RelationJSON { } } +func (d *Driver) ToJSONObject() *DriverJSON { + if d == nil { + return nil + } + return &DriverJSON{ + Name: d.Name, + DatabaseVersion: d.DatabaseVersion, + Meta: d.Meta.ToJSONObject(), + } +} + +func (d *DriverMeta) ToJSONObject() *DriverMetaJSON { + if d == nil { + return nil + } + return &DriverMetaJSON{ + CurrentSchema: d.CurrentSchema, + SearchPaths: d.SearchPaths, + Dict: d.Dict.Dump(), + } +} + // MarshalJSON return custom JSON byte func (s Schema) MarshalJSON() ([]byte, error) { ss := s.ToJSONObject() diff --git a/spec/tbls.schema.json_schema.json b/spec/tbls.schema.json_schema.json index 845a514e..b5e1822b 100644 --- a/spec/tbls.schema.json_schema.json +++ b/spec/tbls.schema.json_schema.json @@ -84,11 +84,6 @@ "table" ] }, - "Dict": { - "properties": {}, - "additionalProperties": false, - "type": "object" - }, "Driver": { "properties": { "name": { @@ -119,7 +114,10 @@ "type": "array" }, "dict": { - "$ref": "#/$defs/Dict" + "additionalProperties": { + "type": "string" + }, + "type": "object" } }, "additionalProperties": false, From f1e8f0208556ec0a4d95e18aa4da1ae8ecfb6156 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Sun, 26 Jan 2025 21:40:06 +0900 Subject: [PATCH 5/6] fix: Fix typo --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 842295f6..d0e59ba8 100644 --- a/Makefile +++ b/Makefile @@ -171,7 +171,7 @@ depsdev: go install github.com/xo/usql@latest go install github.com/Songmu/gocredits/cmd/gocredits@latest go install github.com/securego/gosec/v2/cmd/gosec@latest - go install go install github.com/santhosh-tekuri/jsonschema/cmd/jv@latest + go install github.com/santhosh-tekuri/jsonschema/cmd/jv@latest prerelease: git pull origin --tag From d7d585432c098f53bc9e28ea3f9bb20944d6d957 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Sun, 26 Jan 2025 21:53:23 +0900 Subject: [PATCH 6/6] fix: Fix nil pointer dereference --- schema/json.go | 7 +++++-- testdata/json_output_schema.golden | 3 +-- testdata/yaml_output_schema.golden | 1 - 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/schema/json.go b/schema/json.go index 251a688e..c36d1a5c 100644 --- a/schema/json.go +++ b/schema/json.go @@ -167,11 +167,14 @@ func (d *DriverMeta) ToJSONObject() *DriverMetaJSON { if d == nil { return nil } - return &DriverMetaJSON{ + m := &DriverMetaJSON{ CurrentSchema: d.CurrentSchema, SearchPaths: d.SearchPaths, - Dict: d.Dict.Dump(), } + if d.Dict != nil { + m.Dict = d.Dict.Dump() + } + return m } // MarshalJSON return custom JSON byte diff --git a/testdata/json_output_schema.golden b/testdata/json_output_schema.golden index fbe17658..7d4c5370 100644 --- a/testdata/json_output_schema.golden +++ b/testdata/json_output_schema.golden @@ -34,8 +34,7 @@ "name": "PRIMARY", "type": "", "def": "PRIMARY KEY (a)", - "table": "a", - "columns": null + "table": "a" } ], "triggers": [ diff --git a/testdata/yaml_output_schema.golden b/testdata/yaml_output_schema.golden index 96d42340..dd60e29a 100644 --- a/testdata/yaml_output_schema.golden +++ b/testdata/yaml_output_schema.golden @@ -23,7 +23,6 @@ tables: type: "" def: PRIMARY KEY (a) table: a - columns: [] triggers: - name: update_a_a2 def: CREATE CONSTRAINT TRIGGER update_a_a2 AFTER INSERT OR UPDATE ON a