From 11fe9c36d4c0729f6a7b62f8f051788c01c342cb Mon Sep 17 00:00:00 2001 From: k1LoW Date: Tue, 7 Nov 2023 15:15:15 +0900 Subject: [PATCH 1/3] Do not run detectCardinality before MergeAdditionalData --- config/config.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/config/config.go b/config/config.go index 2f140169..7e00f5fe 100644 --- a/config/config.go +++ b/config/config.go @@ -407,9 +407,6 @@ func (c *Config) ModifySchema(s *schema.Schema) error { for _, l := range c.Labels { s.Labels = s.Labels.Merge(l) } - if err := detectCardinality(s); err != nil { - return err - } if err := detectPKFK(s); err != nil { return err } @@ -822,8 +819,9 @@ func matchLength(s []string, e string) (int, bool) { return 0, false } +// detectCardinality detects the cardinality of the relations +// This function should be applied to the completed schema func detectCardinality(s *schema.Schema) error { - // This function should be applied to the completed schema for _, r := range s.Relations { // child if r.Cardinality == schema.UnknownCardinality { From 246f0f556ba4598b60b75fe66a1e40f9487a7dce Mon Sep 17 00:00:00 2001 From: k1LoW Date: Tue, 7 Nov 2023 18:15:46 +0900 Subject: [PATCH 2/3] Set additional cardinality to the relationship. --- config/config.go | 13 +- sample/adjust/schema.json | 2 +- sample/detect_relations/schema.json | 2 +- sample/detect_relations_singular/schema.json | 2 +- 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/mariadb/schema.json | 2 +- sample/mermaid/README.md | 2 +- sample/mermaid/comment_stars.md | 2 +- sample/mermaid/logs.md | 2 +- sample/mermaid/schema.json | 2 +- sample/mssql/README.md | 2 +- sample/mssql/schema.json | 2 +- sample/mssql/schema.svg | 606 +++++++++---------- sample/mysql/schema.json | 2 +- sample/mysql56/schema.json | 2 +- sample/number/schema.json | 2 +- sample/png/schema.json | 2 +- sample/postgres/schema.json | 2 +- sample/postgres95/schema.json | 2 +- sample/sqlite/schema.json | 2 +- sample/viewpoints/schema.json | 2 +- testdata/test_tbls.yml | 2 + 26 files changed, 339 insertions(+), 328 deletions(-) diff --git a/config/config.go b/config/config.go index 7e00f5fe..a632f723 100644 --- a/config/config.go +++ b/config/config.go @@ -654,15 +654,24 @@ func (c *Config) detectShowColumnsForER(s *schema.Schema) error { func mergeAdditionalRelations(s *schema.Schema, relations []AdditionalRelation) error { for _, r := range relations { + c, err := schema.ToCardinality(r.Cardinality) + if err != nil { + return errors.Wrap(err, "failed to add relation") + } + pc, err := schema.ToCardinality(r.ParentCardinality) + if err != nil { + return errors.Wrap(err, "failed to add relation") + } relation := &schema.Relation{ - Virtual: true, + Cardinality: c, + ParentCardinality: pc, + Virtual: true, } if r.Def != "" { relation.Def = r.Def } else { relation.Def = "Additional Relation" } - var err error relation.Table, err = s.FindTableByName(r.Table) if err != nil { return errors.Wrap(err, "failed to add relation") diff --git a/sample/adjust/schema.json b/sample/adjust/schema.json index 7dbfd05a..56b8c51b 100644 --- a/sample/adjust/schema.json +++ b/sample/adjust/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample PostgreSQL database document.","tables":[{"name":"public.users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('users_id_seq'::regclass)","comment":""},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"users_pkey","def":"CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)","table":"public.users","columns":["id"],"comment":""},{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)","table":"public.users","columns":["username"],"comment":""},{"name":"users_email_key","def":"CREATE UNIQUE INDEX users_email_key ON public.users USING btree (email)","table":"public.users","columns":["email"],"comment":""}],"constraints":[{"name":"users_username_check","type":"CHECK","def":"CHECK ((char_length((username)::text) \u003e 4))","table":"public.users","referenced_table":"","columns":["username"],"referenced_columns":[],"comment":""},{"name":"users_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.users","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""},{"name":"users_username_key","type":"UNIQUE","def":"UNIQUE (username)","table":"public.users","referenced_table":"","columns":["username"],"referenced_columns":[],"comment":""},{"name":"users_email_key","type":"UNIQUE","def":"UNIQUE (email)","table":"public.users","referenced_table":"","columns":["email"],"referenced_columns":[],"comment":""}],"triggers":[{"name":"update_users_updated","def":"CREATE TRIGGER update_users_updated AFTER INSERT OR UPDATE ON public.users FOR EACH ROW EXECUTE FUNCTION update_updated()","comment":"Update updated when users insert or update"}],"def":""},{"name":"public.user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"show_email","type":"boolean","nullable":false,"default":"false","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"user_options_pkey","def":"CREATE UNIQUE INDEX user_options_pkey ON public.user_options USING btree (user_id)","table":"public.user_options","columns":["user_id"],"comment":"PRIMARY KEY"}],"constraints":[{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","table":"public.user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":"FK"},{"name":"user_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"public.user_options","referenced_table":"","columns":["user_id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"public.posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"default":"nextval('posts_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'::character varying","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"post_types","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"labels","type":"varchar(50)[]","nullable":true,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_id_pk","def":"CREATE UNIQUE INDEX posts_id_pk ON public.posts USING btree (id)","table":"public.posts","columns":["id"],"comment":""},{"name":"posts_user_id_title_key","def":"CREATE UNIQUE INDEX posts_user_id_title_key ON public.posts USING btree (user_id, title)","table":"public.posts","columns":["title","user_id"],"comment":""},{"name":"posts_user_id_idx","def":"CREATE INDEX posts_user_id_idx ON public.posts USING btree (user_id)","table":"public.posts","columns":["user_id"],"comment":"posts.user_id index"}],"constraints":[{"name":"update_posts_updated","type":"TRIGGER","def":"CREATE CONSTRAINT TRIGGER update_posts_updated AFTER INSERT OR UPDATE ON public.posts NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE FUNCTION update_updated()","table":"public.posts","referenced_table":"","columns":["tableoid","cmax","xmax","cmin","xmin","ctid","id","user_id","title","body","post_type","labels","created","updated"],"referenced_columns":[],"comment":""},{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL (user_id)","table":"public.posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":"posts -\u003e users"},{"name":"posts_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.posts","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""},{"name":"posts_user_id_title_key","type":"UNIQUE","def":"UNIQUE (user_id, title)","table":"public.posts","referenced_table":"","columns":["user_id","title"],"referenced_columns":[],"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE CONSTRAINT TRIGGER update_posts_updated AFTER INSERT OR UPDATE ON public.posts NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE FUNCTION update_updated()","comment":"Update updated when posts update"}],"def":""},{"name":"public.comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"default":"nextval('comments_id_seq'::regclass)","comment":""},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"default":null,"comment":"","extra_def":"GENERATED ALWAYS AS (post_id * '-1'::integer) STORED"},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"comments_id_pk","def":"CREATE UNIQUE INDEX comments_id_pk ON public.comments USING btree (id)","table":"public.comments","columns":["id"],"comment":""},{"name":"comments_post_id_user_id_key","def":"CREATE UNIQUE INDEX comments_post_id_user_id_key ON public.comments USING btree (post_id, user_id)","table":"public.comments","columns":["post_id","user_id"],"comment":""},{"name":"comments_post_id_user_id_idx","def":"CREATE INDEX comments_post_id_user_id_idx ON public.comments USING btree (post_id, user_id)","table":"public.comments","columns":["post_id","user_id"],"comment":""}],"constraints":[{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users(id)","table":"public.comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":""},{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts(id)","table":"public.comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"],"comment":""},{"name":"comments_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.comments","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""},{"name":"comments_post_id_user_id_key","type":"UNIQUE","def":"UNIQUE (post_id, user_id)","table":"public.comments","referenced_table":"","columns":["post_id","user_id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"public.comment_stars","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"comment_stars_user_id_comment_post_id_comment_user_id_key","def":"CREATE UNIQUE INDEX comment_stars_user_id_comment_post_id_comment_user_id_key ON public.comment_stars USING btree (user_id, comment_post_id, comment_user_id)","table":"public.comment_stars","columns":["comment_post_id","comment_user_id","user_id"],"comment":""}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","table":"public.comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"],"comment":""},{"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":"public.comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_post_id","comment_user_id","comment_user_id"],"referenced_columns":["post_id","user_id","post_id","user_id"],"comment":""},{"name":"comment_stars_user_id_comment_post_id_comment_user_id_key","type":"UNIQUE","def":"UNIQUE (user_id, comment_post_id, comment_user_id)","table":"public.comment_stars","referenced_table":"","columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"public.logs","type":"BASE TABLE","comment":"audit log table","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"uuid","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":""},{"name":"public.post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":null,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":true,"default":null,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":""},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"timestamp without time zone","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"def":"CREATE VIEW post_comments AS (\n SELECT c.id,\n p.title,\n u.username AS post_user,\n c.comment,\n u2.username AS comment_user,\n c.created,\n c.updated\n FROM (((posts p\n LEFT JOIN comments c ON ((p.id = c.post_id)))\n LEFT JOIN users u ON ((u.id = p.user_id)))\n LEFT JOIN users u2 ON ((u2.id = c.user_id)))\n)","referenced_tables":["public.posts","public.comments","public.users"]},{"name":"public.post_comment_stars","type":"MATERIALIZED VIEW","comment":"","columns":[{"name":"id","type":"uuid","nullable":true,"default":null,"comment":""},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":""},{"name":"comment_star_user","type":"varchar(50)","nullable":true,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":true,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":"CREATE MATERIALIZED VIEW post_comment_stars AS (\n SELECT cs.id,\n cu.username AS comment_user,\n csu.username AS comment_star_user,\n cs.created,\n cs.updated\n FROM (((comments c\n LEFT JOIN comment_stars cs ON (((cs.comment_post_id = c.id) AND (cs.comment_user_id = c.user_id))))\n LEFT JOIN users cu ON ((cu.id = cs.comment_user_id)))\n LEFT JOIN users csu ON ((csu.id = cs.user_id)))\n)","referenced_tables":["public.comments","public.comment_stars","public.users"]},{"name":"public.CamelizeTable","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"CamelizeTable_id_key","def":"CREATE UNIQUE INDEX \"CamelizeTable_id_key\" ON public.\"CamelizeTable\" USING btree (id)","table":"public.CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"CamelizeTable_id_key","type":"UNIQUE","def":"UNIQUE (id)","table":"public.CamelizeTable","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"public.hyphen-table","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"CamelizeTableId","type":"uuid","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"hyphen-table_hyphen-column_key","def":"CREATE UNIQUE INDEX \"hyphen-table_hyphen-column_key\" ON public.\"hyphen-table\" USING btree (\"hyphen-column\")","table":"public.hyphen-table","columns":["hyphen-column"],"comment":""}],"constraints":[{"name":"hyphen-table_CamelizeTableId_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (\"CamelizeTableId\") REFERENCES \"CamelizeTable\"(id) ON DELETE CASCADE","table":"public.hyphen-table","referenced_table":"CamelizeTable","columns":["CamelizeTableId"],"referenced_columns":["id"],"comment":""},{"name":"hyphen-table_hyphen-column_key","type":"UNIQUE","def":"UNIQUE (\"hyphen-column\")","table":"public.hyphen-table","referenced_table":"","columns":["hyphen-column"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"administrator.blogs","type":"BASE TABLE","comment":"admin blogs","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('administrator.blogs_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"name","type":"text","nullable":false,"default":null,"comment":""},{"name":"description","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON administrator.blogs USING btree (id)","table":"administrator.blogs","columns":["id"],"comment":""}],"constraints":[{"name":"blogs_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","table":"administrator.blogs","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":""},{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"administrator.blogs","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"backup.blogs","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blogs_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"dump","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON backup.blogs USING btree (id)","table":"backup.blogs","columns":["id"],"comment":""}],"constraints":[{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blogs","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"backup.blog_options","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blog_options_id_seq'::regclass)","comment":""},{"name":"blog_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"label","type":"text","nullable":true,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"blog_options_pkey","def":"CREATE UNIQUE INDEX blog_options_pkey ON backup.blog_options USING btree (id)","table":"backup.blog_options","columns":["id"],"comment":""}],"constraints":[{"name":"blog_options_blog_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (blog_id) REFERENCES blogs(id) ON DELETE CASCADE","table":"backup.blog_options","referenced_table":"blogs","columns":["blog_id"],"referenced_columns":["id"],"comment":""},{"name":"blog_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blog_options","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"time.bar","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"bar_pkey","def":"CREATE UNIQUE INDEX bar_pkey ON \"time\".bar USING btree (id)","table":"time.bar","columns":["id"],"comment":""}],"constraints":[{"name":"bar_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.bar","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"time.hyphenated-table","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"hyphenated-table_pkey","def":"CREATE UNIQUE INDEX \"hyphenated-table_pkey\" ON \"time\".\"hyphenated-table\" USING btree (id)","table":"time.hyphenated-table","columns":["id"],"comment":""}],"constraints":[{"name":"hyphenated-table_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.hyphenated-table","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"time.referencing","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"bar_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"ht_id","type":"integer","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"referencing_pkey","def":"CREATE UNIQUE INDEX referencing_pkey ON \"time\".referencing USING btree (id)","table":"time.referencing","columns":["id"],"comment":""}],"constraints":[{"name":"referencing_bar_id","type":"FOREIGN KEY","def":"FOREIGN KEY (bar_id) REFERENCES \"time\".bar(id)","table":"time.referencing","referenced_table":"bar","columns":["bar_id"],"referenced_columns":["id"],"comment":""},{"name":"referencing_ht_id","type":"FOREIGN KEY","def":"FOREIGN KEY (ht_id) REFERENCES \"time\".\"hyphenated-table\"(id)","table":"time.referencing","referenced_table":"hyphenated-table","columns":["ht_id"],"referenced_columns":["id"],"comment":""},{"name":"referencing_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.referencing","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""}],"relations":[{"table":"public.user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","virtual":false},{"table":"public.posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL (user_id)","virtual":false},{"table":"public.comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users(id)","virtual":false},{"table":"public.comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"public.posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts(id)","virtual":false},{"table":"public.comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","virtual":false},{"table":"public.comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"public.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)","virtual":false},{"table":"public.hyphen-table","columns":["CamelizeTableId"],"cardinality":"Zero or more","parent_table":"public.CamelizeTable","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (\"CamelizeTableId\") REFERENCES \"CamelizeTable\"(id) ON DELETE CASCADE","virtual":false},{"table":"administrator.blogs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","virtual":false},{"table":"backup.blog_options","columns":["blog_id"],"cardinality":"Zero or more","parent_table":"backup.blogs","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (blog_id) REFERENCES blogs(id) ON DELETE CASCADE","virtual":false},{"table":"time.referencing","columns":["bar_id"],"cardinality":"Zero or more","parent_table":"time.bar","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (bar_id) REFERENCES \"time\".bar(id)","virtual":false},{"table":"time.referencing","columns":["ht_id"],"cardinality":"Zero or more","parent_table":"time.hyphenated-table","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (ht_id) REFERENCES \"time\".\"hyphenated-table\"(id)","virtual":false},{"table":"public.logs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"logs-\u003eusers","virtual":true},{"table":"public.logs","columns":["post_id"],"cardinality":"Zero or more","parent_table":"public.posts","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"public.logs","columns":["comment_id"],"cardinality":"Zero or more","parent_table":"public.comments","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"public.logs","columns":["comment_star_id"],"cardinality":"Zero or more","parent_table":"public.comment_stars","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true}],"functions":[{"name":"public.uuid_nil","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_ns_dns","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_ns_url","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_ns_oid","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_ns_x500","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_generate_v1","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_generate_v1mc","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_generate_v3","return_type":"uuid","arguments":"namespace uuid, name text","type":"FUNCTION"},{"name":"public.uuid_generate_v4","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_generate_v5","return_type":"uuid","arguments":"namespace uuid, name text","type":"FUNCTION"},{"name":"public.update_updated","return_type":"trigger","arguments":"","type":"FUNCTION"},{"name":"public.reset_comment","return_type":"void","arguments":"IN comment_id integer","type":"PROCEDURE"}],"driver":{"name":"postgres","database_version":"PostgreSQL 15.1 (Debian 15.1-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit","meta":{"current_schema":"public","search_paths":["\"$user\"","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}}} +{"name":"testdb","desc":"Sample PostgreSQL database document.","tables":[{"name":"public.users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('users_id_seq'::regclass)","comment":""},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"users_pkey","def":"CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)","table":"public.users","columns":["id"],"comment":""},{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)","table":"public.users","columns":["username"],"comment":""},{"name":"users_email_key","def":"CREATE UNIQUE INDEX users_email_key ON public.users USING btree (email)","table":"public.users","columns":["email"],"comment":""}],"constraints":[{"name":"users_username_check","type":"CHECK","def":"CHECK ((char_length((username)::text) \u003e 4))","table":"public.users","referenced_table":"","columns":["username"],"referenced_columns":[],"comment":""},{"name":"users_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.users","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""},{"name":"users_username_key","type":"UNIQUE","def":"UNIQUE (username)","table":"public.users","referenced_table":"","columns":["username"],"referenced_columns":[],"comment":""},{"name":"users_email_key","type":"UNIQUE","def":"UNIQUE (email)","table":"public.users","referenced_table":"","columns":["email"],"referenced_columns":[],"comment":""}],"triggers":[{"name":"update_users_updated","def":"CREATE TRIGGER update_users_updated AFTER INSERT OR UPDATE ON public.users FOR EACH ROW EXECUTE FUNCTION update_updated()","comment":"Update updated when users insert or update"}],"def":""},{"name":"public.user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"show_email","type":"boolean","nullable":false,"default":"false","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"user_options_pkey","def":"CREATE UNIQUE INDEX user_options_pkey ON public.user_options USING btree (user_id)","table":"public.user_options","columns":["user_id"],"comment":"PRIMARY KEY"}],"constraints":[{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","table":"public.user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":"FK"},{"name":"user_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"public.user_options","referenced_table":"","columns":["user_id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"public.posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"default":"nextval('posts_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'::character varying","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"post_types","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"labels","type":"varchar(50)[]","nullable":true,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_id_pk","def":"CREATE UNIQUE INDEX posts_id_pk ON public.posts USING btree (id)","table":"public.posts","columns":["id"],"comment":""},{"name":"posts_user_id_title_key","def":"CREATE UNIQUE INDEX posts_user_id_title_key ON public.posts USING btree (user_id, title)","table":"public.posts","columns":["title","user_id"],"comment":""},{"name":"posts_user_id_idx","def":"CREATE INDEX posts_user_id_idx ON public.posts USING btree (user_id)","table":"public.posts","columns":["user_id"],"comment":"posts.user_id index"}],"constraints":[{"name":"update_posts_updated","type":"TRIGGER","def":"CREATE CONSTRAINT TRIGGER update_posts_updated AFTER INSERT OR UPDATE ON public.posts NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE FUNCTION update_updated()","table":"public.posts","referenced_table":"","columns":["tableoid","cmax","xmax","cmin","xmin","ctid","id","user_id","title","body","post_type","labels","created","updated"],"referenced_columns":[],"comment":""},{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL (user_id)","table":"public.posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":"posts -\u003e users"},{"name":"posts_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.posts","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""},{"name":"posts_user_id_title_key","type":"UNIQUE","def":"UNIQUE (user_id, title)","table":"public.posts","referenced_table":"","columns":["user_id","title"],"referenced_columns":[],"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE CONSTRAINT TRIGGER update_posts_updated AFTER INSERT OR UPDATE ON public.posts NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE FUNCTION update_updated()","comment":"Update updated when posts update"}],"def":""},{"name":"public.comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"default":"nextval('comments_id_seq'::regclass)","comment":""},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"default":null,"comment":"","extra_def":"GENERATED ALWAYS AS (post_id * '-1'::integer) STORED"},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"comments_id_pk","def":"CREATE UNIQUE INDEX comments_id_pk ON public.comments USING btree (id)","table":"public.comments","columns":["id"],"comment":""},{"name":"comments_post_id_user_id_key","def":"CREATE UNIQUE INDEX comments_post_id_user_id_key ON public.comments USING btree (post_id, user_id)","table":"public.comments","columns":["post_id","user_id"],"comment":""},{"name":"comments_post_id_user_id_idx","def":"CREATE INDEX comments_post_id_user_id_idx ON public.comments USING btree (post_id, user_id)","table":"public.comments","columns":["post_id","user_id"],"comment":""}],"constraints":[{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users(id)","table":"public.comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":""},{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts(id)","table":"public.comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"],"comment":""},{"name":"comments_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.comments","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""},{"name":"comments_post_id_user_id_key","type":"UNIQUE","def":"UNIQUE (post_id, user_id)","table":"public.comments","referenced_table":"","columns":["post_id","user_id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"public.comment_stars","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"comment_stars_user_id_comment_post_id_comment_user_id_key","def":"CREATE UNIQUE INDEX comment_stars_user_id_comment_post_id_comment_user_id_key ON public.comment_stars USING btree (user_id, comment_post_id, comment_user_id)","table":"public.comment_stars","columns":["comment_post_id","comment_user_id","user_id"],"comment":""}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","table":"public.comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"],"comment":""},{"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":"public.comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_post_id","comment_user_id","comment_user_id"],"referenced_columns":["post_id","user_id","post_id","user_id"],"comment":""},{"name":"comment_stars_user_id_comment_post_id_comment_user_id_key","type":"UNIQUE","def":"UNIQUE (user_id, comment_post_id, comment_user_id)","table":"public.comment_stars","referenced_table":"","columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"public.logs","type":"BASE TABLE","comment":"audit log table","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"uuid","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":""},{"name":"public.post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":null,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":true,"default":null,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":""},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"timestamp without time zone","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"def":"CREATE VIEW post_comments AS (\n SELECT c.id,\n p.title,\n u.username AS post_user,\n c.comment,\n u2.username AS comment_user,\n c.created,\n c.updated\n FROM (((posts p\n LEFT JOIN comments c ON ((p.id = c.post_id)))\n LEFT JOIN users u ON ((u.id = p.user_id)))\n LEFT JOIN users u2 ON ((u2.id = c.user_id)))\n)","referenced_tables":["public.posts","public.comments","public.users"]},{"name":"public.post_comment_stars","type":"MATERIALIZED VIEW","comment":"","columns":[{"name":"id","type":"uuid","nullable":true,"default":null,"comment":""},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":""},{"name":"comment_star_user","type":"varchar(50)","nullable":true,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":true,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":"CREATE MATERIALIZED VIEW post_comment_stars AS (\n SELECT cs.id,\n cu.username AS comment_user,\n csu.username AS comment_star_user,\n cs.created,\n cs.updated\n FROM (((comments c\n LEFT JOIN comment_stars cs ON (((cs.comment_post_id = c.id) AND (cs.comment_user_id = c.user_id))))\n LEFT JOIN users cu ON ((cu.id = cs.comment_user_id)))\n LEFT JOIN users csu ON ((csu.id = cs.user_id)))\n)","referenced_tables":["public.comments","public.comment_stars","public.users"]},{"name":"public.CamelizeTable","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"CamelizeTable_id_key","def":"CREATE UNIQUE INDEX \"CamelizeTable_id_key\" ON public.\"CamelizeTable\" USING btree (id)","table":"public.CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"CamelizeTable_id_key","type":"UNIQUE","def":"UNIQUE (id)","table":"public.CamelizeTable","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"public.hyphen-table","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"CamelizeTableId","type":"uuid","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"hyphen-table_hyphen-column_key","def":"CREATE UNIQUE INDEX \"hyphen-table_hyphen-column_key\" ON public.\"hyphen-table\" USING btree (\"hyphen-column\")","table":"public.hyphen-table","columns":["hyphen-column"],"comment":""}],"constraints":[{"name":"hyphen-table_CamelizeTableId_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (\"CamelizeTableId\") REFERENCES \"CamelizeTable\"(id) ON DELETE CASCADE","table":"public.hyphen-table","referenced_table":"CamelizeTable","columns":["CamelizeTableId"],"referenced_columns":["id"],"comment":""},{"name":"hyphen-table_hyphen-column_key","type":"UNIQUE","def":"UNIQUE (\"hyphen-column\")","table":"public.hyphen-table","referenced_table":"","columns":["hyphen-column"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"administrator.blogs","type":"BASE TABLE","comment":"admin blogs","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('administrator.blogs_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"name","type":"text","nullable":false,"default":null,"comment":""},{"name":"description","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON administrator.blogs USING btree (id)","table":"administrator.blogs","columns":["id"],"comment":""}],"constraints":[{"name":"blogs_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","table":"administrator.blogs","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":""},{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"administrator.blogs","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"backup.blogs","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blogs_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"dump","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON backup.blogs USING btree (id)","table":"backup.blogs","columns":["id"],"comment":""}],"constraints":[{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blogs","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"backup.blog_options","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blog_options_id_seq'::regclass)","comment":""},{"name":"blog_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"label","type":"text","nullable":true,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"blog_options_pkey","def":"CREATE UNIQUE INDEX blog_options_pkey ON backup.blog_options USING btree (id)","table":"backup.blog_options","columns":["id"],"comment":""}],"constraints":[{"name":"blog_options_blog_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (blog_id) REFERENCES blogs(id) ON DELETE CASCADE","table":"backup.blog_options","referenced_table":"blogs","columns":["blog_id"],"referenced_columns":["id"],"comment":""},{"name":"blog_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blog_options","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"time.bar","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"bar_pkey","def":"CREATE UNIQUE INDEX bar_pkey ON \"time\".bar USING btree (id)","table":"time.bar","columns":["id"],"comment":""}],"constraints":[{"name":"bar_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.bar","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"time.hyphenated-table","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"hyphenated-table_pkey","def":"CREATE UNIQUE INDEX \"hyphenated-table_pkey\" ON \"time\".\"hyphenated-table\" USING btree (id)","table":"time.hyphenated-table","columns":["id"],"comment":""}],"constraints":[{"name":"hyphenated-table_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.hyphenated-table","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"time.referencing","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"bar_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"ht_id","type":"integer","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"referencing_pkey","def":"CREATE UNIQUE INDEX referencing_pkey ON \"time\".referencing USING btree (id)","table":"time.referencing","columns":["id"],"comment":""}],"constraints":[{"name":"referencing_bar_id","type":"FOREIGN KEY","def":"FOREIGN KEY (bar_id) REFERENCES \"time\".bar(id)","table":"time.referencing","referenced_table":"bar","columns":["bar_id"],"referenced_columns":["id"],"comment":""},{"name":"referencing_ht_id","type":"FOREIGN KEY","def":"FOREIGN KEY (ht_id) REFERENCES \"time\".\"hyphenated-table\"(id)","table":"time.referencing","referenced_table":"hyphenated-table","columns":["ht_id"],"referenced_columns":["id"],"comment":""},{"name":"referencing_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.referencing","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""}],"relations":[{"table":"public.user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","virtual":false},{"table":"public.posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL (user_id)","virtual":false},{"table":"public.comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users(id)","virtual":false},{"table":"public.comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"public.posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts(id)","virtual":false},{"table":"public.comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","virtual":false},{"table":"public.comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"public.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)","virtual":false},{"table":"public.hyphen-table","columns":["CamelizeTableId"],"cardinality":"Zero or more","parent_table":"public.CamelizeTable","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (\"CamelizeTableId\") REFERENCES \"CamelizeTable\"(id) ON DELETE CASCADE","virtual":false},{"table":"administrator.blogs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","virtual":false},{"table":"backup.blog_options","columns":["blog_id"],"cardinality":"Zero or more","parent_table":"backup.blogs","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (blog_id) REFERENCES blogs(id) ON DELETE CASCADE","virtual":false},{"table":"time.referencing","columns":["bar_id"],"cardinality":"Zero or more","parent_table":"time.bar","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (bar_id) REFERENCES \"time\".bar(id)","virtual":false},{"table":"time.referencing","columns":["ht_id"],"cardinality":"Zero or more","parent_table":"time.hyphenated-table","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (ht_id) REFERENCES \"time\".\"hyphenated-table\"(id)","virtual":false},{"table":"public.logs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"logs-\u003eusers","virtual":true},{"table":"public.logs","columns":["post_id"],"cardinality":"Zero or more","parent_table":"public.posts","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"public.logs","columns":["comment_id"],"cardinality":"Zero or more","parent_table":"public.comments","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"public.logs","columns":["comment_star_id"],"cardinality":"Zero or more","parent_table":"public.comment_stars","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true}],"functions":[{"name":"public.uuid_nil","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_ns_dns","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_ns_url","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_ns_oid","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_ns_x500","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_generate_v1","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_generate_v1mc","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_generate_v3","return_type":"uuid","arguments":"namespace uuid, name text","type":"FUNCTION"},{"name":"public.uuid_generate_v4","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_generate_v5","return_type":"uuid","arguments":"namespace uuid, name text","type":"FUNCTION"},{"name":"public.update_updated","return_type":"trigger","arguments":"","type":"FUNCTION"},{"name":"public.reset_comment","return_type":"void","arguments":"IN comment_id integer","type":"PROCEDURE"}],"driver":{"name":"postgres","database_version":"PostgreSQL 15.4 (Debian 15.4-2.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit","meta":{"current_schema":"public","search_paths":["\"$user\"","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}}} diff --git a/sample/detect_relations/schema.json b/sample/detect_relations/schema.json index fa1ec75f..efbe2dc8 100644 --- a/sample/detect_relations/schema.json +++ b/sample/detect_relations/schema.json @@ -1 +1 @@ -{"name":"relations","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"],"comment":""},{"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"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"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) 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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"],"comment":""}],"constraints":[{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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 `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_post_id_user_id_idx` (`post_id`,`user_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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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":"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":null,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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 (((`relations`.`posts` `p` left join `relations`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `relations`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `relations`.`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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":null,"comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL,\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) 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,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""}],"triggers":[],"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) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"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)","virtual":false},{"table":"comment_stars","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Detected Relation","virtual":true},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Detected Relation","virtual":true},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Detected Relation","virtual":true},{"table":"logs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Detected Relation","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Detected Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Detected 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":"Detected Relation","virtual":true},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Detected 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.0.32","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} +{"name":"relations","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"],"comment":""},{"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"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"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) 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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"],"comment":""}],"constraints":[{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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 `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_post_id_user_id_idx` (`post_id`,`user_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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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":"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":null,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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 (((`relations`.`posts` `p` left join `relations`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `relations`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `relations`.`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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":null,"comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL,\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) 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,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""}],"triggers":[],"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) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"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)","virtual":false},{"table":"comment_stars","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Detected Relation","virtual":true},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Detected Relation","virtual":true},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Detected Relation","virtual":true},{"table":"logs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Detected Relation","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Detected Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Detected 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":"Detected Relation","virtual":true},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Detected 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.2.0","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} diff --git a/sample/detect_relations_singular/schema.json b/sample/detect_relations_singular/schema.json index cfffd035..a2670ebb 100644 --- a/sample/detect_relations_singular/schema.json +++ b/sample/detect_relations_singular/schema.json @@ -1 +1 @@ -{"name":"relations_singular","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","type":"BASE TABLE","comment":"Comment\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"comment_post_id_user_id_idx","def":"KEY comment_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comment","columns":["post_id","user_id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comment","columns":["post_id","user_id"],"comment":""}],"constraints":[{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comment","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `comment` (\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 `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comment_post_id_user_id_idx` (`post_id`,`user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comment\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"comment_star","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_star","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_star","columns":["user_id","comment_post_id","comment_user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_star","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_star","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `comment_star` (\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) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"hyphen-table","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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":"log","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"log","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"log","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `log` (\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":"post","type":"BASE TABLE","comment":"Post table","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":null,"comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"post_user_id_idx","def":"KEY post_user_id_idx (id) USING BTREE","table":"post","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"post","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"post","columns":["user_id","title"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"post","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"post","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON post\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"def":"CREATE TABLE `post` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL,\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 `post_user_id_idx` (`id`) USING BTREE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Post table'","labels":[{"Name":"green","Virtual":true},{"Name":"red","Virtual":true},{"Name":"blue","Virtual":true}]},{"name":"post_comment","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comment.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":null,"comment":"post.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"default":null,"comment":"post.user.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comment.user.username"},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":"comment.created"},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":"comment.updated"}],"indexes":[],"constraints":[],"triggers":[],"def":"CREATE VIEW post_comment 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 (((`relations_singular`.`post` `p` left join `relations_singular`.`comment` `c` on((`p`.`id` = `c`.`post_id`))) left join `relations_singular`.`user` `u` on((`u`.`id` = `p`.`user_id`))) left join `relations_singular`.`user` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["post","comment","user"]},{"name":"user","type":"BASE TABLE","comment":"User table","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"user","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"user","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"user","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"user","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"user","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"user","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `user` (\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) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User table'"},{"name":"user_option","type":"BASE TABLE","comment":"User option table","columns":[{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_option","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_option","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_option","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_option","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_option_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES user (id)","table":"user_option","referenced_table":"user","columns":["user_id"],"referenced_columns":["id"],"comment":""}],"triggers":[],"def":"CREATE TABLE `user_option` (\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_option_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User option table'"}],"relations":[{"table":"user_option","columns":["user_id"],"cardinality":"Zero or one","parent_table":"user","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES user (id)","virtual":false},{"table":"comment","columns":["post_id"],"cardinality":"Zero or more","parent_table":"post","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Detected Relation","virtual":true},{"table":"comment","columns":["user_id"],"cardinality":"Zero or more","parent_table":"user","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Detected Relation","virtual":true},{"table":"comment_star","columns":["user_id"],"cardinality":"Zero or more","parent_table":"user","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Detected Relation","virtual":true},{"table":"log","columns":["user_id"],"cardinality":"Zero or more","parent_table":"user","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Detected Relation","virtual":true},{"table":"log","columns":["post_id"],"cardinality":"Zero or more","parent_table":"post","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Detected Relation","virtual":true},{"table":"log","columns":["comment_id"],"cardinality":"Zero or more","parent_table":"comment","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Detected Relation","virtual":true},{"table":"log","columns":["comment_star_id"],"cardinality":"Zero or more","parent_table":"comment_star","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Detected Relation","virtual":true},{"table":"post","columns":["user_id"],"cardinality":"Zero or more","parent_table":"user","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Detected 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.0.32","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} +{"name":"relations_singular","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","type":"BASE TABLE","comment":"Comment\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"comment_post_id_user_id_idx","def":"KEY comment_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comment","columns":["post_id","user_id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comment","columns":["post_id","user_id"],"comment":""}],"constraints":[{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comment","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `comment` (\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 `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comment_post_id_user_id_idx` (`post_id`,`user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comment\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"comment_star","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_star","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_star","columns":["user_id","comment_post_id","comment_user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_star","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_star","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `comment_star` (\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) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"hyphen-table","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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":"log","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"log","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"log","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `log` (\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":"post","type":"BASE TABLE","comment":"Post table","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":null,"comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"post_user_id_idx","def":"KEY post_user_id_idx (id) USING BTREE","table":"post","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"post","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"post","columns":["user_id","title"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"post","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"post","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON post\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"def":"CREATE TABLE `post` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL,\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 `post_user_id_idx` (`id`) USING BTREE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Post table'","labels":[{"Name":"green","Virtual":true},{"Name":"red","Virtual":true},{"Name":"blue","Virtual":true}]},{"name":"post_comment","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comment.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":null,"comment":"post.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"default":null,"comment":"post.user.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comment.user.username"},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":"comment.created"},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":"comment.updated"}],"indexes":[],"constraints":[],"triggers":[],"def":"CREATE VIEW post_comment 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 (((`relations_singular`.`post` `p` left join `relations_singular`.`comment` `c` on((`p`.`id` = `c`.`post_id`))) left join `relations_singular`.`user` `u` on((`u`.`id` = `p`.`user_id`))) left join `relations_singular`.`user` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["post","comment","user"]},{"name":"user","type":"BASE TABLE","comment":"User table","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"user","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"user","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"user","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"user","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"user","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"user","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `user` (\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) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User table'"},{"name":"user_option","type":"BASE TABLE","comment":"User option table","columns":[{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_option","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_option","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_option","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_option","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_option_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES user (id)","table":"user_option","referenced_table":"user","columns":["user_id"],"referenced_columns":["id"],"comment":""}],"triggers":[],"def":"CREATE TABLE `user_option` (\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_option_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User option table'"}],"relations":[{"table":"user_option","columns":["user_id"],"cardinality":"Zero or one","parent_table":"user","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES user (id)","virtual":false},{"table":"comment","columns":["post_id"],"cardinality":"Zero or more","parent_table":"post","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Detected Relation","virtual":true},{"table":"comment","columns":["user_id"],"cardinality":"Zero or more","parent_table":"user","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Detected Relation","virtual":true},{"table":"comment_star","columns":["user_id"],"cardinality":"Zero or more","parent_table":"user","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Detected Relation","virtual":true},{"table":"log","columns":["user_id"],"cardinality":"Zero or more","parent_table":"user","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Detected Relation","virtual":true},{"table":"log","columns":["post_id"],"cardinality":"Zero or more","parent_table":"post","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Detected Relation","virtual":true},{"table":"log","columns":["comment_id"],"cardinality":"Zero or more","parent_table":"comment","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Detected Relation","virtual":true},{"table":"log","columns":["comment_star_id"],"cardinality":"Zero or more","parent_table":"comment_star","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Detected Relation","virtual":true},{"table":"post","columns":["user_id"],"cardinality":"Zero or more","parent_table":"user","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Detected 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.2.0","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} diff --git a/sample/dict/schema.json b/sample/dict/schema.json index bc3f925f..0ddc3137 100644 --- a/sample/dict/schema.json +++ b/sample/dict/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"","tables":[{"name":"CamelizeTable","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"],"comment":""},{"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"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"default":null,"comment":"","extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"post_user","type":"varchar(50)","nullable":true,"default":null,"comment":""},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":""},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"],"comment":""}],"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"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,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","referenced_table":null,"columns":null,"referenced_columns":null,"comment":""}],"triggers":[],"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.0.32","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} +{"name":"testdb","desc":"","tables":[{"name":"CamelizeTable","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"],"comment":""},{"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"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"default":null,"comment":"","extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"post_user","type":"varchar(50)","nullable":true,"default":null,"comment":""},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":""},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"],"comment":""}],"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"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,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","referenced_table":null,"columns":null,"referenced_columns":null,"comment":""}],"triggers":[],"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.2.0","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} diff --git a/sample/exclude/schema.json b/sample/exclude/schema.json index 7f8d8ebe..44cc06b6 100644 --- a/sample/exclude/schema.json +++ b/sample/exclude/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"","tables":[{"name":"comment_stars","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"],"comment":""},{"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"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"default":null,"comment":"","extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"],"comment":""}],"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"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,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","referenced_table":null,"columns":null,"referenced_columns":null,"comment":""}],"triggers":[],"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.0.32","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} +{"name":"testdb","desc":"","tables":[{"name":"comment_stars","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"],"comment":""},{"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"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"default":null,"comment":"","extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"],"comment":""}],"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"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,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","referenced_table":null,"columns":null,"referenced_columns":null,"comment":""}],"triggers":[],"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.2.0","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} diff --git a/sample/font/schema.json b/sample/font/schema.json index 2cd3df3e..c127a5ab 100644 --- a/sample/font/schema.json +++ b/sample/font/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"","tables":[{"name":"CamelizeTable","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"],"comment":""},{"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"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"default":null,"comment":"","extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"本文"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"],"comment":""}],"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"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,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","referenced_table":null,"columns":null,"referenced_columns":null,"comment":""}],"triggers":[],"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.0.32","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"サンプル","Virtual":true},{"Name":"tbls","Virtual":true}]} +{"name":"testdb","desc":"","tables":[{"name":"CamelizeTable","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"],"comment":""},{"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"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"default":null,"comment":"","extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"本文"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"],"comment":""}],"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"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,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","referenced_table":null,"columns":null,"referenced_columns":null,"comment":""}],"triggers":[],"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.2.0","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 7ea919af..885e275a 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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"],"comment":""},{"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"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"default":null,"comment":"","extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"],"comment":""}],"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"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,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","referenced_table":null,"columns":null,"referenced_columns":null,"comment":""}],"triggers":[],"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.0.32","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"],"comment":""},{"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"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"default":null,"comment":"","extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"],"comment":""}],"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"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,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","referenced_table":null,"columns":null,"referenced_columns":null,"comment":""}],"triggers":[],"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.2.0","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 1e5a9258..cbcfd474 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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"],"comment":""},{"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"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"default":null,"comment":"","extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"],"comment":""}],"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"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,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":"","labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com","labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","referenced_table":null,"columns":null,"referenced_columns":null,"comment":""}],"triggers":[],"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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.0.32","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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"],"comment":""},{"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"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"default":null,"comment":"","extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"],"comment":""}],"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"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,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":"","labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com","labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","referenced_table":null,"columns":null,"referenced_columns":null,"comment":""}],"triggers":[],"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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.2.0","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} diff --git a/sample/mariadb/schema.json b/sample/mariadb/schema.json index a1758bbb..b3eba269 100644 --- a/sample/mariadb/schema.json +++ b/sample/mariadb/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"bigint(20)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint(20) NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint(20)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint(20)","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int(11)","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint(20)","nullable":true,"default":"NULL","extra_def":"GENERATED ALWAYS AS `post_id` * -1 VIRTUAL","comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":"NULL","comment":""}],"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"],"comment":""},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `comments` (\n `id` bigint(20) NOT NULL AUTO_INCREMENT,\n `post_id` bigint(20) NOT NULL,\n `user_id` int(11) NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint(20) 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`) USING HASH,\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_general_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"comment_stars","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"bigint(20)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint(20)","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int(11)","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":"current_timestamp()","extra_def":"on update current_timestamp()","comment":""},{"name":"updated","type":"timestamp","nullable":false,"default":"'0000-00-00 00:00:00'","comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"],"comment":""},{"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"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `comment_stars` (\n `id` bigint(20) NOT NULL AUTO_INCREMENT,\n `user_id` int(11) NOT NULL,\n `comment_post_id` bigint(20) NOT NULL,\n `comment_user_id` int(11) NOT NULL,\n `created` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),\n `updated` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',\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_general_ci"},{"name":"hyphen-table","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"bigint(20)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint(20) 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_general_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint(20)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint(20)","nullable":true,"default":"NULL","comment":""},{"name":"comment_id","type":"bigint(20)","nullable":true,"default":"NULL","comment":""},{"name":"comment_star_id","type":"bigint(20)","nullable":true,"default":"NULL","comment":""},{"name":"payload","type":"text","nullable":true,"default":"NULL","comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `logs` (\n `id` bigint(20) NOT NULL AUTO_INCREMENT,\n `user_id` int(11) NOT NULL,\n `post_id` bigint(20) DEFAULT NULL,\n `comment_id` bigint(20) DEFAULT NULL,\n `comment_star_id` bigint(20) DEFAULT NULL,\n `payload` text DEFAULT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Auditログ'"},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint(20)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":"NULL","comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"],"comment":""}],"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"def":"CREATE TABLE `posts` (\n `id` bigint(20) NOT NULL AUTO_INCREMENT,\n `user_id` int(11) 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 ON UPDATE NO ACTION\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Posts table'","labels":[{"Name":"green","Virtual":true},{"Name":"red","Virtual":true},{"Name":"blue","Virtual":true}]},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint(20)","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,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":"NULL","comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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":"same_name_constraints","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"bigint(20)","nullable":true,"default":"NULL","comment":""},{"name":"user_id","type":"int(11)","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"same_name","def":"UNIQUE KEY same_name (user_id, id) USING BTREE","table":"same_name_constraints","columns":["user_id","id"],"comment":""}],"constraints":[{"name":"same_name","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"same_name_constraints","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":""},{"name":"same_name","type":"UNIQUE","def":"UNIQUE KEY same_name (user_id, id)","table":"same_name_constraints","referenced_table":null,"columns":["user_id","id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `same_name_constraints` (\n `id` bigint(20) DEFAULT NULL,\n `user_id` int(11) NOT NULL,\n UNIQUE KEY `same_name` (`user_id`,`id`),\n CONSTRAINT `same_name` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int(11)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":"","labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com","labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"timestamp","nullable":false,"default":"current_timestamp()","extra_def":"on update current_timestamp()","comment":""},{"name":"updated","type":"timestamp","nullable":false,"default":"'0000-00-00 00:00:00'","comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `users` (\n `id` int(11) 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 DEFAULT current_timestamp() ON UPDATE current_timestamp(),\n `updated` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`)\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Users table'"},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int(11)","nullable":false,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":"current_timestamp()","extra_def":"on update current_timestamp()","comment":""},{"name":"updated","type":"timestamp","nullable":false,"default":"'0000-00-00 00:00:00'","comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"def":"CREATE TABLE `user_options` (\n `user_id` int(11) NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT 0,\n `created` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),\n `updated` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',\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 ON UPDATE NO ACTION\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='User options table'"}],"relations":[{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"table":"same_name_constraints","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)","virtual":false},{"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)","virtual":false},{"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":[],"driver":{"name":"mariadb","database_version":"10.5.18-MariaDB-1:10.5.18+maria~ubu2004","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","comment":"","columns":[{"name":"id","type":"bigint(20)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint(20) NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint(20)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint(20)","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int(11)","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint(20)","nullable":true,"default":"NULL","extra_def":"GENERATED ALWAYS AS `post_id` * -1 VIRTUAL","comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":"NULL","comment":""}],"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"],"comment":""},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `comments` (\n `id` bigint(20) NOT NULL AUTO_INCREMENT,\n `post_id` bigint(20) NOT NULL,\n `user_id` int(11) NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint(20) 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`) USING HASH,\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_general_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"comment_stars","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"bigint(20)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint(20)","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int(11)","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":"current_timestamp()","extra_def":"on update current_timestamp()","comment":""},{"name":"updated","type":"timestamp","nullable":false,"default":"'0000-00-00 00:00:00'","comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"],"comment":""},{"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"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `comment_stars` (\n `id` bigint(20) NOT NULL AUTO_INCREMENT,\n `user_id` int(11) NOT NULL,\n `comment_post_id` bigint(20) NOT NULL,\n `comment_user_id` int(11) NOT NULL,\n `created` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),\n `updated` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',\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_general_ci"},{"name":"hyphen-table","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"bigint(20)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint(20) 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_general_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint(20)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint(20)","nullable":true,"default":"NULL","comment":""},{"name":"comment_id","type":"bigint(20)","nullable":true,"default":"NULL","comment":""},{"name":"comment_star_id","type":"bigint(20)","nullable":true,"default":"NULL","comment":""},{"name":"payload","type":"text","nullable":true,"default":"NULL","comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `logs` (\n `id` bigint(20) NOT NULL AUTO_INCREMENT,\n `user_id` int(11) NOT NULL,\n `post_id` bigint(20) DEFAULT NULL,\n `comment_id` bigint(20) DEFAULT NULL,\n `comment_star_id` bigint(20) DEFAULT NULL,\n `payload` text DEFAULT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Auditログ'"},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint(20)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":"NULL","comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"],"comment":""}],"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"def":"CREATE TABLE `posts` (\n `id` bigint(20) NOT NULL AUTO_INCREMENT,\n `user_id` int(11) 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 ON UPDATE NO ACTION\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Posts table'","labels":[{"Name":"green","Virtual":true},{"Name":"red","Virtual":true},{"Name":"blue","Virtual":true}]},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint(20)","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,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":"NULL","comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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":"same_name_constraints","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"bigint(20)","nullable":true,"default":"NULL","comment":""},{"name":"user_id","type":"int(11)","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"same_name","def":"UNIQUE KEY same_name (user_id, id) USING BTREE","table":"same_name_constraints","columns":["user_id","id"],"comment":""}],"constraints":[{"name":"same_name","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"same_name_constraints","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":""},{"name":"same_name","type":"UNIQUE","def":"UNIQUE KEY same_name (user_id, id)","table":"same_name_constraints","referenced_table":null,"columns":["user_id","id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `same_name_constraints` (\n `id` bigint(20) DEFAULT NULL,\n `user_id` int(11) NOT NULL,\n UNIQUE KEY `same_name` (`user_id`,`id`),\n CONSTRAINT `same_name` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int(11)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":"","labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com","labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"timestamp","nullable":false,"default":"current_timestamp()","extra_def":"on update current_timestamp()","comment":""},{"name":"updated","type":"timestamp","nullable":false,"default":"'0000-00-00 00:00:00'","comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `users` (\n `id` int(11) 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 DEFAULT current_timestamp() ON UPDATE current_timestamp(),\n `updated` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`)\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Users table'"},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int(11)","nullable":false,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":"current_timestamp()","extra_def":"on update current_timestamp()","comment":""},{"name":"updated","type":"timestamp","nullable":false,"default":"'0000-00-00 00:00:00'","comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"def":"CREATE TABLE `user_options` (\n `user_id` int(11) NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT 0,\n `created` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),\n `updated` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',\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 ON UPDATE NO ACTION\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='User options table'"}],"relations":[{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"table":"same_name_constraints","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)","virtual":false},{"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)","virtual":false},{"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":[],"driver":{"name":"mariadb","database_version":"10.5.22-MariaDB-1:10.5.22+maria~ubu2004","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} diff --git a/sample/mermaid/README.md b/sample/mermaid/README.md index 30d8465f..a6b27044 100644 --- a/sample/mermaid/README.md +++ b/sample/mermaid/README.md @@ -44,7 +44,7 @@ erDiagram "logs" }o--|| "users" : "logs->users" "logs" }o--o| "posts" : "Additional Relation" "logs" }o--o| "comments" : "Additional Relation" -"logs" }o--o| "comment_stars" : "Additional Relation" +"logs" ||--|| "comment_stars" : "Additional Relation" "CamelizeTable" { bigint id PK diff --git a/sample/mermaid/comment_stars.md b/sample/mermaid/comment_stars.md index c623398b..423e4f14 100644 --- a/sample/mermaid/comment_stars.md +++ b/sample/mermaid/comment_stars.md @@ -58,7 +58,7 @@ CREATE TABLE `comment_stars` ( ```mermaid erDiagram -"logs" }o--o| "comment_stars" : "Additional Relation" +"logs" ||--|| "comment_stars" : "Additional Relation" "comment_stars" }o--|| "comments" : "FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)" "comment_stars" }o--|| "users" : "FOREIGN KEY (comment_user_id) REFERENCES users (id)" diff --git a/sample/mermaid/logs.md b/sample/mermaid/logs.md index 3db335cc..cc8ba63e 100644 --- a/sample/mermaid/logs.md +++ b/sample/mermaid/logs.md @@ -54,7 +54,7 @@ erDiagram "logs" }o--|| "users" : "logs->users" "logs" }o--o| "posts" : "Additional Relation" "logs" }o--o| "comments" : "Additional Relation" -"logs" }o--o| "comment_stars" : "Additional Relation" +"logs" ||--|| "comment_stars" : "Additional Relation" "logs" { bigint id PK diff --git a/sample/mermaid/schema.json b/sample/mermaid/schema.json index 1e5a9258..79bb53a5 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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"],"comment":""},{"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"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"default":null,"comment":"","extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"],"comment":""}],"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"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,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":"","labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com","labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","referenced_table":null,"columns":null,"referenced_columns":null,"comment":""}],"triggers":[],"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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.0.32","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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"],"comment":""},{"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"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"default":null,"comment":"","extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"],"comment":""}],"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"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,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":"","labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com","labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","referenced_table":null,"columns":null,"referenced_columns":null,"comment":""}],"triggers":[],"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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.2.0","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} diff --git a/sample/mssql/README.md b/sample/mssql/README.md index 83588f12..5bde8483 100644 --- a/sample/mssql/README.md +++ b/sample/mssql/README.md @@ -12,6 +12,7 @@ Sample database document. | Name | Columns | Comment | Type | Labels | | ---- | ------- | ------- | ---- | ------ | +| [Rabbits.Running](Rabbits.Running.md) | 3 | | BASIC TABLE | | | [users](users.md) | 6 | Users table | BASIC TABLE | | | [user_options](user_options.md) | 4 | User options table | BASIC TABLE | | | [posts](posts.md) | 6 | | BASIC TABLE | `green` `red` `blue` | @@ -24,7 +25,6 @@ Sample database document. | [administrator.blogs](administrator.blogs.md) | 6 | admin blogs | BASIC TABLE | | | [name with spaces](name%20with%20spaces.md) | 1 | | VIEW | | | [Sales.Product](Sales.Product.md) | 2 | | BASIC TABLE | | -| [Rabbits.Running](Rabbits.Running.md) | 3 | | BASIC TABLE | | ## Stored procedures and functions diff --git a/sample/mssql/schema.json b/sample/mssql/schema.json index f3d13edc..68c45d60 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,"default":null,"comment":""},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"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,"default":null,"comment":"ex. user@example.com"},{"name":"created","type":"date","nullable":false,"default":null,"comment":""},{"name":"updated","type":"date","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PK__users_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"users","columns":["id"],"comment":""},{"name":"UQ__users_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ email ]","table":"users","columns":["email"],"comment":""},{"name":"UQ__users_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ username ]","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"PK__users_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"UQ__users_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ email ]","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"UQ__users_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ username ]","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""},{"name":"CK__users__username_*","type":"CHECK","def":"CHECK(len([username])\u003e(4))","table":"users","referenced_table":null,"columns":null,"referenced_columns":null,"comment":""}],"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;","comment":""}],"def":""},{"name":"user_options","type":"BASIC TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"show_email","type":"bit","nullable":false,"default":"((0))","comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""},{"name":"updated","type":"date","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PK__user_opt_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ user_id ]","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PK__user_opt_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ user_id ]","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"def":""},{"name":"posts","type":"BASIC TABLE","comment":"","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":null,"comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"created","type":"date","nullable":false,"default":null,"comment":""},{"name":"updated","type":"date","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_id_pk","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"posts","columns":["id"],"comment":""},{"name":"UQ__posts_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, title ]","table":"posts","columns":["user_id","title"],"comment":""},{"name":"posts_user_id_idx","def":"NONCLUSTERED, [ user_id ]","table":"posts","columns":["user_id"],"comment":""}],"constraints":[{"name":"posts_id_pk","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"UQ__posts_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, title ]","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"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;","comment":""}],"def":"","labels":[{"Name":"green","Virtual":true},{"Name":"red","Virtual":true},{"Name":"blue","Virtual":true}]},{"name":"comments","type":"BASIC TABLE","comment":"","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""},{"name":"updated","type":"date","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"comments_id_pk","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"comments","columns":["id"],"comment":""},{"name":"UQ__comments_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"],"comment":""},{"name":"comments_post_id_user_id_idx","def":"NONCLUSTERED, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"],"comment":""}],"constraints":[{"name":"comments_id_pk","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"UQ__comments_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ post_id, user_id ]","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""},{"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"],"comment":""}],"triggers":[],"def":""},{"name":"comment_stars","type":"BASIC TABLE","comment":"","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""},{"name":"updated","type":"date","nullable":true,"default":null,"comment":""}],"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"],"comment":""}],"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","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""},{"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"],"comment":""}],"triggers":[],"def":""},{"name":"logs","type":"BASIC TABLE","comment":"","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"int","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"int","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"int","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":""},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"int","nullable":true,"default":null,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":null,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":""},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"date","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"date","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":""},{"name":"hyphen-table","type":"BASIC TABLE","comment":"","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":""},{"name":"administrator.blogs","type":"BASIC TABLE","comment":"admin blogs","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"name","type":"text","nullable":false,"default":null,"comment":""},{"name":"description","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""},{"name":"updated","type":"date","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PK__blogs_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"administrator.blogs","columns":["id"],"comment":""}],"constraints":[{"name":"PK__blogs_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"administrator.blogs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"def":""},{"name":"name with spaces","type":"VIEW","comment":"","columns":[{"name":"title","type":"varchar(255)","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"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","comment":"","columns":[{"name":"ProductID","type":"int","nullable":false,"default":null,"comment":""},{"name":"SalesPersonID","type":"int","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PK__Product_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ ProductID ]","table":"Sales.Product","columns":["ProductID"],"comment":""},{"name":"UQ__Product_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ SalesPersonID ]","table":"Sales.Product","columns":["SalesPersonID"],"comment":""}],"constraints":[{"name":"PK__Product_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ ProductID ]","table":"Sales.Product","referenced_table":null,"columns":["ProductID"],"referenced_columns":null,"comment":""},{"name":"UQ__Product_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ SalesPersonID ]","table":"Sales.Product","referenced_table":null,"columns":["SalesPersonID"],"referenced_columns":null,"comment":""}],"triggers":[],"def":""},{"name":"Rabbits.Running","type":"BASIC TABLE","comment":"","columns":[{"name":"LocationID","type":"int","nullable":false,"default":null,"comment":""},{"name":"ProductID","type":"int","nullable":true,"default":null,"comment":""},{"name":"EmployeeID","type":"int","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PK__Running_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ LocationID ]","table":"Rabbits.Running","columns":["LocationID"],"comment":""},{"name":"UQ__Running_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ EmployeeID ]","table":"Rabbits.Running","columns":["EmployeeID"],"comment":""},{"name":"UQ__Running_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ ProductID ]","table":"Rabbits.Running","columns":["ProductID"],"comment":""}],"constraints":[{"name":"PK__Running_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ LocationID ]","table":"Rabbits.Running","referenced_table":null,"columns":["LocationID"],"referenced_columns":null,"comment":""},{"name":"UQ__Running_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ EmployeeID ]","table":"Rabbits.Running","referenced_table":null,"columns":["EmployeeID"],"referenced_columns":null,"comment":""},{"name":"UQ__Running_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ ProductID ]","table":"Rabbits.Running","referenced_table":null,"columns":["ProductID"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"def":""}],"relations":[{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","virtual":false},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","virtual":false},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","virtual":false},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","virtual":false},{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","virtual":false},{"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":"","virtual":false},{"table":"administrator.blogs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","virtual":false},{"table":"Rabbits.Running","columns":["ProductID"],"cardinality":"Zero or one","parent_table":"Sales.Product","parent_columns":["SalesPersonID"],"parent_cardinality":"Zero or one","def":"","virtual":false},{"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 2017 (RTM-CU31) (KB5016884) - 14.0.3456.2 (X64) \n\tSep 2 2022 11:01:50 \n\tCopyright (C) 2017 Microsoft Corporation\n\tDeveloper Edition (64-bit) on Linux (Ubuntu 18.04.6 LTS)","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"Rabbits.Running","type":"BASIC TABLE","comment":"","columns":[{"name":"LocationID","type":"int","nullable":false,"default":null,"comment":""},{"name":"ProductID","type":"int","nullable":true,"default":null,"comment":""},{"name":"EmployeeID","type":"int","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PK__Running_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ LocationID ]","table":"Rabbits.Running","columns":["LocationID"],"comment":""},{"name":"UQ__Running_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ EmployeeID ]","table":"Rabbits.Running","columns":["EmployeeID"],"comment":""},{"name":"UQ__Running_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ ProductID ]","table":"Rabbits.Running","columns":["ProductID"],"comment":""}],"constraints":[{"name":"PK__Running_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ LocationID ]","table":"Rabbits.Running","referenced_table":null,"columns":["LocationID"],"referenced_columns":null,"comment":""},{"name":"UQ__Running_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ EmployeeID ]","table":"Rabbits.Running","referenced_table":null,"columns":["EmployeeID"],"referenced_columns":null,"comment":""},{"name":"UQ__Running_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ ProductID ]","table":"Rabbits.Running","referenced_table":null,"columns":["ProductID"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"def":""},{"name":"users","type":"BASIC TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"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,"default":null,"comment":"ex. user@example.com"},{"name":"created","type":"date","nullable":false,"default":null,"comment":""},{"name":"updated","type":"date","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PK__users_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"users","columns":["id"],"comment":""},{"name":"UQ__users_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ email ]","table":"users","columns":["email"],"comment":""},{"name":"UQ__users_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ username ]","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"PK__users_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"UQ__users_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ email ]","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"UQ__users_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ username ]","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""},{"name":"CK__users__username_*","type":"CHECK","def":"CHECK(len([username])\u003e(4))","table":"users","referenced_table":null,"columns":null,"referenced_columns":null,"comment":""}],"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;","comment":""}],"def":""},{"name":"user_options","type":"BASIC TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"show_email","type":"bit","nullable":false,"default":"((0))","comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""},{"name":"updated","type":"date","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PK__user_opt_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ user_id ]","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PK__user_opt_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ user_id ]","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"def":""},{"name":"posts","type":"BASIC TABLE","comment":"","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":null,"comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"created","type":"date","nullable":false,"default":null,"comment":""},{"name":"updated","type":"date","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_id_pk","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"posts","columns":["id"],"comment":""},{"name":"UQ__posts_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, title ]","table":"posts","columns":["user_id","title"],"comment":""},{"name":"posts_user_id_idx","def":"NONCLUSTERED, [ user_id ]","table":"posts","columns":["user_id"],"comment":""}],"constraints":[{"name":"posts_id_pk","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"UQ__posts_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, title ]","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"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;","comment":""}],"def":"","labels":[{"Name":"green","Virtual":true},{"Name":"red","Virtual":true},{"Name":"blue","Virtual":true}]},{"name":"comments","type":"BASIC TABLE","comment":"","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""},{"name":"updated","type":"date","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"comments_id_pk","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"comments","columns":["id"],"comment":""},{"name":"UQ__comments_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"],"comment":""},{"name":"comments_post_id_user_id_idx","def":"NONCLUSTERED, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"],"comment":""}],"constraints":[{"name":"comments_id_pk","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"UQ__comments_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ post_id, user_id ]","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""},{"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"],"comment":""}],"triggers":[],"def":""},{"name":"comment_stars","type":"BASIC TABLE","comment":"","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""},{"name":"updated","type":"date","nullable":true,"default":null,"comment":""}],"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"],"comment":""}],"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","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""},{"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"],"comment":""}],"triggers":[],"def":""},{"name":"logs","type":"BASIC TABLE","comment":"","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"int","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"int","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"int","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":""},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"int","nullable":true,"default":null,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":null,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":""},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"date","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"date","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":""},{"name":"hyphen-table","type":"BASIC TABLE","comment":"","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":""},{"name":"administrator.blogs","type":"BASIC TABLE","comment":"admin blogs","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"name","type":"text","nullable":false,"default":null,"comment":""},{"name":"description","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""},{"name":"updated","type":"date","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PK__blogs_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"administrator.blogs","columns":["id"],"comment":""}],"constraints":[{"name":"PK__blogs_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"administrator.blogs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"def":""},{"name":"name with spaces","type":"VIEW","comment":"","columns":[{"name":"title","type":"varchar(255)","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"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","comment":"","columns":[{"name":"ProductID","type":"int","nullable":false,"default":null,"comment":""},{"name":"SalesPersonID","type":"int","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PK__Product_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ ProductID ]","table":"Sales.Product","columns":["ProductID"],"comment":""},{"name":"UQ__Product_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ SalesPersonID ]","table":"Sales.Product","columns":["SalesPersonID"],"comment":""}],"constraints":[{"name":"PK__Product_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ ProductID ]","table":"Sales.Product","referenced_table":null,"columns":["ProductID"],"referenced_columns":null,"comment":""},{"name":"UQ__Product_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ SalesPersonID ]","table":"Sales.Product","referenced_table":null,"columns":["SalesPersonID"],"referenced_columns":null,"comment":""}],"triggers":[],"def":""}],"relations":[{"table":"Rabbits.Running","columns":["ProductID"],"cardinality":"Zero or one","parent_table":"Sales.Product","parent_columns":["SalesPersonID"],"parent_cardinality":"Zero or one","def":"","virtual":false},{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","virtual":false},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","virtual":false},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","virtual":false},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","virtual":false},{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","virtual":false},{"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":"","virtual":false},{"table":"administrator.blogs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","virtual":false},{"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 2017 (RTM-CU31-GDR) (KB5029376) - 14.0.3465.1 (X64) \n\tJul 30 2023 15:31:58 \n\tCopyright (C) 2017 Microsoft Corporation\n\tDeveloper Edition (64-bit) on Linux (Ubuntu 18.04.6 LTS)","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} diff --git a/sample/mssql/schema.svg b/sample/mssql/schema.svg index 00c04cf1..fc04c709 100644 --- a/sample/mssql/schema.svg +++ b/sample/mssql/schema.svg @@ -4,380 +4,380 @@ - + testdb - - + + +Rabbits.Running + + +Rabbits.Running +     +[BASIC TABLE] + +LocationID     +[int] + +ProductID     +[int] + +EmployeeID     +[int] + + + +Sales.Product + + +Sales.Product +     +[BASIC TABLE] + +ProductID     +[int] + +SalesPersonID     +[int] + + + +Rabbits.Running:ProductID->Sales.Product:SalesPersonID + + + + + users - - -users -     -[BASIC TABLE] - -id     -[int] - -username     -[varchar(50)] - -password     -[varchar(50)] - -email     -[varchar(355)] - -created     -[date] - -updated     -[date] + + +users +     +[BASIC TABLE] + +id     +[int] + +username     +[varchar(50)] + +password     +[varchar(50)] + +email     +[varchar(355)] + +created     +[date] + +updated     +[date] - + user_options - - -user_options -     -[BASIC TABLE] - -user_id     -[int] - -show_email     -[bit] - -created     -[date] - -updated     -[date] + + +user_options +     +[BASIC TABLE] + +user_id     +[int] + +show_email     +[bit] + +created     +[date] + +updated     +[date] - + user_options:user_id->users:id - - + + - + posts - - -posts -     -[BASIC TABLE] - -id     -[int] - -user_id     -[int] - -title     -[varchar(255)] - -body     -[text] - -created     -[date] - -updated     -[date] + + +posts +     +[BASIC TABLE] + +id     +[int] + +user_id     +[int] + +title     +[varchar(255)] + +body     +[text] + +created     +[date] + +updated     +[date] - + posts:user_id->users:id - - + + - + comments - - -comments -     -[BASIC TABLE] - -id     -[int] - -post_id     -[int] - -user_id     -[int] - -comment     -[text] - -created     -[date] - -updated     -[date] + + +comments +     +[BASIC TABLE] + +id     +[int] + +post_id     +[int] + +user_id     +[int] + +comment     +[text] + +created     +[date] + +updated     +[date] - + comments:user_id->users:id - - + + - + comments:post_id->posts:id - - + + - + comment_stars - - -comment_stars -     -[BASIC TABLE] - -id     -[int] - -user_id     -[int] - -comment_post_id     -[int] - -comment_user_id     -[int] - -created     -[date] - -updated     -[date] + + +comment_stars +     +[BASIC TABLE] + +id     +[int] + +user_id     +[int] + +comment_post_id     +[int] + +comment_user_id     +[int] + +created     +[date] + +updated     +[date] - + comment_stars:comment_user_id->users:id - - + + - + comment_stars:comment_post_id->comments:post_id - - + + - + logs - - -logs -     -[BASIC TABLE] - -id     -[int] - -user_id     -[int] - -post_id     -[int] - -comment_id     -[int] - -comment_star_id     -[int] - -payload     -[text] - -created     -[date] + + +logs +     +[BASIC TABLE] + +id     +[int] + +user_id     +[int] + +post_id     +[int] + +comment_id     +[int] + +comment_star_id     +[int] + +payload     +[text] + +created     +[date] logs:user_id->users:id - - -logs->users + + +logs->users logs:post_id->posts:id - - -Additional Relation + + +Additional Relation logs:comment_id->comments:id - - -Additional Relation + + +Additional Relation logs:comment_star_id->comment_stars:id - - -Additional Relation + + +Additional Relation - + post_comments - - -post_comments -     -[VIEW] - -id     -[int] - -title     -[varchar(255)] - -post_user     -[varchar(50)] - -comment     -[text] - -comment_user     -[varchar(50)] - -created     -[date] - -updated     -[date] + + +post_comments +     +[VIEW] + +id     +[int] + +title     +[varchar(255)] + +post_user     +[varchar(50)] + +comment     +[text] + +comment_user     +[varchar(50)] + +created     +[date] + +updated     +[date] - + CamelizeTable - - -CamelizeTable -     -[BASIC TABLE] - -id     -[int] - -created     -[date] + + +CamelizeTable +     +[BASIC TABLE] + +id     +[int] + +created     +[date] - + hyphen-table - - -hyphen-table -     -[BASIC TABLE] - -id     -[int] - -hyphen-column     -[text] - -created     -[date] + + +hyphen-table +     +[BASIC TABLE] + +id     +[int] + +hyphen-column     +[text] + +created     +[date] - + administrator.blogs - - -administrator.blogs -     -[BASIC TABLE] - -id     -[int] - -user_id     -[int] - -name     -[text] - -description     -[text] - -created     -[date] - -updated     -[date] + + +administrator.blogs +     +[BASIC TABLE] + +id     +[int] + +user_id     +[int] + +name     +[text] + +description     +[text] + +created     +[date] + +updated     +[date] - + administrator.blogs:user_id->users:id - - + + - -name with spaces - - -name with spaces -     -[VIEW] - -title     -[varchar(255)] - - -Sales.Product - - -Sales.Product -     -[BASIC TABLE] - -ProductID     -[int] - -SalesPersonID     -[int] - - - -Rabbits.Running - - -Rabbits.Running -     -[BASIC TABLE] - -LocationID     -[int] - -ProductID     -[int] - -EmployeeID     -[int] - - - -Rabbits.Running:ProductID->Sales.Product:SalesPersonID - - +name with spaces + + +name with spaces +     +[VIEW] + +title     +[varchar(255)] diff --git a/sample/mysql/schema.json b/sample/mysql/schema.json index 1e5a9258..79bb53a5 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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"],"comment":""},{"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"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"default":null,"comment":"","extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"],"comment":""}],"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"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,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":"","labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com","labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","referenced_table":null,"columns":null,"referenced_columns":null,"comment":""}],"triggers":[],"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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.0.32","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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"],"comment":""},{"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"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"default":null,"comment":"","extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"],"comment":""}],"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"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,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":"","labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com","labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","referenced_table":null,"columns":null,"referenced_columns":null,"comment":""}],"triggers":[],"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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.2.0","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} diff --git a/sample/mysql56/schema.json b/sample/mysql56/schema.json index d8385e45..9947cf84 100644 --- a/sample/mysql56/schema.json +++ b/sample/mysql56/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"bigint(20)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint(20) NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=latin1"},{"name":"comment_stars","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"bigint(20)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint(20)","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int(11)","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":"CURRENT_TIMESTAMP","extra_def":"on update CURRENT_TIMESTAMP","comment":""},{"name":"updated","type":"timestamp","nullable":false,"default":"0000-00-00 00:00:00","comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"],"comment":""},{"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"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `comment_stars` (\n `id` bigint(20) NOT NULL AUTO_INCREMENT,\n `user_id` int(11) NOT NULL,\n `comment_post_id` bigint(20) NOT NULL,\n `comment_user_id` int(11) NOT NULL,\n `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n `updated` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',\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=latin1"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint(20)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint(20)","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int(11)","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `comments` (\n `id` bigint(20) NOT NULL AUTO_INCREMENT,\n `post_id` bigint(20) NOT NULL,\n `user_id` int(11) NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\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`) USING HASH,\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=latin1 COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"bigint(20)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint(20) NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=latin1"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint(20)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint(20)","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint(20)","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"bigint(20)","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `logs` (\n `id` bigint(20) NOT NULL AUTO_INCREMENT,\n `user_id` int(11) NOT NULL,\n `post_id` bigint(20) DEFAULT NULL,\n `comment_id` bigint(20) DEFAULT NULL,\n `comment_star_id` bigint(20) DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Auditログ'"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint(20)","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,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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(20)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"],"comment":""}],"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"def":"CREATE TABLE `posts` (\n `id` bigint(20) NOT NULL AUTO_INCREMENT,\n `user_id` int(11) 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 ON UPDATE NO ACTION\n) ENGINE=InnoDB DEFAULT CHARSET=latin1 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(11)","nullable":false,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":"CURRENT_TIMESTAMP","extra_def":"on update CURRENT_TIMESTAMP","comment":""},{"name":"updated","type":"timestamp","nullable":false,"default":"0000-00-00 00:00:00","comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"def":"CREATE TABLE `user_options` (\n `user_id` int(11) NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n `updated` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',\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 ON UPDATE NO ACTION\n) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int(11)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":"","labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com","labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"timestamp","nullable":false,"default":"CURRENT_TIMESTAMP","extra_def":"on update CURRENT_TIMESTAMP","comment":""},{"name":"updated","type":"timestamp","nullable":false,"default":"0000-00-00 00:00:00","comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `users` (\n `id` int(11) 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 DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n `updated` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`)\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=latin1 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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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":[],"driver":{"name":"mysql","database_version":"5.6.51","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","comment":"","columns":[{"name":"id","type":"bigint(20)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint(20) NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=latin1"},{"name":"comment_stars","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"bigint(20)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint(20)","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int(11)","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":"CURRENT_TIMESTAMP","extra_def":"on update CURRENT_TIMESTAMP","comment":""},{"name":"updated","type":"timestamp","nullable":false,"default":"0000-00-00 00:00:00","comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"],"comment":""},{"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"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `comment_stars` (\n `id` bigint(20) NOT NULL AUTO_INCREMENT,\n `user_id` int(11) NOT NULL,\n `comment_post_id` bigint(20) NOT NULL,\n `comment_user_id` int(11) NOT NULL,\n `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n `updated` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',\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=latin1"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint(20)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint(20)","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int(11)","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `comments` (\n `id` bigint(20) NOT NULL AUTO_INCREMENT,\n `post_id` bigint(20) NOT NULL,\n `user_id` int(11) NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\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`) USING HASH,\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=latin1 COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"bigint(20)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint(20) NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=latin1"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint(20)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint(20)","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint(20)","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"bigint(20)","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `logs` (\n `id` bigint(20) NOT NULL AUTO_INCREMENT,\n `user_id` int(11) NOT NULL,\n `post_id` bigint(20) DEFAULT NULL,\n `comment_id` bigint(20) DEFAULT NULL,\n `comment_star_id` bigint(20) DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Auditログ'"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint(20)","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,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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(20)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"],"comment":""}],"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"def":"CREATE TABLE `posts` (\n `id` bigint(20) NOT NULL AUTO_INCREMENT,\n `user_id` int(11) 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 ON UPDATE NO ACTION\n) ENGINE=InnoDB DEFAULT CHARSET=latin1 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(11)","nullable":false,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":"CURRENT_TIMESTAMP","extra_def":"on update CURRENT_TIMESTAMP","comment":""},{"name":"updated","type":"timestamp","nullable":false,"default":"0000-00-00 00:00:00","comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"def":"CREATE TABLE `user_options` (\n `user_id` int(11) NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n `updated` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',\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 ON UPDATE NO ACTION\n) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int(11)","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":"","labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com","labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"timestamp","nullable":false,"default":"CURRENT_TIMESTAMP","extra_def":"on update CURRENT_TIMESTAMP","comment":""},{"name":"updated","type":"timestamp","nullable":false,"default":"0000-00-00 00:00:00","comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE `users` (\n `id` int(11) 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 DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n `updated` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`)\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=latin1 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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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":[],"driver":{"name":"mysql","database_version":"5.6.51","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 a982a2f5..a40fab54 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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"],"comment":""},{"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"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"default":null,"comment":"","extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"],"comment":""}],"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"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,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","referenced_table":null,"columns":null,"referenced_columns":null,"comment":""}],"triggers":[],"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.0.32","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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"],"comment":""},{"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"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"default":null,"comment":"","extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"],"comment":""}],"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"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,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","referenced_table":null,"columns":null,"referenced_columns":null,"comment":""}],"triggers":[],"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.2.0","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 1e5a9258..79bb53a5 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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"],"comment":""},{"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"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"default":null,"comment":"","extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"],"comment":""}],"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"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,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":"","labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com","labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","referenced_table":null,"columns":null,"referenced_columns":null,"comment":""}],"triggers":[],"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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.0.32","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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"],"comment":""},{"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"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"default":null,"comment":"","extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"],"comment":""}],"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"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,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":"","labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com","labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","referenced_table":null,"columns":null,"referenced_columns":null,"comment":""}],"triggers":[],"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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.2.0","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} diff --git a/sample/postgres/schema.json b/sample/postgres/schema.json index 7dbfd05a..56b8c51b 100644 --- a/sample/postgres/schema.json +++ b/sample/postgres/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample PostgreSQL database document.","tables":[{"name":"public.users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('users_id_seq'::regclass)","comment":""},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"users_pkey","def":"CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)","table":"public.users","columns":["id"],"comment":""},{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)","table":"public.users","columns":["username"],"comment":""},{"name":"users_email_key","def":"CREATE UNIQUE INDEX users_email_key ON public.users USING btree (email)","table":"public.users","columns":["email"],"comment":""}],"constraints":[{"name":"users_username_check","type":"CHECK","def":"CHECK ((char_length((username)::text) \u003e 4))","table":"public.users","referenced_table":"","columns":["username"],"referenced_columns":[],"comment":""},{"name":"users_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.users","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""},{"name":"users_username_key","type":"UNIQUE","def":"UNIQUE (username)","table":"public.users","referenced_table":"","columns":["username"],"referenced_columns":[],"comment":""},{"name":"users_email_key","type":"UNIQUE","def":"UNIQUE (email)","table":"public.users","referenced_table":"","columns":["email"],"referenced_columns":[],"comment":""}],"triggers":[{"name":"update_users_updated","def":"CREATE TRIGGER update_users_updated AFTER INSERT OR UPDATE ON public.users FOR EACH ROW EXECUTE FUNCTION update_updated()","comment":"Update updated when users insert or update"}],"def":""},{"name":"public.user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"show_email","type":"boolean","nullable":false,"default":"false","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"user_options_pkey","def":"CREATE UNIQUE INDEX user_options_pkey ON public.user_options USING btree (user_id)","table":"public.user_options","columns":["user_id"],"comment":"PRIMARY KEY"}],"constraints":[{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","table":"public.user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":"FK"},{"name":"user_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"public.user_options","referenced_table":"","columns":["user_id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"public.posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"default":"nextval('posts_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'::character varying","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"post_types","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"labels","type":"varchar(50)[]","nullable":true,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_id_pk","def":"CREATE UNIQUE INDEX posts_id_pk ON public.posts USING btree (id)","table":"public.posts","columns":["id"],"comment":""},{"name":"posts_user_id_title_key","def":"CREATE UNIQUE INDEX posts_user_id_title_key ON public.posts USING btree (user_id, title)","table":"public.posts","columns":["title","user_id"],"comment":""},{"name":"posts_user_id_idx","def":"CREATE INDEX posts_user_id_idx ON public.posts USING btree (user_id)","table":"public.posts","columns":["user_id"],"comment":"posts.user_id index"}],"constraints":[{"name":"update_posts_updated","type":"TRIGGER","def":"CREATE CONSTRAINT TRIGGER update_posts_updated AFTER INSERT OR UPDATE ON public.posts NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE FUNCTION update_updated()","table":"public.posts","referenced_table":"","columns":["tableoid","cmax","xmax","cmin","xmin","ctid","id","user_id","title","body","post_type","labels","created","updated"],"referenced_columns":[],"comment":""},{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL (user_id)","table":"public.posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":"posts -\u003e users"},{"name":"posts_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.posts","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""},{"name":"posts_user_id_title_key","type":"UNIQUE","def":"UNIQUE (user_id, title)","table":"public.posts","referenced_table":"","columns":["user_id","title"],"referenced_columns":[],"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE CONSTRAINT TRIGGER update_posts_updated AFTER INSERT OR UPDATE ON public.posts NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE FUNCTION update_updated()","comment":"Update updated when posts update"}],"def":""},{"name":"public.comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"default":"nextval('comments_id_seq'::regclass)","comment":""},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"default":null,"comment":"","extra_def":"GENERATED ALWAYS AS (post_id * '-1'::integer) STORED"},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"comments_id_pk","def":"CREATE UNIQUE INDEX comments_id_pk ON public.comments USING btree (id)","table":"public.comments","columns":["id"],"comment":""},{"name":"comments_post_id_user_id_key","def":"CREATE UNIQUE INDEX comments_post_id_user_id_key ON public.comments USING btree (post_id, user_id)","table":"public.comments","columns":["post_id","user_id"],"comment":""},{"name":"comments_post_id_user_id_idx","def":"CREATE INDEX comments_post_id_user_id_idx ON public.comments USING btree (post_id, user_id)","table":"public.comments","columns":["post_id","user_id"],"comment":""}],"constraints":[{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users(id)","table":"public.comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":""},{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts(id)","table":"public.comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"],"comment":""},{"name":"comments_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.comments","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""},{"name":"comments_post_id_user_id_key","type":"UNIQUE","def":"UNIQUE (post_id, user_id)","table":"public.comments","referenced_table":"","columns":["post_id","user_id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"public.comment_stars","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"comment_stars_user_id_comment_post_id_comment_user_id_key","def":"CREATE UNIQUE INDEX comment_stars_user_id_comment_post_id_comment_user_id_key ON public.comment_stars USING btree (user_id, comment_post_id, comment_user_id)","table":"public.comment_stars","columns":["comment_post_id","comment_user_id","user_id"],"comment":""}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","table":"public.comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"],"comment":""},{"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":"public.comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_post_id","comment_user_id","comment_user_id"],"referenced_columns":["post_id","user_id","post_id","user_id"],"comment":""},{"name":"comment_stars_user_id_comment_post_id_comment_user_id_key","type":"UNIQUE","def":"UNIQUE (user_id, comment_post_id, comment_user_id)","table":"public.comment_stars","referenced_table":"","columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"public.logs","type":"BASE TABLE","comment":"audit log table","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"uuid","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":""},{"name":"public.post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":null,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":true,"default":null,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":""},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"timestamp without time zone","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"def":"CREATE VIEW post_comments AS (\n SELECT c.id,\n p.title,\n u.username AS post_user,\n c.comment,\n u2.username AS comment_user,\n c.created,\n c.updated\n FROM (((posts p\n LEFT JOIN comments c ON ((p.id = c.post_id)))\n LEFT JOIN users u ON ((u.id = p.user_id)))\n LEFT JOIN users u2 ON ((u2.id = c.user_id)))\n)","referenced_tables":["public.posts","public.comments","public.users"]},{"name":"public.post_comment_stars","type":"MATERIALIZED VIEW","comment":"","columns":[{"name":"id","type":"uuid","nullable":true,"default":null,"comment":""},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":""},{"name":"comment_star_user","type":"varchar(50)","nullable":true,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":true,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":"CREATE MATERIALIZED VIEW post_comment_stars AS (\n SELECT cs.id,\n cu.username AS comment_user,\n csu.username AS comment_star_user,\n cs.created,\n cs.updated\n FROM (((comments c\n LEFT JOIN comment_stars cs ON (((cs.comment_post_id = c.id) AND (cs.comment_user_id = c.user_id))))\n LEFT JOIN users cu ON ((cu.id = cs.comment_user_id)))\n LEFT JOIN users csu ON ((csu.id = cs.user_id)))\n)","referenced_tables":["public.comments","public.comment_stars","public.users"]},{"name":"public.CamelizeTable","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"CamelizeTable_id_key","def":"CREATE UNIQUE INDEX \"CamelizeTable_id_key\" ON public.\"CamelizeTable\" USING btree (id)","table":"public.CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"CamelizeTable_id_key","type":"UNIQUE","def":"UNIQUE (id)","table":"public.CamelizeTable","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"public.hyphen-table","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"CamelizeTableId","type":"uuid","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"hyphen-table_hyphen-column_key","def":"CREATE UNIQUE INDEX \"hyphen-table_hyphen-column_key\" ON public.\"hyphen-table\" USING btree (\"hyphen-column\")","table":"public.hyphen-table","columns":["hyphen-column"],"comment":""}],"constraints":[{"name":"hyphen-table_CamelizeTableId_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (\"CamelizeTableId\") REFERENCES \"CamelizeTable\"(id) ON DELETE CASCADE","table":"public.hyphen-table","referenced_table":"CamelizeTable","columns":["CamelizeTableId"],"referenced_columns":["id"],"comment":""},{"name":"hyphen-table_hyphen-column_key","type":"UNIQUE","def":"UNIQUE (\"hyphen-column\")","table":"public.hyphen-table","referenced_table":"","columns":["hyphen-column"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"administrator.blogs","type":"BASE TABLE","comment":"admin blogs","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('administrator.blogs_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"name","type":"text","nullable":false,"default":null,"comment":""},{"name":"description","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON administrator.blogs USING btree (id)","table":"administrator.blogs","columns":["id"],"comment":""}],"constraints":[{"name":"blogs_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","table":"administrator.blogs","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":""},{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"administrator.blogs","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"backup.blogs","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blogs_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"dump","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON backup.blogs USING btree (id)","table":"backup.blogs","columns":["id"],"comment":""}],"constraints":[{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blogs","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"backup.blog_options","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blog_options_id_seq'::regclass)","comment":""},{"name":"blog_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"label","type":"text","nullable":true,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"blog_options_pkey","def":"CREATE UNIQUE INDEX blog_options_pkey ON backup.blog_options USING btree (id)","table":"backup.blog_options","columns":["id"],"comment":""}],"constraints":[{"name":"blog_options_blog_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (blog_id) REFERENCES blogs(id) ON DELETE CASCADE","table":"backup.blog_options","referenced_table":"blogs","columns":["blog_id"],"referenced_columns":["id"],"comment":""},{"name":"blog_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blog_options","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"time.bar","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"bar_pkey","def":"CREATE UNIQUE INDEX bar_pkey ON \"time\".bar USING btree (id)","table":"time.bar","columns":["id"],"comment":""}],"constraints":[{"name":"bar_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.bar","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"time.hyphenated-table","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"hyphenated-table_pkey","def":"CREATE UNIQUE INDEX \"hyphenated-table_pkey\" ON \"time\".\"hyphenated-table\" USING btree (id)","table":"time.hyphenated-table","columns":["id"],"comment":""}],"constraints":[{"name":"hyphenated-table_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.hyphenated-table","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"time.referencing","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"bar_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"ht_id","type":"integer","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"referencing_pkey","def":"CREATE UNIQUE INDEX referencing_pkey ON \"time\".referencing USING btree (id)","table":"time.referencing","columns":["id"],"comment":""}],"constraints":[{"name":"referencing_bar_id","type":"FOREIGN KEY","def":"FOREIGN KEY (bar_id) REFERENCES \"time\".bar(id)","table":"time.referencing","referenced_table":"bar","columns":["bar_id"],"referenced_columns":["id"],"comment":""},{"name":"referencing_ht_id","type":"FOREIGN KEY","def":"FOREIGN KEY (ht_id) REFERENCES \"time\".\"hyphenated-table\"(id)","table":"time.referencing","referenced_table":"hyphenated-table","columns":["ht_id"],"referenced_columns":["id"],"comment":""},{"name":"referencing_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.referencing","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""}],"relations":[{"table":"public.user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","virtual":false},{"table":"public.posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL (user_id)","virtual":false},{"table":"public.comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users(id)","virtual":false},{"table":"public.comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"public.posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts(id)","virtual":false},{"table":"public.comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","virtual":false},{"table":"public.comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"public.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)","virtual":false},{"table":"public.hyphen-table","columns":["CamelizeTableId"],"cardinality":"Zero or more","parent_table":"public.CamelizeTable","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (\"CamelizeTableId\") REFERENCES \"CamelizeTable\"(id) ON DELETE CASCADE","virtual":false},{"table":"administrator.blogs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","virtual":false},{"table":"backup.blog_options","columns":["blog_id"],"cardinality":"Zero or more","parent_table":"backup.blogs","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (blog_id) REFERENCES blogs(id) ON DELETE CASCADE","virtual":false},{"table":"time.referencing","columns":["bar_id"],"cardinality":"Zero or more","parent_table":"time.bar","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (bar_id) REFERENCES \"time\".bar(id)","virtual":false},{"table":"time.referencing","columns":["ht_id"],"cardinality":"Zero or more","parent_table":"time.hyphenated-table","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (ht_id) REFERENCES \"time\".\"hyphenated-table\"(id)","virtual":false},{"table":"public.logs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"logs-\u003eusers","virtual":true},{"table":"public.logs","columns":["post_id"],"cardinality":"Zero or more","parent_table":"public.posts","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"public.logs","columns":["comment_id"],"cardinality":"Zero or more","parent_table":"public.comments","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"public.logs","columns":["comment_star_id"],"cardinality":"Zero or more","parent_table":"public.comment_stars","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true}],"functions":[{"name":"public.uuid_nil","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_ns_dns","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_ns_url","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_ns_oid","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_ns_x500","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_generate_v1","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_generate_v1mc","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_generate_v3","return_type":"uuid","arguments":"namespace uuid, name text","type":"FUNCTION"},{"name":"public.uuid_generate_v4","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_generate_v5","return_type":"uuid","arguments":"namespace uuid, name text","type":"FUNCTION"},{"name":"public.update_updated","return_type":"trigger","arguments":"","type":"FUNCTION"},{"name":"public.reset_comment","return_type":"void","arguments":"IN comment_id integer","type":"PROCEDURE"}],"driver":{"name":"postgres","database_version":"PostgreSQL 15.1 (Debian 15.1-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit","meta":{"current_schema":"public","search_paths":["\"$user\"","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}}} +{"name":"testdb","desc":"Sample PostgreSQL database document.","tables":[{"name":"public.users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('users_id_seq'::regclass)","comment":""},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"users_pkey","def":"CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)","table":"public.users","columns":["id"],"comment":""},{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)","table":"public.users","columns":["username"],"comment":""},{"name":"users_email_key","def":"CREATE UNIQUE INDEX users_email_key ON public.users USING btree (email)","table":"public.users","columns":["email"],"comment":""}],"constraints":[{"name":"users_username_check","type":"CHECK","def":"CHECK ((char_length((username)::text) \u003e 4))","table":"public.users","referenced_table":"","columns":["username"],"referenced_columns":[],"comment":""},{"name":"users_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.users","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""},{"name":"users_username_key","type":"UNIQUE","def":"UNIQUE (username)","table":"public.users","referenced_table":"","columns":["username"],"referenced_columns":[],"comment":""},{"name":"users_email_key","type":"UNIQUE","def":"UNIQUE (email)","table":"public.users","referenced_table":"","columns":["email"],"referenced_columns":[],"comment":""}],"triggers":[{"name":"update_users_updated","def":"CREATE TRIGGER update_users_updated AFTER INSERT OR UPDATE ON public.users FOR EACH ROW EXECUTE FUNCTION update_updated()","comment":"Update updated when users insert or update"}],"def":""},{"name":"public.user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"show_email","type":"boolean","nullable":false,"default":"false","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"user_options_pkey","def":"CREATE UNIQUE INDEX user_options_pkey ON public.user_options USING btree (user_id)","table":"public.user_options","columns":["user_id"],"comment":"PRIMARY KEY"}],"constraints":[{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","table":"public.user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":"FK"},{"name":"user_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"public.user_options","referenced_table":"","columns":["user_id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"public.posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"default":"nextval('posts_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'::character varying","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"post_types","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"labels","type":"varchar(50)[]","nullable":true,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_id_pk","def":"CREATE UNIQUE INDEX posts_id_pk ON public.posts USING btree (id)","table":"public.posts","columns":["id"],"comment":""},{"name":"posts_user_id_title_key","def":"CREATE UNIQUE INDEX posts_user_id_title_key ON public.posts USING btree (user_id, title)","table":"public.posts","columns":["title","user_id"],"comment":""},{"name":"posts_user_id_idx","def":"CREATE INDEX posts_user_id_idx ON public.posts USING btree (user_id)","table":"public.posts","columns":["user_id"],"comment":"posts.user_id index"}],"constraints":[{"name":"update_posts_updated","type":"TRIGGER","def":"CREATE CONSTRAINT TRIGGER update_posts_updated AFTER INSERT OR UPDATE ON public.posts NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE FUNCTION update_updated()","table":"public.posts","referenced_table":"","columns":["tableoid","cmax","xmax","cmin","xmin","ctid","id","user_id","title","body","post_type","labels","created","updated"],"referenced_columns":[],"comment":""},{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL (user_id)","table":"public.posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":"posts -\u003e users"},{"name":"posts_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.posts","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""},{"name":"posts_user_id_title_key","type":"UNIQUE","def":"UNIQUE (user_id, title)","table":"public.posts","referenced_table":"","columns":["user_id","title"],"referenced_columns":[],"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE CONSTRAINT TRIGGER update_posts_updated AFTER INSERT OR UPDATE ON public.posts NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE FUNCTION update_updated()","comment":"Update updated when posts update"}],"def":""},{"name":"public.comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"default":"nextval('comments_id_seq'::regclass)","comment":""},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"default":null,"comment":"","extra_def":"GENERATED ALWAYS AS (post_id * '-1'::integer) STORED"},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"comments_id_pk","def":"CREATE UNIQUE INDEX comments_id_pk ON public.comments USING btree (id)","table":"public.comments","columns":["id"],"comment":""},{"name":"comments_post_id_user_id_key","def":"CREATE UNIQUE INDEX comments_post_id_user_id_key ON public.comments USING btree (post_id, user_id)","table":"public.comments","columns":["post_id","user_id"],"comment":""},{"name":"comments_post_id_user_id_idx","def":"CREATE INDEX comments_post_id_user_id_idx ON public.comments USING btree (post_id, user_id)","table":"public.comments","columns":["post_id","user_id"],"comment":""}],"constraints":[{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users(id)","table":"public.comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":""},{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts(id)","table":"public.comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"],"comment":""},{"name":"comments_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.comments","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""},{"name":"comments_post_id_user_id_key","type":"UNIQUE","def":"UNIQUE (post_id, user_id)","table":"public.comments","referenced_table":"","columns":["post_id","user_id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"public.comment_stars","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"comment_stars_user_id_comment_post_id_comment_user_id_key","def":"CREATE UNIQUE INDEX comment_stars_user_id_comment_post_id_comment_user_id_key ON public.comment_stars USING btree (user_id, comment_post_id, comment_user_id)","table":"public.comment_stars","columns":["comment_post_id","comment_user_id","user_id"],"comment":""}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","table":"public.comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"],"comment":""},{"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":"public.comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_post_id","comment_user_id","comment_user_id"],"referenced_columns":["post_id","user_id","post_id","user_id"],"comment":""},{"name":"comment_stars_user_id_comment_post_id_comment_user_id_key","type":"UNIQUE","def":"UNIQUE (user_id, comment_post_id, comment_user_id)","table":"public.comment_stars","referenced_table":"","columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"public.logs","type":"BASE TABLE","comment":"audit log table","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"uuid","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":""},{"name":"public.post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":null,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":true,"default":null,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":""},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"timestamp without time zone","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"def":"CREATE VIEW post_comments AS (\n SELECT c.id,\n p.title,\n u.username AS post_user,\n c.comment,\n u2.username AS comment_user,\n c.created,\n c.updated\n FROM (((posts p\n LEFT JOIN comments c ON ((p.id = c.post_id)))\n LEFT JOIN users u ON ((u.id = p.user_id)))\n LEFT JOIN users u2 ON ((u2.id = c.user_id)))\n)","referenced_tables":["public.posts","public.comments","public.users"]},{"name":"public.post_comment_stars","type":"MATERIALIZED VIEW","comment":"","columns":[{"name":"id","type":"uuid","nullable":true,"default":null,"comment":""},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":""},{"name":"comment_star_user","type":"varchar(50)","nullable":true,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":true,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":"CREATE MATERIALIZED VIEW post_comment_stars AS (\n SELECT cs.id,\n cu.username AS comment_user,\n csu.username AS comment_star_user,\n cs.created,\n cs.updated\n FROM (((comments c\n LEFT JOIN comment_stars cs ON (((cs.comment_post_id = c.id) AND (cs.comment_user_id = c.user_id))))\n LEFT JOIN users cu ON ((cu.id = cs.comment_user_id)))\n LEFT JOIN users csu ON ((csu.id = cs.user_id)))\n)","referenced_tables":["public.comments","public.comment_stars","public.users"]},{"name":"public.CamelizeTable","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"CamelizeTable_id_key","def":"CREATE UNIQUE INDEX \"CamelizeTable_id_key\" ON public.\"CamelizeTable\" USING btree (id)","table":"public.CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"CamelizeTable_id_key","type":"UNIQUE","def":"UNIQUE (id)","table":"public.CamelizeTable","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"public.hyphen-table","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"CamelizeTableId","type":"uuid","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"hyphen-table_hyphen-column_key","def":"CREATE UNIQUE INDEX \"hyphen-table_hyphen-column_key\" ON public.\"hyphen-table\" USING btree (\"hyphen-column\")","table":"public.hyphen-table","columns":["hyphen-column"],"comment":""}],"constraints":[{"name":"hyphen-table_CamelizeTableId_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (\"CamelizeTableId\") REFERENCES \"CamelizeTable\"(id) ON DELETE CASCADE","table":"public.hyphen-table","referenced_table":"CamelizeTable","columns":["CamelizeTableId"],"referenced_columns":["id"],"comment":""},{"name":"hyphen-table_hyphen-column_key","type":"UNIQUE","def":"UNIQUE (\"hyphen-column\")","table":"public.hyphen-table","referenced_table":"","columns":["hyphen-column"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"administrator.blogs","type":"BASE TABLE","comment":"admin blogs","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('administrator.blogs_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"name","type":"text","nullable":false,"default":null,"comment":""},{"name":"description","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON administrator.blogs USING btree (id)","table":"administrator.blogs","columns":["id"],"comment":""}],"constraints":[{"name":"blogs_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","table":"administrator.blogs","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":""},{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"administrator.blogs","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"backup.blogs","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blogs_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"dump","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON backup.blogs USING btree (id)","table":"backup.blogs","columns":["id"],"comment":""}],"constraints":[{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blogs","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"backup.blog_options","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blog_options_id_seq'::regclass)","comment":""},{"name":"blog_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"label","type":"text","nullable":true,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"blog_options_pkey","def":"CREATE UNIQUE INDEX blog_options_pkey ON backup.blog_options USING btree (id)","table":"backup.blog_options","columns":["id"],"comment":""}],"constraints":[{"name":"blog_options_blog_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (blog_id) REFERENCES blogs(id) ON DELETE CASCADE","table":"backup.blog_options","referenced_table":"blogs","columns":["blog_id"],"referenced_columns":["id"],"comment":""},{"name":"blog_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blog_options","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"time.bar","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"bar_pkey","def":"CREATE UNIQUE INDEX bar_pkey ON \"time\".bar USING btree (id)","table":"time.bar","columns":["id"],"comment":""}],"constraints":[{"name":"bar_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.bar","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"time.hyphenated-table","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"hyphenated-table_pkey","def":"CREATE UNIQUE INDEX \"hyphenated-table_pkey\" ON \"time\".\"hyphenated-table\" USING btree (id)","table":"time.hyphenated-table","columns":["id"],"comment":""}],"constraints":[{"name":"hyphenated-table_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.hyphenated-table","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"time.referencing","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"bar_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"ht_id","type":"integer","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"referencing_pkey","def":"CREATE UNIQUE INDEX referencing_pkey ON \"time\".referencing USING btree (id)","table":"time.referencing","columns":["id"],"comment":""}],"constraints":[{"name":"referencing_bar_id","type":"FOREIGN KEY","def":"FOREIGN KEY (bar_id) REFERENCES \"time\".bar(id)","table":"time.referencing","referenced_table":"bar","columns":["bar_id"],"referenced_columns":["id"],"comment":""},{"name":"referencing_ht_id","type":"FOREIGN KEY","def":"FOREIGN KEY (ht_id) REFERENCES \"time\".\"hyphenated-table\"(id)","table":"time.referencing","referenced_table":"hyphenated-table","columns":["ht_id"],"referenced_columns":["id"],"comment":""},{"name":"referencing_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.referencing","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""}],"relations":[{"table":"public.user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","virtual":false},{"table":"public.posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL (user_id)","virtual":false},{"table":"public.comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users(id)","virtual":false},{"table":"public.comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"public.posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts(id)","virtual":false},{"table":"public.comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","virtual":false},{"table":"public.comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"public.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)","virtual":false},{"table":"public.hyphen-table","columns":["CamelizeTableId"],"cardinality":"Zero or more","parent_table":"public.CamelizeTable","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (\"CamelizeTableId\") REFERENCES \"CamelizeTable\"(id) ON DELETE CASCADE","virtual":false},{"table":"administrator.blogs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","virtual":false},{"table":"backup.blog_options","columns":["blog_id"],"cardinality":"Zero or more","parent_table":"backup.blogs","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (blog_id) REFERENCES blogs(id) ON DELETE CASCADE","virtual":false},{"table":"time.referencing","columns":["bar_id"],"cardinality":"Zero or more","parent_table":"time.bar","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (bar_id) REFERENCES \"time\".bar(id)","virtual":false},{"table":"time.referencing","columns":["ht_id"],"cardinality":"Zero or more","parent_table":"time.hyphenated-table","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (ht_id) REFERENCES \"time\".\"hyphenated-table\"(id)","virtual":false},{"table":"public.logs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"logs-\u003eusers","virtual":true},{"table":"public.logs","columns":["post_id"],"cardinality":"Zero or more","parent_table":"public.posts","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"public.logs","columns":["comment_id"],"cardinality":"Zero or more","parent_table":"public.comments","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"public.logs","columns":["comment_star_id"],"cardinality":"Zero or more","parent_table":"public.comment_stars","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true}],"functions":[{"name":"public.uuid_nil","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_ns_dns","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_ns_url","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_ns_oid","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_ns_x500","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_generate_v1","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_generate_v1mc","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_generate_v3","return_type":"uuid","arguments":"namespace uuid, name text","type":"FUNCTION"},{"name":"public.uuid_generate_v4","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_generate_v5","return_type":"uuid","arguments":"namespace uuid, name text","type":"FUNCTION"},{"name":"public.update_updated","return_type":"trigger","arguments":"","type":"FUNCTION"},{"name":"public.reset_comment","return_type":"void","arguments":"IN comment_id integer","type":"PROCEDURE"}],"driver":{"name":"postgres","database_version":"PostgreSQL 15.4 (Debian 15.4-2.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit","meta":{"current_schema":"public","search_paths":["\"$user\"","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}}} diff --git a/sample/postgres95/schema.json b/sample/postgres95/schema.json index 68764a3c..a4d43fa6 100644 --- a/sample/postgres95/schema.json +++ b/sample/postgres95/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample PostgreSQL database document.","tables":[{"name":"public.users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('users_id_seq'::regclass)","comment":""},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"users_pkey","def":"CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)","table":"public.users","columns":["id"],"comment":""},{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)","table":"public.users","columns":["username"],"comment":""},{"name":"users_email_key","def":"CREATE UNIQUE INDEX users_email_key ON public.users USING btree (email)","table":"public.users","columns":["email"],"comment":""}],"constraints":[{"name":"users_username_check","type":"CHECK","def":"CHECK ((char_length((username)::text) \u003e 4))","table":"public.users","referenced_table":"","columns":["username"],"referenced_columns":[],"comment":""},{"name":"users_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.users","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""},{"name":"users_username_key","type":"UNIQUE","def":"UNIQUE (username)","table":"public.users","referenced_table":"","columns":["username"],"referenced_columns":[],"comment":""},{"name":"users_email_key","type":"UNIQUE","def":"UNIQUE (email)","table":"public.users","referenced_table":"","columns":["email"],"referenced_columns":[],"comment":""}],"triggers":[{"name":"update_users_updated","def":"CREATE TRIGGER update_users_updated AFTER INSERT OR UPDATE ON public.users FOR EACH ROW EXECUTE PROCEDURE update_updated()","comment":"Update updated when users insert or update"}],"def":""},{"name":"public.user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"show_email","type":"boolean","nullable":false,"default":"false","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"user_options_pkey","def":"CREATE UNIQUE INDEX user_options_pkey ON public.user_options USING btree (user_id)","table":"public.user_options","columns":["user_id"],"comment":"PRIMARY KEY"}],"constraints":[{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","table":"public.user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":"FK"},{"name":"user_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"public.user_options","referenced_table":"","columns":["user_id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"public.posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"default":"nextval('posts_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'::character varying","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"post_types","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"labels","type":"varchar(50)[]","nullable":true,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_id_pk","def":"CREATE UNIQUE INDEX posts_id_pk ON public.posts USING btree (id)","table":"public.posts","columns":["id"],"comment":""},{"name":"posts_user_id_title_key","def":"CREATE UNIQUE INDEX posts_user_id_title_key ON public.posts USING btree (user_id, title)","table":"public.posts","columns":["title","user_id"],"comment":""},{"name":"posts_user_id_idx","def":"CREATE INDEX posts_user_id_idx ON public.posts USING btree (user_id)","table":"public.posts","columns":["user_id"],"comment":"posts.user_id index"}],"constraints":[{"name":"update_posts_updated","type":"TRIGGER","def":"CREATE CONSTRAINT TRIGGER update_posts_updated AFTER INSERT OR UPDATE ON public.posts NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE update_updated()","table":"public.posts","referenced_table":"","columns":["updated","body","post_type","labels","created","tableoid","cmax","xmax","cmin","xmin","ctid","id","user_id","title"],"referenced_columns":[],"comment":""},{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","table":"public.posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":"posts -\u003e users"},{"name":"posts_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.posts","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""},{"name":"posts_user_id_title_key","type":"UNIQUE","def":"UNIQUE (user_id, title)","table":"public.posts","referenced_table":"","columns":["user_id","title"],"referenced_columns":[],"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE CONSTRAINT TRIGGER update_posts_updated AFTER INSERT OR UPDATE ON public.posts NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE update_updated()","comment":"Update updated when posts update"}],"def":""},{"name":"public.comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"default":"nextval('comments_id_seq'::regclass)","comment":""},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"comments_id_pk","def":"CREATE UNIQUE INDEX comments_id_pk ON public.comments USING btree (id)","table":"public.comments","columns":["id"],"comment":""},{"name":"comments_post_id_user_id_key","def":"CREATE UNIQUE INDEX comments_post_id_user_id_key ON public.comments USING btree (post_id, user_id)","table":"public.comments","columns":["post_id","user_id"],"comment":""},{"name":"comments_post_id_user_id_idx","def":"CREATE INDEX comments_post_id_user_id_idx ON public.comments USING btree (post_id, user_id)","table":"public.comments","columns":["post_id","user_id"],"comment":""}],"constraints":[{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users(id)","table":"public.comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":""},{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts(id)","table":"public.comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"],"comment":""},{"name":"comments_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.comments","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""},{"name":"comments_post_id_user_id_key","type":"UNIQUE","def":"UNIQUE (post_id, user_id)","table":"public.comments","referenced_table":"","columns":["post_id","user_id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"public.comment_stars","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"comment_stars_user_id_comment_post_id_comment_user_id_key","def":"CREATE UNIQUE INDEX comment_stars_user_id_comment_post_id_comment_user_id_key ON public.comment_stars USING btree (user_id, comment_post_id, comment_user_id)","table":"public.comment_stars","columns":["comment_post_id","comment_user_id","user_id"],"comment":""}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","table":"public.comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"],"comment":""},{"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":"public.comment_stars","referenced_table":"comments","columns":["comment_user_id","comment_post_id","comment_post_id","comment_user_id"],"referenced_columns":["post_id","post_id","user_id","user_id"],"comment":""},{"name":"comment_stars_user_id_comment_post_id_comment_user_id_key","type":"UNIQUE","def":"UNIQUE (user_id, comment_post_id, comment_user_id)","table":"public.comment_stars","referenced_table":"","columns":["comment_user_id","comment_post_id","user_id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"public.logs","type":"BASE TABLE","comment":"audit log table","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"uuid","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":""},{"name":"public.post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":null,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":true,"default":null,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":""},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"timestamp without time zone","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"def":"CREATE VIEW post_comments AS (\n SELECT c.id,\n p.title,\n u.username AS post_user,\n c.comment,\n u2.username AS comment_user,\n c.created,\n c.updated\n FROM (((posts p\n LEFT JOIN comments c ON ((p.id = c.post_id)))\n LEFT JOIN users u ON ((u.id = p.user_id)))\n LEFT JOIN users u2 ON ((u2.id = c.user_id)))\n)","referenced_tables":["public.posts","public.comments","public.users"]},{"name":"public.post_comment_stars","type":"MATERIALIZED VIEW","comment":"","columns":[{"name":"id","type":"uuid","nullable":true,"default":null,"comment":""},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":""},{"name":"comment_star_user","type":"varchar(50)","nullable":true,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":true,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":"CREATE MATERIALIZED VIEW post_comment_stars AS (\n SELECT cs.id,\n cu.username AS comment_user,\n csu.username AS comment_star_user,\n cs.created,\n cs.updated\n FROM (((comments c\n LEFT JOIN comment_stars cs ON (((cs.comment_post_id = c.id) AND (cs.comment_user_id = c.user_id))))\n LEFT JOIN users cu ON ((cu.id = cs.comment_user_id)))\n LEFT JOIN users csu ON ((csu.id = cs.user_id)))\n)","referenced_tables":["public.comments","public.comment_stars","public.users"]},{"name":"public.CamelizeTable","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"CamelizeTable_id_key","def":"CREATE UNIQUE INDEX \"CamelizeTable_id_key\" ON public.\"CamelizeTable\" USING btree (id)","table":"public.CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"CamelizeTable_id_key","type":"UNIQUE","def":"UNIQUE (id)","table":"public.CamelizeTable","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"public.hyphen-table","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"CamelizeTableId","type":"uuid","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"hyphen-table_hyphen-column_key","def":"CREATE UNIQUE INDEX \"hyphen-table_hyphen-column_key\" ON public.\"hyphen-table\" USING btree (\"hyphen-column\")","table":"public.hyphen-table","columns":["hyphen-column"],"comment":""}],"constraints":[{"name":"hyphen-table_CamelizeTableId_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (\"CamelizeTableId\") REFERENCES \"CamelizeTable\"(id) ON DELETE CASCADE","table":"public.hyphen-table","referenced_table":"CamelizeTable","columns":["CamelizeTableId"],"referenced_columns":["id"],"comment":""},{"name":"hyphen-table_hyphen-column_key","type":"UNIQUE","def":"UNIQUE (\"hyphen-column\")","table":"public.hyphen-table","referenced_table":"","columns":["hyphen-column"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"administrator.blogs","type":"BASE TABLE","comment":"admin blogs","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('administrator.blogs_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"name","type":"text","nullable":false,"default":null,"comment":""},{"name":"description","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON administrator.blogs USING btree (id)","table":"administrator.blogs","columns":["id"],"comment":""}],"constraints":[{"name":"blogs_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","table":"administrator.blogs","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":""},{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"administrator.blogs","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"backup.blogs","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blogs_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"dump","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON backup.blogs USING btree (id)","table":"backup.blogs","columns":["id"],"comment":""}],"constraints":[{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blogs","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"backup.blog_options","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blog_options_id_seq'::regclass)","comment":""},{"name":"blog_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"label","type":"text","nullable":true,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"blog_options_pkey","def":"CREATE UNIQUE INDEX blog_options_pkey ON backup.blog_options USING btree (id)","table":"backup.blog_options","columns":["id"],"comment":""}],"constraints":[{"name":"blog_options_blog_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (blog_id) REFERENCES blogs(id) ON DELETE CASCADE","table":"backup.blog_options","referenced_table":"blogs","columns":["blog_id"],"referenced_columns":["id"],"comment":""},{"name":"blog_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blog_options","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"time.bar","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"bar_pkey","def":"CREATE UNIQUE INDEX bar_pkey ON \"time\".bar USING btree (id)","table":"time.bar","columns":["id"],"comment":""}],"constraints":[{"name":"bar_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.bar","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"time.hyphenated-table","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"hyphenated-table_pkey","def":"CREATE UNIQUE INDEX \"hyphenated-table_pkey\" ON \"time\".\"hyphenated-table\" USING btree (id)","table":"time.hyphenated-table","columns":["id"],"comment":""}],"constraints":[{"name":"hyphenated-table_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.hyphenated-table","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"time.referencing","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"bar_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"ht_id","type":"integer","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"referencing_pkey","def":"CREATE UNIQUE INDEX referencing_pkey ON \"time\".referencing USING btree (id)","table":"time.referencing","columns":["id"],"comment":""}],"constraints":[{"name":"referencing_bar_id","type":"FOREIGN KEY","def":"FOREIGN KEY (bar_id) REFERENCES \"time\".bar(id)","table":"time.referencing","referenced_table":"bar","columns":["bar_id"],"referenced_columns":["id"],"comment":""},{"name":"referencing_ht_id","type":"FOREIGN KEY","def":"FOREIGN KEY (ht_id) REFERENCES \"time\".\"hyphenated-table\"(id)","table":"time.referencing","referenced_table":"hyphenated-table","columns":["ht_id"],"referenced_columns":["id"],"comment":""},{"name":"referencing_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.referencing","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""}],"relations":[{"table":"public.user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","virtual":false},{"table":"public.posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","virtual":false},{"table":"public.comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users(id)","virtual":false},{"table":"public.comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"public.posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts(id)","virtual":false},{"table":"public.comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","virtual":false},{"table":"public.comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"public.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)","virtual":false},{"table":"public.hyphen-table","columns":["CamelizeTableId"],"cardinality":"Zero or more","parent_table":"public.CamelizeTable","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (\"CamelizeTableId\") REFERENCES \"CamelizeTable\"(id) ON DELETE CASCADE","virtual":false},{"table":"administrator.blogs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","virtual":false},{"table":"backup.blog_options","columns":["blog_id"],"cardinality":"Zero or more","parent_table":"backup.blogs","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (blog_id) REFERENCES blogs(id) ON DELETE CASCADE","virtual":false},{"table":"time.referencing","columns":["bar_id"],"cardinality":"Zero or more","parent_table":"time.bar","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (bar_id) REFERENCES \"time\".bar(id)","virtual":false},{"table":"time.referencing","columns":["ht_id"],"cardinality":"Zero or more","parent_table":"time.hyphenated-table","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (ht_id) REFERENCES \"time\".\"hyphenated-table\"(id)","virtual":false},{"table":"public.logs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"logs-\u003eusers","virtual":true},{"table":"public.logs","columns":["post_id"],"cardinality":"Zero or more","parent_table":"public.posts","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"public.logs","columns":["comment_id"],"cardinality":"Zero or more","parent_table":"public.comments","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"public.logs","columns":["comment_star_id"],"cardinality":"Zero or more","parent_table":"public.comment_stars","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true}],"functions":[{"name":"public.uuid_nil","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_ns_dns","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_ns_url","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_ns_oid","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_ns_x500","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_generate_v1","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_generate_v1mc","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_generate_v3","return_type":"uuid","arguments":"namespace uuid, name text","type":"FUNCTION"},{"name":"public.uuid_generate_v4","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_generate_v5","return_type":"uuid","arguments":"namespace uuid, name text","type":"FUNCTION"},{"name":"public.update_updated","return_type":"trigger","arguments":"","type":"FUNCTION"}],"driver":{"name":"postgres","database_version":"PostgreSQL 9.5.25 on x86_64-pc-linux-gnu (Debian 9.5.25-1.pgdg90+1), compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit","meta":{"current_schema":"public","search_paths":["\"$user\"","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}}} +{"name":"testdb","desc":"Sample PostgreSQL database document.","tables":[{"name":"public.users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('users_id_seq'::regclass)","comment":""},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"users_pkey","def":"CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)","table":"public.users","columns":["id"],"comment":""},{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)","table":"public.users","columns":["username"],"comment":""},{"name":"users_email_key","def":"CREATE UNIQUE INDEX users_email_key ON public.users USING btree (email)","table":"public.users","columns":["email"],"comment":""}],"constraints":[{"name":"users_username_check","type":"CHECK","def":"CHECK ((char_length((username)::text) \u003e 4))","table":"public.users","referenced_table":"","columns":["username"],"referenced_columns":[],"comment":""},{"name":"users_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.users","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""},{"name":"users_username_key","type":"UNIQUE","def":"UNIQUE (username)","table":"public.users","referenced_table":"","columns":["username"],"referenced_columns":[],"comment":""},{"name":"users_email_key","type":"UNIQUE","def":"UNIQUE (email)","table":"public.users","referenced_table":"","columns":["email"],"referenced_columns":[],"comment":""}],"triggers":[{"name":"update_users_updated","def":"CREATE TRIGGER update_users_updated AFTER INSERT OR UPDATE ON public.users FOR EACH ROW EXECUTE PROCEDURE update_updated()","comment":"Update updated when users insert or update"}],"def":""},{"name":"public.user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"show_email","type":"boolean","nullable":false,"default":"false","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"user_options_pkey","def":"CREATE UNIQUE INDEX user_options_pkey ON public.user_options USING btree (user_id)","table":"public.user_options","columns":["user_id"],"comment":"PRIMARY KEY"}],"constraints":[{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","table":"public.user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":"FK"},{"name":"user_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"public.user_options","referenced_table":"","columns":["user_id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"public.posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"default":"nextval('posts_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'::character varying","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"post_types","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"labels","type":"varchar(50)[]","nullable":true,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_id_pk","def":"CREATE UNIQUE INDEX posts_id_pk ON public.posts USING btree (id)","table":"public.posts","columns":["id"],"comment":""},{"name":"posts_user_id_title_key","def":"CREATE UNIQUE INDEX posts_user_id_title_key ON public.posts USING btree (user_id, title)","table":"public.posts","columns":["title","user_id"],"comment":""},{"name":"posts_user_id_idx","def":"CREATE INDEX posts_user_id_idx ON public.posts USING btree (user_id)","table":"public.posts","columns":["user_id"],"comment":"posts.user_id index"}],"constraints":[{"name":"update_posts_updated","type":"TRIGGER","def":"CREATE CONSTRAINT TRIGGER update_posts_updated AFTER INSERT OR UPDATE ON public.posts NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE update_updated()","table":"public.posts","referenced_table":"","columns":["updated","body","post_type","labels","created","tableoid","cmax","xmax","cmin","xmin","ctid","id","user_id","title"],"referenced_columns":[],"comment":""},{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","table":"public.posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":"posts -\u003e users"},{"name":"posts_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.posts","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""},{"name":"posts_user_id_title_key","type":"UNIQUE","def":"UNIQUE (user_id, title)","table":"public.posts","referenced_table":"","columns":["user_id","title"],"referenced_columns":[],"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE CONSTRAINT TRIGGER update_posts_updated AFTER INSERT OR UPDATE ON public.posts NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE update_updated()","comment":"Update updated when posts update"}],"def":""},{"name":"public.comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"default":"nextval('comments_id_seq'::regclass)","comment":""},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"comments_id_pk","def":"CREATE UNIQUE INDEX comments_id_pk ON public.comments USING btree (id)","table":"public.comments","columns":["id"],"comment":""},{"name":"comments_post_id_user_id_key","def":"CREATE UNIQUE INDEX comments_post_id_user_id_key ON public.comments USING btree (post_id, user_id)","table":"public.comments","columns":["post_id","user_id"],"comment":""},{"name":"comments_post_id_user_id_idx","def":"CREATE INDEX comments_post_id_user_id_idx ON public.comments USING btree (post_id, user_id)","table":"public.comments","columns":["post_id","user_id"],"comment":""}],"constraints":[{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users(id)","table":"public.comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":""},{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts(id)","table":"public.comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"],"comment":""},{"name":"comments_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.comments","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""},{"name":"comments_post_id_user_id_key","type":"UNIQUE","def":"UNIQUE (post_id, user_id)","table":"public.comments","referenced_table":"","columns":["post_id","user_id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"public.comment_stars","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"comment_stars_user_id_comment_post_id_comment_user_id_key","def":"CREATE UNIQUE INDEX comment_stars_user_id_comment_post_id_comment_user_id_key ON public.comment_stars USING btree (user_id, comment_post_id, comment_user_id)","table":"public.comment_stars","columns":["comment_post_id","comment_user_id","user_id"],"comment":""}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","table":"public.comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"],"comment":""},{"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":"public.comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_post_id","comment_user_id","comment_user_id"],"referenced_columns":["user_id","post_id","post_id","user_id"],"comment":""},{"name":"comment_stars_user_id_comment_post_id_comment_user_id_key","type":"UNIQUE","def":"UNIQUE (user_id, comment_post_id, comment_user_id)","table":"public.comment_stars","referenced_table":"","columns":["comment_user_id","comment_post_id","user_id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"public.logs","type":"BASE TABLE","comment":"audit log table","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"uuid","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":""},{"name":"public.post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":null,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":true,"default":null,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":""},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"timestamp without time zone","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"def":"CREATE VIEW post_comments AS (\n SELECT c.id,\n p.title,\n u.username AS post_user,\n c.comment,\n u2.username AS comment_user,\n c.created,\n c.updated\n FROM (((posts p\n LEFT JOIN comments c ON ((p.id = c.post_id)))\n LEFT JOIN users u ON ((u.id = p.user_id)))\n LEFT JOIN users u2 ON ((u2.id = c.user_id)))\n)","referenced_tables":["public.posts","public.comments","public.users"]},{"name":"public.post_comment_stars","type":"MATERIALIZED VIEW","comment":"","columns":[{"name":"id","type":"uuid","nullable":true,"default":null,"comment":""},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":""},{"name":"comment_star_user","type":"varchar(50)","nullable":true,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":true,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":"CREATE MATERIALIZED VIEW post_comment_stars AS (\n SELECT cs.id,\n cu.username AS comment_user,\n csu.username AS comment_star_user,\n cs.created,\n cs.updated\n FROM (((comments c\n LEFT JOIN comment_stars cs ON (((cs.comment_post_id = c.id) AND (cs.comment_user_id = c.user_id))))\n LEFT JOIN users cu ON ((cu.id = cs.comment_user_id)))\n LEFT JOIN users csu ON ((csu.id = cs.user_id)))\n)","referenced_tables":["public.comments","public.comment_stars","public.users"]},{"name":"public.CamelizeTable","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"CamelizeTable_id_key","def":"CREATE UNIQUE INDEX \"CamelizeTable_id_key\" ON public.\"CamelizeTable\" USING btree (id)","table":"public.CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"CamelizeTable_id_key","type":"UNIQUE","def":"UNIQUE (id)","table":"public.CamelizeTable","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"public.hyphen-table","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"CamelizeTableId","type":"uuid","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"hyphen-table_hyphen-column_key","def":"CREATE UNIQUE INDEX \"hyphen-table_hyphen-column_key\" ON public.\"hyphen-table\" USING btree (\"hyphen-column\")","table":"public.hyphen-table","columns":["hyphen-column"],"comment":""}],"constraints":[{"name":"hyphen-table_CamelizeTableId_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (\"CamelizeTableId\") REFERENCES \"CamelizeTable\"(id) ON DELETE CASCADE","table":"public.hyphen-table","referenced_table":"CamelizeTable","columns":["CamelizeTableId"],"referenced_columns":["id"],"comment":""},{"name":"hyphen-table_hyphen-column_key","type":"UNIQUE","def":"UNIQUE (\"hyphen-column\")","table":"public.hyphen-table","referenced_table":"","columns":["hyphen-column"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"administrator.blogs","type":"BASE TABLE","comment":"admin blogs","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('administrator.blogs_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"name","type":"text","nullable":false,"default":null,"comment":""},{"name":"description","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON administrator.blogs USING btree (id)","table":"administrator.blogs","columns":["id"],"comment":""}],"constraints":[{"name":"blogs_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","table":"administrator.blogs","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":""},{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"administrator.blogs","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"backup.blogs","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blogs_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"dump","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp without time zone","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON backup.blogs USING btree (id)","table":"backup.blogs","columns":["id"],"comment":""}],"constraints":[{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blogs","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"backup.blog_options","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blog_options_id_seq'::regclass)","comment":""},{"name":"blog_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"label","type":"text","nullable":true,"default":null,"comment":""},{"name":"updated","type":"timestamp without time zone","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"blog_options_pkey","def":"CREATE UNIQUE INDEX blog_options_pkey ON backup.blog_options USING btree (id)","table":"backup.blog_options","columns":["id"],"comment":""}],"constraints":[{"name":"blog_options_blog_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (blog_id) REFERENCES blogs(id) ON DELETE CASCADE","table":"backup.blog_options","referenced_table":"blogs","columns":["blog_id"],"referenced_columns":["id"],"comment":""},{"name":"blog_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blog_options","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"time.bar","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"bar_pkey","def":"CREATE UNIQUE INDEX bar_pkey ON \"time\".bar USING btree (id)","table":"time.bar","columns":["id"],"comment":""}],"constraints":[{"name":"bar_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.bar","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"time.hyphenated-table","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"hyphenated-table_pkey","def":"CREATE UNIQUE INDEX \"hyphenated-table_pkey\" ON \"time\".\"hyphenated-table\" USING btree (id)","table":"time.hyphenated-table","columns":["id"],"comment":""}],"constraints":[{"name":"hyphenated-table_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.hyphenated-table","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""},{"name":"time.referencing","type":"BASE TABLE","comment":"","columns":[{"name":"id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"bar_id","type":"integer","nullable":false,"default":null,"comment":""},{"name":"ht_id","type":"integer","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"referencing_pkey","def":"CREATE UNIQUE INDEX referencing_pkey ON \"time\".referencing USING btree (id)","table":"time.referencing","columns":["id"],"comment":""}],"constraints":[{"name":"referencing_bar_id","type":"FOREIGN KEY","def":"FOREIGN KEY (bar_id) REFERENCES \"time\".bar(id)","table":"time.referencing","referenced_table":"bar","columns":["bar_id"],"referenced_columns":["id"],"comment":""},{"name":"referencing_ht_id","type":"FOREIGN KEY","def":"FOREIGN KEY (ht_id) REFERENCES \"time\".\"hyphenated-table\"(id)","table":"time.referencing","referenced_table":"hyphenated-table","columns":["ht_id"],"referenced_columns":["id"],"comment":""},{"name":"referencing_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.referencing","referenced_table":"","columns":["id"],"referenced_columns":[],"comment":""}],"triggers":[],"def":""}],"relations":[{"table":"public.user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","virtual":false},{"table":"public.posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","virtual":false},{"table":"public.comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users(id)","virtual":false},{"table":"public.comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"public.posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts(id)","virtual":false},{"table":"public.comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","virtual":false},{"table":"public.comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"public.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)","virtual":false},{"table":"public.hyphen-table","columns":["CamelizeTableId"],"cardinality":"Zero or more","parent_table":"public.CamelizeTable","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (\"CamelizeTableId\") REFERENCES \"CamelizeTable\"(id) ON DELETE CASCADE","virtual":false},{"table":"administrator.blogs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE","virtual":false},{"table":"backup.blog_options","columns":["blog_id"],"cardinality":"Zero or more","parent_table":"backup.blogs","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (blog_id) REFERENCES blogs(id) ON DELETE CASCADE","virtual":false},{"table":"time.referencing","columns":["bar_id"],"cardinality":"Zero or more","parent_table":"time.bar","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (bar_id) REFERENCES \"time\".bar(id)","virtual":false},{"table":"time.referencing","columns":["ht_id"],"cardinality":"Zero or more","parent_table":"time.hyphenated-table","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (ht_id) REFERENCES \"time\".\"hyphenated-table\"(id)","virtual":false},{"table":"public.logs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"public.users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"logs-\u003eusers","virtual":true},{"table":"public.logs","columns":["post_id"],"cardinality":"Zero or more","parent_table":"public.posts","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"public.logs","columns":["comment_id"],"cardinality":"Zero or more","parent_table":"public.comments","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"public.logs","columns":["comment_star_id"],"cardinality":"Zero or more","parent_table":"public.comment_stars","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true}],"functions":[{"name":"public.uuid_nil","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_ns_dns","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_ns_url","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_ns_oid","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_ns_x500","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_generate_v1","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_generate_v1mc","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_generate_v3","return_type":"uuid","arguments":"namespace uuid, name text","type":"FUNCTION"},{"name":"public.uuid_generate_v4","return_type":"uuid","arguments":"","type":"FUNCTION"},{"name":"public.uuid_generate_v5","return_type":"uuid","arguments":"namespace uuid, name text","type":"FUNCTION"},{"name":"public.update_updated","return_type":"trigger","arguments":"","type":"FUNCTION"}],"driver":{"name":"postgres","database_version":"PostgreSQL 9.5.25 on x86_64-pc-linux-gnu (Debian 9.5.25-1.pgdg90+1), compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit","meta":{"current_schema":"public","search_paths":["\"$user\"","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}}} diff --git a/sample/sqlite/schema.json b/sample/sqlite/schema.json index 901454cc..f3d68e5a 100644 --- a/sample/sqlite/schema.json +++ b/sample/sqlite/schema.json @@ -1 +1 @@ -{"name":"testdb.sqlite3","desc":"Sample database document.","tables":[{"name":"users","type":"table","comment":"","columns":[{"name":"id","type":"INTEGER","nullable":true,"default":null,"comment":""},{"name":"username","type":"TEXT","nullable":false,"default":null,"comment":""},{"name":"password","type":"TEXT","nullable":false,"default":null,"comment":"","labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"TEXT","nullable":false,"default":null,"comment":"","labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"NUMERIC","nullable":false,"default":null,"comment":""},{"name":"updated","type":"NUMERIC","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON users(username)","table":"users","columns":["username"],"comment":""},{"name":"sqlite_autoindex_users_2","def":"UNIQUE (email)","table":"users","columns":["email"],"comment":""},{"name":"sqlite_autoindex_users_1","def":"UNIQUE (username)","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"sqlite_autoindex_users_2","type":"UNIQUE","def":"UNIQUE (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"sqlite_autoindex_users_1","type":"UNIQUE","def":"UNIQUE (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""},{"name":"-","type":"CHECK","def":"CHECK(length(username) \u003e 4)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE users (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n username TEXT UNIQUE NOT NULL CHECK(length(username) \u003e 4),\n password TEXT NOT NULL,\n email TEXT UNIQUE NOT NULL,\n created NUMERIC NOT NULL,\n updated NUMERIC\n)"},{"name":"user_options","type":"table","comment":"","columns":[{"name":"user_id","type":"INTEGER","nullable":true,"default":null,"comment":""},{"name":"show_email","type":"INTEGER","nullable":false,"default":"0","comment":""},{"name":"created","type":"NUMERIC","nullable":false,"default":null,"comment":""},{"name":"updated","type":"NUMERIC","nullable":true,"default":null,"comment":""}],"indexes":[],"constraints":[{"name":"user_id","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"- (Foreign key ID: 0)","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":""}],"triggers":[],"def":"CREATE TABLE user_options (\n user_id INTEGER PRIMARY KEY,\n show_email INTEGER NOT NULL DEFAULT 0,\n created NUMERIC NOT NULL,\n updated NUMERIC,\n CONSTRAINT user_options_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE\n)"},{"name":"posts","type":"table","comment":"","columns":[{"name":"id","type":"INTEGER","nullable":true,"default":null,"comment":""},{"name":"user_id","type":"INTEGER","nullable":false,"default":null,"comment":""},{"name":"title","type":"TEXT","nullable":false,"default":null,"comment":""},{"name":"body","type":"TEXT","nullable":false,"default":null,"comment":"post body"},{"name":"created","type":"NUMERIC","nullable":false,"default":null,"comment":""},{"name":"updated","type":"NUMERIC","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"CREATE INDEX posts_user_id_idx ON posts(user_id)","table":"posts","columns":["user_id"],"comment":""}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"- (Foreign key ID: 0)","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated AFTER UPDATE ON posts FOR EACH ROW\nBEGIN\n UPDATE posts SET updated = current_timestamp WHERE id = OLD.id;\nEND","comment":""}],"def":"CREATE TABLE posts (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n user_id INTEGER NOT NULL,\n title TEXT NOT NULL,\n body TEXT NOT NULL,\n created NUMERIC NOT NULL,\n updated NUMERIC,\n CONSTRAINT posts_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE\n)","labels":[{"Name":"green","Virtual":true},{"Name":"red","Virtual":true},{"Name":"blue","Virtual":true}]},{"name":"comments","type":"table","comment":"","columns":[{"name":"id","type":"INTEGER","nullable":true,"default":null,"comment":""},{"name":"post_id","type":"INTEGER","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"INTEGER","nullable":false,"default":null,"comment":""},{"name":"comment","type":"TEXT","nullable":false,"default":null,"comment":""},{"name":"created","type":"NUMERIC","nullable":false,"default":null,"comment":""},{"name":"updated","type":"NUMERIC","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"CREATE INDEX comments_post_id_user_id_idx ON comments(post_id, user_id)","table":"comments","columns":["post_id","user_id"],"comment":""},{"name":"sqlite_autoindex_comments_1","def":"UNIQUE (post_id, user_id)","table":"comments","columns":["post_id","user_id"],"comment":""}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"- (Foreign key ID: 0)","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE NO ACTION MATCH NONE","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":""},{"name":"- (Foreign key ID: 1)","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id) ON UPDATE NO ACTION ON DELETE NO ACTION MATCH NONE","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"],"comment":""},{"name":"sqlite_autoindex_comments_1","type":"UNIQUE","def":"UNIQUE (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE comments (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n post_id INTEGER NOT NULL,\n user_id INTEGER NOT NULL,\n comment TEXT NOT NULL,\n created NUMERIC NOT NULL,\n updated NUMERIC,\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 UNIQUE(post_id, user_id)\n)"},{"name":"comment_stars","type":"table","comment":"","columns":[{"name":"id","type":"INTEGER","nullable":true,"default":null,"comment":""},{"name":"user_id","type":"INTEGER","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"INTEGER","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"INTEGER","nullable":false,"default":null,"comment":""},{"name":"created","type":"NUMERIC","nullable":false,"default":null,"comment":""},{"name":"updated","type":"NUMERIC","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"sqlite_autoindex_comment_stars_1","def":"UNIQUE (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"],"comment":""}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"- (Foreign key ID: 0)","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE NO ACTION MATCH NONE","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"],"comment":""},{"name":"- (Foreign key ID: 1)","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 MATCH NONE","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"],"comment":""},{"name":"sqlite_autoindex_comment_stars_1","type":"UNIQUE","def":"UNIQUE (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE comment_stars (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n user_id INTEGER NOT NULL,\n comment_post_id INTEGER NOT NULL,\n comment_user_id INTEGER NOT NULL,\n created NUMERIC NOT NULL,\n updated NUMERIC,\n CONSTRAINT comment_stars_user_id_post_id_fk FOREIGN KEY(comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id),\n CONSTRAINT comment_stars_user_id_fk FOREIGN KEY(comment_user_id) REFERENCES users(id),\n UNIQUE(user_id, comment_post_id, comment_user_id)\n)"},{"name":"logs","type":"table","comment":"","columns":[{"name":"id","type":"INTEGER","nullable":true,"default":null,"comment":""},{"name":"user_id","type":"INTEGER","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"INTEGER","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"INTEGER","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"INTEGER","nullable":true,"default":null,"comment":""},{"name":"payload","type":"TEXT","nullable":true,"default":null,"comment":""},{"name":"created","type":"NUMERIC","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE logs (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n user_id INTEGER NOT NULL,\n post_id INTEGER,\n comment_id INTEGER,\n comment_star_id INTEGER,\n payload TEXT,\n created NUMERIC NOT NULL\n)"},{"name":"post_comments","type":"view","comment":"post and comments View table","columns":[{"name":"id","type":"INTEGER","nullable":true,"default":null,"comment":"comments.id"},{"name":"title","type":"TEXT","nullable":true,"default":null,"comment":"posts.title"},{"name":"post_user","type":"TEXT","nullable":true,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"TEXT","nullable":true,"default":null,"comment":""},{"name":"comment_user","type":"TEXT","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"NUMERIC","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"NUMERIC","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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","referenced_tables":["posts","comments","users"]},{"name":"CamelizeTable","type":"table","comment":"","columns":[{"name":"id","type":"INTEGER","nullable":true,"default":null,"comment":""},{"name":"created","type":"NUMERIC","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE CamelizeTable (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n created NUMERIC NOT NULL\n)"},{"name":"hyphen-table","type":"table","comment":"","columns":[{"name":"id","type":"INTEGER","nullable":true,"default":null,"comment":""},{"name":"hyphen-column","type":"TEXT","nullable":false,"default":null,"comment":""},{"name":"created","type":"NUMERIC","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE 'hyphen-table' (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n 'hyphen-column' TEXT NOT NULL,\n created NUMERIC NOT NULL\n)"},{"name":"check_constraints","type":"table","comment":"","columns":[{"name":"id","type":"INTEGER","nullable":true,"default":null,"comment":""},{"name":"col","type":"TEXT","nullable":true,"default":null,"comment":""},{"name":"brackets","type":"TEXT","nullable":false,"default":null,"comment":""},{"name":"checkcheck","type":"TEXT","nullable":false,"default":null,"comment":""},{"name":"downcase","type":"TEXT","nullable":false,"default":null,"comment":""},{"name":"nl","type":"TEXT","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"sqlite_autoindex_check_constraints_4","def":"UNIQUE (nl)","table":"check_constraints","columns":["nl"],"comment":""},{"name":"sqlite_autoindex_check_constraints_3","def":"UNIQUE (downcase)","table":"check_constraints","columns":["downcase"],"comment":""},{"name":"sqlite_autoindex_check_constraints_2","def":"UNIQUE (checkcheck)","table":"check_constraints","columns":["checkcheck"],"comment":""},{"name":"sqlite_autoindex_check_constraints_1","def":"UNIQUE (brackets)","table":"check_constraints","columns":["brackets"],"comment":""}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"check_constraints","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"sqlite_autoindex_check_constraints_4","type":"UNIQUE","def":"UNIQUE (nl)","table":"check_constraints","referenced_table":null,"columns":["nl"],"referenced_columns":null,"comment":""},{"name":"sqlite_autoindex_check_constraints_3","type":"UNIQUE","def":"UNIQUE (downcase)","table":"check_constraints","referenced_table":null,"columns":["downcase"],"referenced_columns":null,"comment":""},{"name":"sqlite_autoindex_check_constraints_2","type":"UNIQUE","def":"UNIQUE (checkcheck)","table":"check_constraints","referenced_table":null,"columns":["checkcheck"],"referenced_columns":null,"comment":""},{"name":"sqlite_autoindex_check_constraints_1","type":"UNIQUE","def":"UNIQUE (brackets)","table":"check_constraints","referenced_table":null,"columns":["brackets"],"referenced_columns":null,"comment":""},{"name":"-","type":"CHECK","def":"CHECK(length(col) \u003e 4)","table":"check_constraints","referenced_table":null,"columns":["col"],"referenced_columns":null,"comment":""},{"name":"-","type":"CHECK","def":"CHECK(((length(brackets) \u003e 4)))","table":"check_constraints","referenced_table":null,"columns":["brackets"],"referenced_columns":null,"comment":""},{"name":"-","type":"CHECK","def":"CHECK(length(checkcheck) \u003e 4)","table":"check_constraints","referenced_table":null,"columns":["checkcheck"],"referenced_columns":null,"comment":""},{"name":"-","type":"CHECK","def":"check(length(downcase) \u003e 4)","table":"check_constraints","referenced_table":null,"columns":["downcase"],"referenced_columns":null,"comment":""},{"name":"-","type":"CHECK","def":"check(length(nl) \u003e 4 OR nl != 'ln')","table":"check_constraints","referenced_table":null,"columns":["nl"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE check_constraints (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n col TEXT CHECK(length(col) \u003e 4),\n brackets TEXT UNIQUE NOT NULL CHECK(((length(brackets) \u003e 4))),\n checkcheck TEXT UNIQUE NOT NULL CHECK(length(checkcheck) \u003e 4),\n downcase TEXT UNIQUE NOT NULL check(length(downcase) \u003e 4),\n nl TEXT UNIQUE NOT\n NULL check(length(nl) \u003e 4 OR\n nl != 'ln')\n)"},{"name":"syslog","type":"virtual table","comment":"","columns":[{"name":"logs","type":"","nullable":true,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":"CREATE VIRTUAL TABLE syslog USING fts3(logs)"},{"name":"access_log","type":"virtual table","comment":"","columns":[{"name":"logs","type":"","nullable":true,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":"CREATE VIRTUAL TABLE access_log USING fts4(logs)"}],"relations":[{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE","virtual":false},{"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) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE","virtual":false},{"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) ON UPDATE NO ACTION ON DELETE NO ACTION MATCH NONE","virtual":false},{"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) ON UPDATE NO ACTION ON DELETE NO ACTION MATCH NONE","virtual":false},{"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) ON UPDATE NO ACTION ON DELETE NO ACTION MATCH NONE","virtual":false},{"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) ON UPDATE NO ACTION ON DELETE NO ACTION MATCH NONE","virtual":false},{"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":null,"driver":{"name":"sqlite","database_version":"3.39.4","meta":{}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} +{"name":"testdb.sqlite3","desc":"Sample database document.","tables":[{"name":"users","type":"table","comment":"","columns":[{"name":"id","type":"INTEGER","nullable":true,"default":null,"comment":""},{"name":"username","type":"TEXT","nullable":false,"default":null,"comment":""},{"name":"password","type":"TEXT","nullable":false,"default":null,"comment":"","labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"TEXT","nullable":false,"default":null,"comment":"","labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"NUMERIC","nullable":false,"default":null,"comment":""},{"name":"updated","type":"NUMERIC","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON users(username)","table":"users","columns":["username"],"comment":""},{"name":"sqlite_autoindex_users_2","def":"UNIQUE (email)","table":"users","columns":["email"],"comment":""},{"name":"sqlite_autoindex_users_1","def":"UNIQUE (username)","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"sqlite_autoindex_users_2","type":"UNIQUE","def":"UNIQUE (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"sqlite_autoindex_users_1","type":"UNIQUE","def":"UNIQUE (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""},{"name":"-","type":"CHECK","def":"CHECK(length(username) \u003e 4)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE users (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n username TEXT UNIQUE NOT NULL CHECK(length(username) \u003e 4),\n password TEXT NOT NULL,\n email TEXT UNIQUE NOT NULL,\n created NUMERIC NOT NULL,\n updated NUMERIC\n)"},{"name":"user_options","type":"table","comment":"","columns":[{"name":"user_id","type":"INTEGER","nullable":true,"default":null,"comment":""},{"name":"show_email","type":"INTEGER","nullable":false,"default":"0","comment":""},{"name":"created","type":"NUMERIC","nullable":false,"default":null,"comment":""},{"name":"updated","type":"NUMERIC","nullable":true,"default":null,"comment":""}],"indexes":[],"constraints":[{"name":"user_id","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"- (Foreign key ID: 0)","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":""}],"triggers":[],"def":"CREATE TABLE user_options (\n user_id INTEGER PRIMARY KEY,\n show_email INTEGER NOT NULL DEFAULT 0,\n created NUMERIC NOT NULL,\n updated NUMERIC,\n CONSTRAINT user_options_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE\n)"},{"name":"posts","type":"table","comment":"","columns":[{"name":"id","type":"INTEGER","nullable":true,"default":null,"comment":""},{"name":"user_id","type":"INTEGER","nullable":false,"default":null,"comment":""},{"name":"title","type":"TEXT","nullable":false,"default":null,"comment":""},{"name":"body","type":"TEXT","nullable":false,"default":null,"comment":"post body"},{"name":"created","type":"NUMERIC","nullable":false,"default":null,"comment":""},{"name":"updated","type":"NUMERIC","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"CREATE INDEX posts_user_id_idx ON posts(user_id)","table":"posts","columns":["user_id"],"comment":""}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"- (Foreign key ID: 0)","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated AFTER UPDATE ON posts FOR EACH ROW\nBEGIN\n UPDATE posts SET updated = current_timestamp WHERE id = OLD.id;\nEND","comment":""}],"def":"CREATE TABLE posts (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n user_id INTEGER NOT NULL,\n title TEXT NOT NULL,\n body TEXT NOT NULL,\n created NUMERIC NOT NULL,\n updated NUMERIC,\n CONSTRAINT posts_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE\n)","labels":[{"Name":"green","Virtual":true},{"Name":"red","Virtual":true},{"Name":"blue","Virtual":true}]},{"name":"comments","type":"table","comment":"","columns":[{"name":"id","type":"INTEGER","nullable":true,"default":null,"comment":""},{"name":"post_id","type":"INTEGER","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"INTEGER","nullable":false,"default":null,"comment":""},{"name":"comment","type":"TEXT","nullable":false,"default":null,"comment":""},{"name":"created","type":"NUMERIC","nullable":false,"default":null,"comment":""},{"name":"updated","type":"NUMERIC","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"CREATE INDEX comments_post_id_user_id_idx ON comments(post_id, user_id)","table":"comments","columns":["post_id","user_id"],"comment":""},{"name":"sqlite_autoindex_comments_1","def":"UNIQUE (post_id, user_id)","table":"comments","columns":["post_id","user_id"],"comment":""}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"- (Foreign key ID: 0)","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE NO ACTION MATCH NONE","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"],"comment":""},{"name":"- (Foreign key ID: 1)","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id) ON UPDATE NO ACTION ON DELETE NO ACTION MATCH NONE","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"],"comment":""},{"name":"sqlite_autoindex_comments_1","type":"UNIQUE","def":"UNIQUE (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE comments (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n post_id INTEGER NOT NULL,\n user_id INTEGER NOT NULL,\n comment TEXT NOT NULL,\n created NUMERIC NOT NULL,\n updated NUMERIC,\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 UNIQUE(post_id, user_id)\n)"},{"name":"comment_stars","type":"table","comment":"","columns":[{"name":"id","type":"INTEGER","nullable":true,"default":null,"comment":""},{"name":"user_id","type":"INTEGER","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"INTEGER","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"INTEGER","nullable":false,"default":null,"comment":""},{"name":"created","type":"NUMERIC","nullable":false,"default":null,"comment":""},{"name":"updated","type":"NUMERIC","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"sqlite_autoindex_comment_stars_1","def":"UNIQUE (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"],"comment":""}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"- (Foreign key ID: 0)","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE NO ACTION MATCH NONE","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"],"comment":""},{"name":"- (Foreign key ID: 1)","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 MATCH NONE","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"],"comment":""},{"name":"sqlite_autoindex_comment_stars_1","type":"UNIQUE","def":"UNIQUE (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE comment_stars (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n user_id INTEGER NOT NULL,\n comment_post_id INTEGER NOT NULL,\n comment_user_id INTEGER NOT NULL,\n created NUMERIC NOT NULL,\n updated NUMERIC,\n CONSTRAINT comment_stars_user_id_post_id_fk FOREIGN KEY(comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id),\n CONSTRAINT comment_stars_user_id_fk FOREIGN KEY(comment_user_id) REFERENCES users(id),\n UNIQUE(user_id, comment_post_id, comment_user_id)\n)"},{"name":"logs","type":"table","comment":"","columns":[{"name":"id","type":"INTEGER","nullable":true,"default":null,"comment":""},{"name":"user_id","type":"INTEGER","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"INTEGER","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"INTEGER","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"INTEGER","nullable":true,"default":null,"comment":""},{"name":"payload","type":"TEXT","nullable":true,"default":null,"comment":""},{"name":"created","type":"NUMERIC","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE logs (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n user_id INTEGER NOT NULL,\n post_id INTEGER,\n comment_id INTEGER,\n comment_star_id INTEGER,\n payload TEXT,\n created NUMERIC NOT NULL\n)"},{"name":"post_comments","type":"view","comment":"post and comments View table","columns":[{"name":"id","type":"INTEGER","nullable":true,"default":null,"comment":"comments.id"},{"name":"title","type":"TEXT","nullable":true,"default":null,"comment":"posts.title"},{"name":"post_user","type":"TEXT","nullable":true,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"TEXT","nullable":true,"default":null,"comment":""},{"name":"comment_user","type":"TEXT","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"NUMERIC","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"NUMERIC","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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","referenced_tables":["posts","comments","users"]},{"name":"CamelizeTable","type":"table","comment":"","columns":[{"name":"id","type":"INTEGER","nullable":true,"default":null,"comment":""},{"name":"created","type":"NUMERIC","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE CamelizeTable (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n created NUMERIC NOT NULL\n)"},{"name":"hyphen-table","type":"table","comment":"","columns":[{"name":"id","type":"INTEGER","nullable":true,"default":null,"comment":""},{"name":"hyphen-column","type":"TEXT","nullable":false,"default":null,"comment":""},{"name":"created","type":"NUMERIC","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE 'hyphen-table' (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n 'hyphen-column' TEXT NOT NULL,\n created NUMERIC NOT NULL\n)"},{"name":"check_constraints","type":"table","comment":"","columns":[{"name":"id","type":"INTEGER","nullable":true,"default":null,"comment":""},{"name":"col","type":"TEXT","nullable":true,"default":null,"comment":""},{"name":"brackets","type":"TEXT","nullable":false,"default":null,"comment":""},{"name":"checkcheck","type":"TEXT","nullable":false,"default":null,"comment":""},{"name":"downcase","type":"TEXT","nullable":false,"default":null,"comment":""},{"name":"nl","type":"TEXT","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"sqlite_autoindex_check_constraints_4","def":"UNIQUE (nl)","table":"check_constraints","columns":["nl"],"comment":""},{"name":"sqlite_autoindex_check_constraints_3","def":"UNIQUE (downcase)","table":"check_constraints","columns":["downcase"],"comment":""},{"name":"sqlite_autoindex_check_constraints_2","def":"UNIQUE (checkcheck)","table":"check_constraints","columns":["checkcheck"],"comment":""},{"name":"sqlite_autoindex_check_constraints_1","def":"UNIQUE (brackets)","table":"check_constraints","columns":["brackets"],"comment":""}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"check_constraints","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"sqlite_autoindex_check_constraints_4","type":"UNIQUE","def":"UNIQUE (nl)","table":"check_constraints","referenced_table":null,"columns":["nl"],"referenced_columns":null,"comment":""},{"name":"sqlite_autoindex_check_constraints_3","type":"UNIQUE","def":"UNIQUE (downcase)","table":"check_constraints","referenced_table":null,"columns":["downcase"],"referenced_columns":null,"comment":""},{"name":"sqlite_autoindex_check_constraints_2","type":"UNIQUE","def":"UNIQUE (checkcheck)","table":"check_constraints","referenced_table":null,"columns":["checkcheck"],"referenced_columns":null,"comment":""},{"name":"sqlite_autoindex_check_constraints_1","type":"UNIQUE","def":"UNIQUE (brackets)","table":"check_constraints","referenced_table":null,"columns":["brackets"],"referenced_columns":null,"comment":""},{"name":"-","type":"CHECK","def":"CHECK(length(col) \u003e 4)","table":"check_constraints","referenced_table":null,"columns":["col"],"referenced_columns":null,"comment":""},{"name":"-","type":"CHECK","def":"CHECK(((length(brackets) \u003e 4)))","table":"check_constraints","referenced_table":null,"columns":["brackets"],"referenced_columns":null,"comment":""},{"name":"-","type":"CHECK","def":"CHECK(length(checkcheck) \u003e 4)","table":"check_constraints","referenced_table":null,"columns":["checkcheck"],"referenced_columns":null,"comment":""},{"name":"-","type":"CHECK","def":"check(length(downcase) \u003e 4)","table":"check_constraints","referenced_table":null,"columns":["downcase"],"referenced_columns":null,"comment":""},{"name":"-","type":"CHECK","def":"check(length(nl) \u003e 4 OR nl != 'ln')","table":"check_constraints","referenced_table":null,"columns":["nl"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE check_constraints (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n col TEXT CHECK(length(col) \u003e 4),\n brackets TEXT UNIQUE NOT NULL CHECK(((length(brackets) \u003e 4))),\n checkcheck TEXT UNIQUE NOT NULL CHECK(length(checkcheck) \u003e 4),\n downcase TEXT UNIQUE NOT NULL check(length(downcase) \u003e 4),\n nl TEXT UNIQUE NOT\n NULL check(length(nl) \u003e 4 OR\n nl != 'ln')\n)"},{"name":"syslog","type":"virtual table","comment":"","columns":[{"name":"logs","type":"","nullable":true,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":"CREATE VIRTUAL TABLE syslog USING fts3(logs)"},{"name":"access_log","type":"virtual table","comment":"","columns":[{"name":"logs","type":"","nullable":true,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":"CREATE VIRTUAL TABLE access_log USING fts4(logs)"}],"relations":[{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE","virtual":false},{"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) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE","virtual":false},{"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) ON UPDATE NO ACTION ON DELETE NO ACTION MATCH NONE","virtual":false},{"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) ON UPDATE NO ACTION ON DELETE NO ACTION MATCH NONE","virtual":false},{"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) ON UPDATE NO ACTION ON DELETE NO ACTION MATCH NONE","virtual":false},{"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) ON UPDATE NO ACTION ON DELETE NO ACTION MATCH NONE","virtual":false},{"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":null,"driver":{"name":"sqlite","database_version":"3.42.0","meta":{}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} diff --git a/sample/viewpoints/schema.json b/sample/viewpoints/schema.json index e1e5bf49..dcb6fc14 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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":"","labels":[{"Name":"user","Virtual":true}]},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"],"comment":""},{"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"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":"","labels":[{"Name":"user","Virtual":true}]},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"default":null,"comment":"","extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":"","labels":[{"Name":"user","Virtual":true}]},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"],"comment":""}],"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"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,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":"","labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com","labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","referenced_table":null,"columns":null,"referenced_columns":null,"comment":""}],"triggers":[],"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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.1.0","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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":"","labels":[{"Name":"user","Virtual":true}]},{"name":"comment_post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"],"comment":""},{"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"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":"","labels":[{"Name":"user","Virtual":true}]},{"name":"comment","type":"text","nullable":false,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"default":null,"comment":"","extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"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"],"comment":""},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"],"comment":""},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"],"comment":""}],"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"],"comment":""},{"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"],"comment":""},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"bigint","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"bigint","nullable":false,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"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,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":"","labels":[{"Name":"user","Virtual":true}]},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"default":null,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false,"default":null,"comment":""},{"name":"updated","type":"datetime","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"],"comment":""}],"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"],"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()","comment":""}],"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,"default":null,"comment":""},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"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,"default":null,"comment":"","extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"comment":"","labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"default":null,"comment":"ex. user@example.com","labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"timestamp","nullable":false,"default":null,"comment":""},{"name":"updated","type":"timestamp","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"],"comment":""},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"],"comment":""},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","referenced_table":null,"columns":null,"referenced_columns":null,"comment":""}],"triggers":[],"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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)","virtual":false},{"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.2.0","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/testdata/test_tbls.yml b/testdata/test_tbls.yml index 2225da47..2724d531 100644 --- a/testdata/test_tbls.yml +++ b/testdata/test_tbls.yml @@ -43,6 +43,8 @@ relations: parentTable: comment_stars parentColumns: - id + cardinality: exactly one + parentCardinality: exactly one comments: - table: posts From 94a6a5533eb2bde7862782c8f94a70618340e84f Mon Sep 17 00:00:00 2001 From: k1LoW Date: Tue, 7 Nov 2023 19:33:46 +0900 Subject: [PATCH 3/3] Fix --- sample/mssql/README.md | 2 +- sample/mssql/schema.json | 2 +- sample/mssql/schema.svg | 606 +++++++++++++++++++-------------------- 3 files changed, 305 insertions(+), 305 deletions(-) diff --git a/sample/mssql/README.md b/sample/mssql/README.md index 5bde8483..83588f12 100644 --- a/sample/mssql/README.md +++ b/sample/mssql/README.md @@ -12,7 +12,6 @@ Sample database document. | Name | Columns | Comment | Type | Labels | | ---- | ------- | ------- | ---- | ------ | -| [Rabbits.Running](Rabbits.Running.md) | 3 | | BASIC TABLE | | | [users](users.md) | 6 | Users table | BASIC TABLE | | | [user_options](user_options.md) | 4 | User options table | BASIC TABLE | | | [posts](posts.md) | 6 | | BASIC TABLE | `green` `red` `blue` | @@ -25,6 +24,7 @@ Sample database document. | [administrator.blogs](administrator.blogs.md) | 6 | admin blogs | BASIC TABLE | | | [name with spaces](name%20with%20spaces.md) | 1 | | VIEW | | | [Sales.Product](Sales.Product.md) | 2 | | BASIC TABLE | | +| [Rabbits.Running](Rabbits.Running.md) | 3 | | BASIC TABLE | | ## Stored procedures and functions diff --git a/sample/mssql/schema.json b/sample/mssql/schema.json index 68c45d60..3730dae2 100644 --- a/sample/mssql/schema.json +++ b/sample/mssql/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"Rabbits.Running","type":"BASIC TABLE","comment":"","columns":[{"name":"LocationID","type":"int","nullable":false,"default":null,"comment":""},{"name":"ProductID","type":"int","nullable":true,"default":null,"comment":""},{"name":"EmployeeID","type":"int","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PK__Running_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ LocationID ]","table":"Rabbits.Running","columns":["LocationID"],"comment":""},{"name":"UQ__Running_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ EmployeeID ]","table":"Rabbits.Running","columns":["EmployeeID"],"comment":""},{"name":"UQ__Running_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ ProductID ]","table":"Rabbits.Running","columns":["ProductID"],"comment":""}],"constraints":[{"name":"PK__Running_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ LocationID ]","table":"Rabbits.Running","referenced_table":null,"columns":["LocationID"],"referenced_columns":null,"comment":""},{"name":"UQ__Running_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ EmployeeID ]","table":"Rabbits.Running","referenced_table":null,"columns":["EmployeeID"],"referenced_columns":null,"comment":""},{"name":"UQ__Running_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ ProductID ]","table":"Rabbits.Running","referenced_table":null,"columns":["ProductID"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"def":""},{"name":"users","type":"BASIC TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"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,"default":null,"comment":"ex. user@example.com"},{"name":"created","type":"date","nullable":false,"default":null,"comment":""},{"name":"updated","type":"date","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PK__users_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"users","columns":["id"],"comment":""},{"name":"UQ__users_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ email ]","table":"users","columns":["email"],"comment":""},{"name":"UQ__users_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ username ]","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"PK__users_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"UQ__users_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ email ]","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"UQ__users_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ username ]","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""},{"name":"CK__users__username_*","type":"CHECK","def":"CHECK(len([username])\u003e(4))","table":"users","referenced_table":null,"columns":null,"referenced_columns":null,"comment":""}],"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;","comment":""}],"def":""},{"name":"user_options","type":"BASIC TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"show_email","type":"bit","nullable":false,"default":"((0))","comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""},{"name":"updated","type":"date","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PK__user_opt_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ user_id ]","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PK__user_opt_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ user_id ]","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"def":""},{"name":"posts","type":"BASIC TABLE","comment":"","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":null,"comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"created","type":"date","nullable":false,"default":null,"comment":""},{"name":"updated","type":"date","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_id_pk","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"posts","columns":["id"],"comment":""},{"name":"UQ__posts_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, title ]","table":"posts","columns":["user_id","title"],"comment":""},{"name":"posts_user_id_idx","def":"NONCLUSTERED, [ user_id ]","table":"posts","columns":["user_id"],"comment":""}],"constraints":[{"name":"posts_id_pk","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"UQ__posts_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, title ]","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"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;","comment":""}],"def":"","labels":[{"Name":"green","Virtual":true},{"Name":"red","Virtual":true},{"Name":"blue","Virtual":true}]},{"name":"comments","type":"BASIC TABLE","comment":"","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""},{"name":"updated","type":"date","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"comments_id_pk","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"comments","columns":["id"],"comment":""},{"name":"UQ__comments_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"],"comment":""},{"name":"comments_post_id_user_id_idx","def":"NONCLUSTERED, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"],"comment":""}],"constraints":[{"name":"comments_id_pk","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"UQ__comments_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ post_id, user_id ]","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""},{"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"],"comment":""}],"triggers":[],"def":""},{"name":"comment_stars","type":"BASIC TABLE","comment":"","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""},{"name":"updated","type":"date","nullable":true,"default":null,"comment":""}],"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"],"comment":""}],"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","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""},{"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"],"comment":""}],"triggers":[],"def":""},{"name":"logs","type":"BASIC TABLE","comment":"","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"int","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"int","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"int","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":""},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"int","nullable":true,"default":null,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":null,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":""},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"date","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"date","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":""},{"name":"hyphen-table","type":"BASIC TABLE","comment":"","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":""},{"name":"administrator.blogs","type":"BASIC TABLE","comment":"admin blogs","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"name","type":"text","nullable":false,"default":null,"comment":""},{"name":"description","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""},{"name":"updated","type":"date","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PK__blogs_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"administrator.blogs","columns":["id"],"comment":""}],"constraints":[{"name":"PK__blogs_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"administrator.blogs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"def":""},{"name":"name with spaces","type":"VIEW","comment":"","columns":[{"name":"title","type":"varchar(255)","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"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","comment":"","columns":[{"name":"ProductID","type":"int","nullable":false,"default":null,"comment":""},{"name":"SalesPersonID","type":"int","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PK__Product_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ ProductID ]","table":"Sales.Product","columns":["ProductID"],"comment":""},{"name":"UQ__Product_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ SalesPersonID ]","table":"Sales.Product","columns":["SalesPersonID"],"comment":""}],"constraints":[{"name":"PK__Product_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ ProductID ]","table":"Sales.Product","referenced_table":null,"columns":["ProductID"],"referenced_columns":null,"comment":""},{"name":"UQ__Product_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ SalesPersonID ]","table":"Sales.Product","referenced_table":null,"columns":["SalesPersonID"],"referenced_columns":null,"comment":""}],"triggers":[],"def":""}],"relations":[{"table":"Rabbits.Running","columns":["ProductID"],"cardinality":"Zero or one","parent_table":"Sales.Product","parent_columns":["SalesPersonID"],"parent_cardinality":"Zero or one","def":"","virtual":false},{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","virtual":false},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","virtual":false},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","virtual":false},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","virtual":false},{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","virtual":false},{"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":"","virtual":false},{"table":"administrator.blogs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","virtual":false},{"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 2017 (RTM-CU31-GDR) (KB5029376) - 14.0.3465.1 (X64) \n\tJul 30 2023 15:31:58 \n\tCopyright (C) 2017 Microsoft Corporation\n\tDeveloper Edition (64-bit) on Linux (Ubuntu 18.04.6 LTS)","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,"default":null,"comment":""},{"name":"username","type":"varchar(50)","nullable":false,"default":null,"comment":""},{"name":"password","type":"varchar(50)","nullable":false,"default":null,"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,"default":null,"comment":"ex. user@example.com"},{"name":"created","type":"date","nullable":false,"default":null,"comment":""},{"name":"updated","type":"date","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PK__users_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"users","columns":["id"],"comment":""},{"name":"UQ__users_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ email ]","table":"users","columns":["email"],"comment":""},{"name":"UQ__users_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ username ]","table":"users","columns":["username"],"comment":""}],"constraints":[{"name":"PK__users_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"users","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"UQ__users_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ email ]","table":"users","referenced_table":null,"columns":["email"],"referenced_columns":null,"comment":""},{"name":"UQ__users_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ username ]","table":"users","referenced_table":null,"columns":["username"],"referenced_columns":null,"comment":""},{"name":"CK__users__username_*","type":"CHECK","def":"CHECK(len([username])\u003e(4))","table":"users","referenced_table":null,"columns":null,"referenced_columns":null,"comment":""}],"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;","comment":""}],"def":""},{"name":"user_options","type":"BASIC TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"show_email","type":"bit","nullable":false,"default":"((0))","comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""},{"name":"updated","type":"date","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PK__user_opt_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ user_id ]","table":"user_options","columns":["user_id"],"comment":""}],"constraints":[{"name":"PK__user_opt_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ user_id ]","table":"user_options","referenced_table":null,"columns":["user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"def":""},{"name":"posts","type":"BASIC TABLE","comment":"","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":null,"comment":""},{"name":"body","type":"text","nullable":false,"default":null,"comment":"post body"},{"name":"created","type":"date","nullable":false,"default":null,"comment":""},{"name":"updated","type":"date","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"posts_id_pk","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"posts","columns":["id"],"comment":""},{"name":"UQ__posts_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, title ]","table":"posts","columns":["user_id","title"],"comment":""},{"name":"posts_user_id_idx","def":"NONCLUSTERED, [ user_id ]","table":"posts","columns":["user_id"],"comment":""}],"constraints":[{"name":"posts_id_pk","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"posts","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"UQ__posts_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, title ]","table":"posts","referenced_table":null,"columns":["user_id","title"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"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;","comment":""}],"def":"","labels":[{"Name":"green","Virtual":true},{"Name":"red","Virtual":true},{"Name":"blue","Virtual":true}]},{"name":"comments","type":"BASIC TABLE","comment":"","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""},{"name":"updated","type":"date","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"comments_id_pk","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"comments","columns":["id"],"comment":""},{"name":"UQ__comments_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"],"comment":""},{"name":"comments_post_id_user_id_idx","def":"NONCLUSTERED, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"],"comment":""}],"constraints":[{"name":"comments_id_pk","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"comments","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"UQ__comments_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ post_id, user_id ]","table":"comments","referenced_table":null,"columns":["post_id","user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""},{"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"],"comment":""}],"triggers":[],"def":""},{"name":"comment_stars","type":"BASIC TABLE","comment":"","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_post_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"comment_user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""},{"name":"updated","type":"date","nullable":true,"default":null,"comment":""}],"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"],"comment":""}],"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","referenced_table":null,"columns":["user_id","comment_post_id","comment_user_id"],"referenced_columns":null,"comment":""},{"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"],"comment":""},{"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"],"comment":""}],"triggers":[],"def":""},{"name":"logs","type":"BASIC TABLE","comment":"","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"post_id","type":"int","nullable":true,"default":null,"comment":""},{"name":"comment_id","type":"int","nullable":true,"default":null,"comment":""},{"name":"comment_star_id","type":"int","nullable":true,"default":null,"comment":""},{"name":"payload","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":""},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"int","nullable":true,"default":null,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":null,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"default":null,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"default":null,"comment":""},{"name":"comment_user","type":"varchar(50)","nullable":true,"default":null,"comment":"comments.users.username"},{"name":"created","type":"date","nullable":true,"default":null,"comment":"comments.created"},{"name":"updated","type":"date","nullable":true,"default":null,"comment":"comments.updated"}],"indexes":[],"constraints":[],"triggers":[],"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","comment":"","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":""},{"name":"hyphen-table","type":"BASIC TABLE","comment":"","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"hyphen-column","type":"text","nullable":false,"default":null,"comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":""},{"name":"administrator.blogs","type":"BASIC TABLE","comment":"admin blogs","columns":[{"name":"id","type":"int","nullable":false,"default":null,"comment":""},{"name":"user_id","type":"int","nullable":false,"default":null,"comment":""},{"name":"name","type":"text","nullable":false,"default":null,"comment":""},{"name":"description","type":"text","nullable":true,"default":null,"comment":""},{"name":"created","type":"date","nullable":false,"default":null,"comment":""},{"name":"updated","type":"date","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PK__blogs_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"administrator.blogs","columns":["id"],"comment":""}],"constraints":[{"name":"PK__blogs_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"administrator.blogs","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"def":""},{"name":"name with spaces","type":"VIEW","comment":"","columns":[{"name":"title","type":"varchar(255)","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"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","comment":"","columns":[{"name":"ProductID","type":"int","nullable":false,"default":null,"comment":""},{"name":"SalesPersonID","type":"int","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PK__Product_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ ProductID ]","table":"Sales.Product","columns":["ProductID"],"comment":""},{"name":"UQ__Product_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ SalesPersonID ]","table":"Sales.Product","columns":["SalesPersonID"],"comment":""}],"constraints":[{"name":"PK__Product_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ ProductID ]","table":"Sales.Product","referenced_table":null,"columns":["ProductID"],"referenced_columns":null,"comment":""},{"name":"UQ__Product_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ SalesPersonID ]","table":"Sales.Product","referenced_table":null,"columns":["SalesPersonID"],"referenced_columns":null,"comment":""}],"triggers":[],"def":""},{"name":"Rabbits.Running","type":"BASIC TABLE","comment":"","columns":[{"name":"LocationID","type":"int","nullable":false,"default":null,"comment":""},{"name":"ProductID","type":"int","nullable":true,"default":null,"comment":""},{"name":"EmployeeID","type":"int","nullable":true,"default":null,"comment":""}],"indexes":[{"name":"PK__Running_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ LocationID ]","table":"Rabbits.Running","columns":["LocationID"],"comment":""},{"name":"UQ__Running_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ EmployeeID ]","table":"Rabbits.Running","columns":["EmployeeID"],"comment":""},{"name":"UQ__Running_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ ProductID ]","table":"Rabbits.Running","columns":["ProductID"],"comment":""}],"constraints":[{"name":"PK__Running_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ LocationID ]","table":"Rabbits.Running","referenced_table":null,"columns":["LocationID"],"referenced_columns":null,"comment":""},{"name":"UQ__Running_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ EmployeeID ]","table":"Rabbits.Running","referenced_table":null,"columns":["EmployeeID"],"referenced_columns":null,"comment":""},{"name":"UQ__Running_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ ProductID ]","table":"Rabbits.Running","referenced_table":null,"columns":["ProductID"],"referenced_columns":null,"comment":""},{"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"],"comment":""}],"triggers":[],"def":""}],"relations":[{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","virtual":false},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","virtual":false},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","virtual":false},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","virtual":false},{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","virtual":false},{"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":"","virtual":false},{"table":"administrator.blogs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","virtual":false},{"table":"Rabbits.Running","columns":["ProductID"],"cardinality":"Zero or one","parent_table":"Sales.Product","parent_columns":["SalesPersonID"],"parent_cardinality":"Zero or one","def":"","virtual":false},{"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 2017 (RTM-CU31-GDR) (KB5029376) - 14.0.3465.1 (X64) \n\tJul 30 2023 15:31:58 \n\tCopyright (C) 2017 Microsoft Corporation\n\tDeveloper Edition (64-bit) on Linux (Ubuntu 18.04.6 LTS)","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} diff --git a/sample/mssql/schema.svg b/sample/mssql/schema.svg index fc04c709..00c04cf1 100644 --- a/sample/mssql/schema.svg +++ b/sample/mssql/schema.svg @@ -4,380 +4,380 @@ - + testdb - - - -Rabbits.Running - - -Rabbits.Running -     -[BASIC TABLE] - -LocationID     -[int] - -ProductID     -[int] - -EmployeeID     -[int] - - - -Sales.Product - - -Sales.Product -     -[BASIC TABLE] - -ProductID     -[int] - -SalesPersonID     -[int] - - - -Rabbits.Running:ProductID->Sales.Product:SalesPersonID - - - + - + users - - -users -     -[BASIC TABLE] - -id     -[int] - -username     -[varchar(50)] - -password     -[varchar(50)] - -email     -[varchar(355)] - -created     -[date] - -updated     -[date] + + +users +     +[BASIC TABLE] + +id     +[int] + +username     +[varchar(50)] + +password     +[varchar(50)] + +email     +[varchar(355)] + +created     +[date] + +updated     +[date] - + user_options - - -user_options -     -[BASIC TABLE] - -user_id     -[int] - -show_email     -[bit] - -created     -[date] - -updated     -[date] + + +user_options +     +[BASIC TABLE] + +user_id     +[int] + +show_email     +[bit] + +created     +[date] + +updated     +[date] - + user_options:user_id->users:id - - + + - + posts - - -posts -     -[BASIC TABLE] - -id     -[int] - -user_id     -[int] - -title     -[varchar(255)] - -body     -[text] - -created     -[date] - -updated     -[date] + + +posts +     +[BASIC TABLE] + +id     +[int] + +user_id     +[int] + +title     +[varchar(255)] + +body     +[text] + +created     +[date] + +updated     +[date] - + posts:user_id->users:id - - + + - + comments - - -comments -     -[BASIC TABLE] - -id     -[int] - -post_id     -[int] - -user_id     -[int] - -comment     -[text] - -created     -[date] - -updated     -[date] + + +comments +     +[BASIC TABLE] + +id     +[int] + +post_id     +[int] + +user_id     +[int] + +comment     +[text] + +created     +[date] + +updated     +[date] - + comments:user_id->users:id - - + + - + comments:post_id->posts:id - - + + - + comment_stars - - -comment_stars -     -[BASIC TABLE] - -id     -[int] - -user_id     -[int] - -comment_post_id     -[int] - -comment_user_id     -[int] - -created     -[date] - -updated     -[date] + + +comment_stars +     +[BASIC TABLE] + +id     +[int] + +user_id     +[int] + +comment_post_id     +[int] + +comment_user_id     +[int] + +created     +[date] + +updated     +[date] - + comment_stars:comment_user_id->users:id - - + + - + comment_stars:comment_post_id->comments:post_id - - + + - + logs - - -logs -     -[BASIC TABLE] - -id     -[int] - -user_id     -[int] - -post_id     -[int] - -comment_id     -[int] - -comment_star_id     -[int] - -payload     -[text] - -created     -[date] + + +logs +     +[BASIC TABLE] + +id     +[int] + +user_id     +[int] + +post_id     +[int] + +comment_id     +[int] + +comment_star_id     +[int] + +payload     +[text] + +created     +[date] logs:user_id->users:id - - -logs->users + + +logs->users logs:post_id->posts:id - - -Additional Relation + + +Additional Relation logs:comment_id->comments:id - - -Additional Relation + + +Additional Relation logs:comment_star_id->comment_stars:id - - -Additional Relation + + +Additional Relation - + post_comments - - -post_comments -     -[VIEW] - -id     -[int] - -title     -[varchar(255)] - -post_user     -[varchar(50)] - -comment     -[text] - -comment_user     -[varchar(50)] - -created     -[date] - -updated     -[date] + + +post_comments +     +[VIEW] + +id     +[int] + +title     +[varchar(255)] + +post_user     +[varchar(50)] + +comment     +[text] + +comment_user     +[varchar(50)] + +created     +[date] + +updated     +[date] - + CamelizeTable - - -CamelizeTable -     -[BASIC TABLE] - -id     -[int] - -created     -[date] + + +CamelizeTable +     +[BASIC TABLE] + +id     +[int] + +created     +[date] - + hyphen-table - - -hyphen-table -     -[BASIC TABLE] - -id     -[int] - -hyphen-column     -[text] - -created     -[date] + + +hyphen-table +     +[BASIC TABLE] + +id     +[int] + +hyphen-column     +[text] + +created     +[date] - + administrator.blogs - - -administrator.blogs -     -[BASIC TABLE] - -id     -[int] - -user_id     -[int] - -name     -[text] - -description     -[text] - -created     -[date] - -updated     -[date] + + +administrator.blogs +     +[BASIC TABLE] + +id     +[int] + +user_id     +[int] + +name     +[text] + +description     +[text] + +created     +[date] + +updated     +[date] - + administrator.blogs:user_id->users:id - - + + - + name with spaces - - -name with spaces -     -[VIEW] - -title     -[varchar(255)] + + +name with spaces +     +[VIEW] + +title     +[varchar(255)] + + + +Sales.Product + + +Sales.Product +     +[BASIC TABLE] + +ProductID     +[int] + +SalesPersonID     +[int] + + + +Rabbits.Running + + +Rabbits.Running +     +[BASIC TABLE] + +LocationID     +[int] + +ProductID     +[int] + +EmployeeID     +[int] + + + +Rabbits.Running:ProductID->Sales.Product:SalesPersonID + +