From 9fe4e3f6d37900e8669a32d01831240dc1a349f3 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Thu, 23 Jan 2025 23:36:47 +0900 Subject: [PATCH 01/13] fix: Set omitempty --- schema/schema.go | 50 ++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/schema/schema.go b/schema/schema.go index c3f07c95..3a7308da 100644 --- a/schema/schema.go +++ b/schema/schema.go @@ -52,8 +52,8 @@ func (labels Labels) Contains(name string) bool { // Viewpoint is the struct for viewpoint information type Viewpoint struct { - Name string `json:"name,omitempty"` - Desc string `json:"desc,omitempty"` + Name string `json:"name"` + Desc string `json:"desc"` Labels []string `json:"labels,omitempty"` Tables []string `json:"tables,omitempty"` Distance int `json:"distance,omitempty"` @@ -63,8 +63,8 @@ type Viewpoint struct { } type ViewpointGroup struct { - Name string `json:"name,omitempty"` - Desc string `json:"desc,omitempty"` + Name string `json:"name"` + Desc string `json:"desc"` Labels []string `json:"labels,omitempty"` Tables []string `json:"tables,omitempty"` Color string `json:"color,omitempty"` @@ -92,7 +92,7 @@ type Index struct { Def string `json:"def"` Table *string `json:"table"` Columns []string `json:"columns"` - Comment string `json:"comment"` + Comment string `json:"comment,omitempty"` } // Constraint is the struct for database constraint @@ -104,14 +104,14 @@ type Constraint struct { ReferencedTable *string `json:"referenced_table" yaml:"referencedTable"` Columns []string `json:"columns"` ReferencedColumns []string `json:"referenced_columns" yaml:"referencedColumns"` - Comment string `json:"comment"` + Comment string `json:"comment,omitempty"` } // Trigger is the struct for database trigger type Trigger struct { Name string `json:"name"` Def string `json:"def"` - Comment string `json:"comment"` + Comment string `json:"comment,omitempty"` } // Column is the struct for table column @@ -119,8 +119,8 @@ type Column struct { Name string `json:"name"` Type string `json:"type"` Nullable bool `json:"nullable"` - Default sql.NullString `json:"default"` - Comment string `json:"comment"` + Default sql.NullString `json:"default,omitempty"` + Comment string `json:"comment,omitempty"` ExtraDef string `json:"extra_def,omitempty" yaml:"extraDef,omitempty"` Occurrences sql.NullInt32 `json:"occurrences,omitempty" yaml:"occurrences,omitempty"` Percents sql.NullFloat64 `json:"percents,omitempty" yaml:"percents,omitempty"` @@ -142,13 +142,13 @@ type TableViewpoint struct { type Table struct { Name string `json:"name"` Type string `json:"type"` - Comment string `json:"comment"` + Comment string `json:"comment,omitempty"` Columns []*Column `json:"columns"` - Viewpoints []*TableViewpoint `json:"viewpoints"` - Indexes []*Index `json:"indexes"` - Constraints []*Constraint `json:"constraints"` - Triggers []*Trigger `json:"triggers"` - Def string `json:"def"` + Viewpoints []*TableViewpoint `json:"viewpoints,omitempty"` + Indexes []*Index `json:"indexes,omitempty"` + Constraints []*Constraint `json:"constraints,omitempty"` + Triggers []*Trigger `json:"triggers,omitempty"` + Def string `json:"def,omitempty"` Labels Labels `json:"labels,omitempty"` ReferencedTables []*Table `json:"referenced_tables,omitempty" yaml:"referencedTables,omitempty"` External bool `json:"-"` // Table external to the schema @@ -160,10 +160,10 @@ type Relation struct { Columns []*Column `json:"columns"` ParentTable *Table `json:"parent_table" yaml:"parentTable"` ParentColumns []*Column `json:"parent_columns" yaml:"parentColumns"` - Cardinality Cardinality `json:"cardinality"` - ParentCardinality Cardinality `json:"parent_cardinality" yaml:"parentCardinality"` + Cardinality Cardinality `json:"cardinality,omitempty"` + ParentCardinality Cardinality `json:"parent_cardinality,omitempty" yaml:"parentCardinality"` Def string `json:"def"` - Virtual bool `json:"virtual"` + Virtual bool `json:"virtual,omitempty"` HideForER bool `json:"-"` } @@ -189,19 +189,19 @@ type Enum struct { // Driver is the struct for tbls driver information type Driver struct { Name string `json:"name"` - DatabaseVersion string `json:"database_version" yaml:"databaseVersion"` - Meta *DriverMeta `json:"meta"` + DatabaseVersion string `json:"database_version,omitempty" yaml:"databaseVersion,omitempty"` + Meta *DriverMeta `json:"meta,omitempty"` } // Schema is the struct for database schema type Schema struct { - Name string `json:"name"` - Desc string `json:"desc"` + Name string `json:"name,omitempty"` + Desc string `json:"desc,omitempty"` Tables []*Table `json:"tables"` - Relations []*Relation `json:"relations"` - Functions []*Function `json:"functions"` + Relations []*Relation `json:"relations,omitempty"` + Functions []*Function `json:"functions,omitempty"` Enums []*Enum `json:"enums,omitempty"` - Driver *Driver `json:"driver"` + Driver *Driver `json:"driver,omitempty"` Labels Labels `json:"labels,omitempty"` Viewpoints Viewpoints `json:"viewpoints,omitempty"` } From 6d20ba81d0f3e8ba932cf16f5cf21bab159976ce Mon Sep 17 00:00:00 2001 From: k1LoW Date: Thu, 23 Jan 2025 23:36:47 +0900 Subject: [PATCH 02/13] fix: Set omitempty --- schema/json.go | 42 ++++++++--------- testdata/json_output_schema.golden | 9 ++-- testdata/modify_schema_.golden | 45 +++++++------------ .../modify_schema_mod_name_and_desc.golden | 45 +++++++------------ testdata/modify_schema_not_override.golden | 45 +++++++------------ testdata/modify_schema_override.golden | 45 +++++++------------ testdata/modify_schema_relations.golden | 45 +++++++------------ testdata/yaml_output_schema.golden | 5 --- 8 files changed, 99 insertions(+), 182 deletions(-) diff --git a/schema/json.go b/schema/json.go index e62f8854..05c875be 100644 --- a/schema/json.go +++ b/schema/json.go @@ -14,13 +14,13 @@ func (s Schema) MarshalJSON() ([]byte, error) { } return json.Marshal(&struct { - Name string `json:"name"` - Desc string `json:"desc"` + Name string `json:"name,omitempty"` + Desc string `json:"desc,omitempty"` Tables []*Table `json:"tables"` - Relations []*Relation `json:"relations"` - Functions []*Function `json:"functions"` + Relations []*Relation `json:"relations,omitempty"` + Functions []*Function `json:"functions,omitempty"` Enums []*Enum `json:"enums,omitempty"` - Driver *Driver `json:"driver"` + Driver *Driver `json:"driver,omitempty"` Labels Labels `json:"labels,omitempty"` Viewpoints []*Viewpoint `json:"viewpoints,omitempty"` }{ @@ -69,8 +69,8 @@ func (d Driver) MarshalJSON() ([]byte, error) { } return json.Marshal(&struct { Name string `json:"name"` - DatabaseVersion string `json:"database_version"` - Meta *DriverMeta `json:"meta"` + DatabaseVersion string `json:"database_version,omitempty"` + Meta *DriverMeta `json:"meta,omitempty"` }{ Name: d.Name, DatabaseVersion: d.DatabaseVersion, @@ -101,11 +101,11 @@ func (t Table) MarshalJSON() ([]byte, error) { return json.Marshal(&struct { Name string `json:"name"` Type string `json:"type"` - Comment string `json:"comment"` + Comment string `json:"comment,omitempty"` Columns []*Column `json:"columns"` - Indexes []*Index `json:"indexes"` - Constraints []*Constraint `json:"constraints"` - Triggers []*Trigger `json:"triggers"` + Indexes []*Index `json:"indexes,omitempty"` + Constraints []*Constraint `json:"constraints,omitempty"` + Triggers []*Trigger `json:"triggers,omitempty"` Def string `json:"def"` Labels Labels `json:"labels,omitempty"` ReferencedTables []string `json:"referenced_tables,omitempty"` @@ -208,12 +208,12 @@ func (t *Table) UnmarshalJSON(data []byte) error { s := struct { Name string `json:"name"` Type string `json:"type"` - Comment string `json:"comment"` + Comment string `json:"comment,omitempty"` Columns []*Column `json:"columns"` - Indexes []*Index `json:"indexes"` - Constraints []*Constraint `json:"constraints"` - Triggers []*Trigger `json:"triggers"` - Def string `json:"def"` + Indexes []*Index `json:"indexes,omitempty"` + Constraints []*Constraint `json:"constraints,omitempty"` + Triggers []*Trigger `json:"triggers,omitempty"` + Def string `json:"def,omitempty"` Labels Labels `json:"labels,omitempty"` ReferencedTables []string `json:"referenced_tables,omitempty"` }{} @@ -244,8 +244,8 @@ func (c *Column) UnmarshalJSON(data []byte) error { Name string `json:"name"` Type string `json:"type"` Nullable bool `json:"nullable"` - Default *string `json:"default"` - Comment string `json:"comment"` + Default *string `json:"default,omitempty"` + Comment string `json:"comment,omitempty"` ExtraDef string `json:"extra_def,omitempty"` Labels Labels `json:"labels,omitempty"` ParentRelations []*Relation `json:"-"` @@ -276,12 +276,12 @@ func (r *Relation) UnmarshalJSON(data []byte) error { s := struct { Table string `json:"table"` Columns []string `json:"columns"` - Cardinality string `json:"cardinality"` + Cardinality string `json:"cardinality,omitempty"` ParentTable string `json:"parent_table"` ParentColumns []string `json:"parent_columns"` - ParentCardinality string `json:"parent_cardinality"` + ParentCardinality string `json:"parent_cardinality,omitempty"` Def string `json:"def"` - Virtual bool `json:"virtual"` + Virtual bool `json:"virtual,omitempty"` }{} err := json.Unmarshal(data, &s) if err != nil { diff --git a/testdata/json_output_schema.golden b/testdata/json_output_schema.golden index 34ea9768..e1b323bd 100644 --- a/testdata/json_output_schema.golden +++ b/testdata/json_output_schema.golden @@ -29,8 +29,7 @@ "table": "a", "columns": [ "a" - ], - "comment": "" + ] } ], "constraints": [ @@ -41,15 +40,13 @@ "table": "a", "referenced_table": null, "columns": null, - "referenced_columns": null, - "comment": "" + "referenced_columns": null } ], "triggers": [ { "name": "update_a_a2", - "def": "CREATE CONSTRAINT TRIGGER update_a_a2 AFTER INSERT OR UPDATE ON a", - "comment": "" + "def": "CREATE CONSTRAINT TRIGGER update_a_a2 AFTER INSERT OR UPDATE ON a" } ], "def": "", diff --git a/testdata/modify_schema_.golden b/testdata/modify_schema_.golden index 5f8115fe..472b60f9 100644 --- a/testdata/modify_schema_.golden +++ b/testdata/modify_schema_.golden @@ -29,8 +29,7 @@ "table": "users", "columns": [ "username" - ], - "comment": "" + ] } ], "constraints": [ @@ -43,8 +42,7 @@ "columns": [ "id" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null }, { "name": "sqlite_autoindex_users_1", @@ -55,8 +53,7 @@ "columns": [ "username" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null }, { "name": "-", @@ -67,8 +64,7 @@ "columns": [ "username" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null } ], "triggers": [], @@ -107,8 +103,7 @@ "table": "categories", "columns": [ "name" - ], - "comment": "" + ] } ], "constraints": [ @@ -121,8 +116,7 @@ "columns": [ "id" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null }, { "name": "sqlite_autoindex_categories_1", @@ -133,8 +127,7 @@ "columns": [ "name" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null } ], "triggers": [], @@ -191,8 +184,7 @@ "table": "posts", "columns": [ "user_id" - ], - "comment": "" + ] } ], "constraints": [ @@ -205,8 +197,7 @@ "columns": [ "id" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null }, { "name": "- (Foreign key ID: 0)", @@ -219,8 +210,7 @@ ], "referenced_columns": [ "id" - ], - "comment": "" + ] }, { "name": "- (Foreign key ID: 1)", @@ -233,15 +223,13 @@ ], "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 TRIGGER update_posts_updated AFTER UPDATE ON posts FOR EACH ROW\nBEGIN\n UPDATE posts SET updated = current_timestamp WHERE id = OLD.id;\nEND" } ], "def": "CREATE TABLE posts (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n user_id INTEGER NOT NULL,\n category_id INTEGER NOT NULL,\n title TEXT NOT NULL,\n CONSTRAINT posts_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE,\n CONSTRAINT posts_category_id_fk FOREIGN KEY(category_id) REFERENCES categories(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE\n)", @@ -290,8 +278,7 @@ "columns": [ "id" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null }, { "name": "- (Foreign key ID: 0)", @@ -304,8 +291,7 @@ ], "referenced_columns": [ "id" - ], - "comment": "" + ] } ], "triggers": [], @@ -352,8 +338,7 @@ "columns": [ "id" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null } ], "triggers": [], diff --git a/testdata/modify_schema_mod_name_and_desc.golden b/testdata/modify_schema_mod_name_and_desc.golden index 593bb419..8a7cf498 100644 --- a/testdata/modify_schema_mod_name_and_desc.golden +++ b/testdata/modify_schema_mod_name_and_desc.golden @@ -29,8 +29,7 @@ "table": "users", "columns": [ "username" - ], - "comment": "" + ] } ], "constraints": [ @@ -43,8 +42,7 @@ "columns": [ "id" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null }, { "name": "sqlite_autoindex_users_1", @@ -55,8 +53,7 @@ "columns": [ "username" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null }, { "name": "-", @@ -67,8 +64,7 @@ "columns": [ "username" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null } ], "triggers": [], @@ -107,8 +103,7 @@ "table": "categories", "columns": [ "name" - ], - "comment": "" + ] } ], "constraints": [ @@ -121,8 +116,7 @@ "columns": [ "id" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null }, { "name": "sqlite_autoindex_categories_1", @@ -133,8 +127,7 @@ "columns": [ "name" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null } ], "triggers": [], @@ -191,8 +184,7 @@ "table": "posts", "columns": [ "user_id" - ], - "comment": "" + ] } ], "constraints": [ @@ -205,8 +197,7 @@ "columns": [ "id" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null }, { "name": "- (Foreign key ID: 0)", @@ -219,8 +210,7 @@ ], "referenced_columns": [ "id" - ], - "comment": "" + ] }, { "name": "- (Foreign key ID: 1)", @@ -233,15 +223,13 @@ ], "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 TRIGGER update_posts_updated AFTER UPDATE ON posts FOR EACH ROW\nBEGIN\n UPDATE posts SET updated = current_timestamp WHERE id = OLD.id;\nEND" } ], "def": "CREATE TABLE posts (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n user_id INTEGER NOT NULL,\n category_id INTEGER NOT NULL,\n title TEXT NOT NULL,\n CONSTRAINT posts_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE,\n CONSTRAINT posts_category_id_fk FOREIGN KEY(category_id) REFERENCES categories(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE\n)", @@ -290,8 +278,7 @@ "columns": [ "id" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null }, { "name": "- (Foreign key ID: 0)", @@ -304,8 +291,7 @@ ], "referenced_columns": [ "id" - ], - "comment": "" + ] } ], "triggers": [], @@ -352,8 +338,7 @@ "columns": [ "id" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null } ], "triggers": [], diff --git a/testdata/modify_schema_not_override.golden b/testdata/modify_schema_not_override.golden index 969af534..bc9a74d6 100644 --- a/testdata/modify_schema_not_override.golden +++ b/testdata/modify_schema_not_override.golden @@ -29,8 +29,7 @@ "table": "users", "columns": [ "username" - ], - "comment": "" + ] } ], "constraints": [ @@ -43,8 +42,7 @@ "columns": [ "id" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null }, { "name": "sqlite_autoindex_users_1", @@ -55,8 +53,7 @@ "columns": [ "username" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null }, { "name": "-", @@ -67,8 +64,7 @@ "columns": [ "username" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null } ], "triggers": [], @@ -107,8 +103,7 @@ "table": "categories", "columns": [ "name" - ], - "comment": "" + ] } ], "constraints": [ @@ -121,8 +116,7 @@ "columns": [ "id" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null }, { "name": "sqlite_autoindex_categories_1", @@ -133,8 +127,7 @@ "columns": [ "name" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null } ], "triggers": [], @@ -191,8 +184,7 @@ "table": "posts", "columns": [ "user_id" - ], - "comment": "" + ] } ], "constraints": [ @@ -205,8 +197,7 @@ "columns": [ "id" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null }, { "name": "- (Foreign key ID: 0)", @@ -219,8 +210,7 @@ ], "referenced_columns": [ "id" - ], - "comment": "" + ] }, { "name": "- (Foreign key ID: 1)", @@ -233,15 +223,13 @@ ], "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 TRIGGER update_posts_updated AFTER UPDATE ON posts FOR EACH ROW\nBEGIN\n UPDATE posts SET updated = current_timestamp WHERE id = OLD.id;\nEND" } ], "def": "CREATE TABLE posts (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n user_id INTEGER NOT NULL,\n category_id INTEGER NOT NULL,\n title TEXT NOT NULL,\n CONSTRAINT posts_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE,\n CONSTRAINT posts_category_id_fk FOREIGN KEY(category_id) REFERENCES categories(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE\n)", @@ -290,8 +278,7 @@ "columns": [ "id" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null }, { "name": "- (Foreign key ID: 0)", @@ -304,8 +291,7 @@ ], "referenced_columns": [ "id" - ], - "comment": "" + ] } ], "triggers": [], @@ -352,8 +338,7 @@ "columns": [ "id" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null } ], "triggers": [], diff --git a/testdata/modify_schema_override.golden b/testdata/modify_schema_override.golden index 81be5cea..216fdd2d 100644 --- a/testdata/modify_schema_override.golden +++ b/testdata/modify_schema_override.golden @@ -29,8 +29,7 @@ "table": "users", "columns": [ "username" - ], - "comment": "" + ] } ], "constraints": [ @@ -43,8 +42,7 @@ "columns": [ "id" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null }, { "name": "sqlite_autoindex_users_1", @@ -55,8 +53,7 @@ "columns": [ "username" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null }, { "name": "-", @@ -67,8 +64,7 @@ "columns": [ "username" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null } ], "triggers": [], @@ -107,8 +103,7 @@ "table": "categories", "columns": [ "name" - ], - "comment": "" + ] } ], "constraints": [ @@ -121,8 +116,7 @@ "columns": [ "id" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null }, { "name": "sqlite_autoindex_categories_1", @@ -133,8 +127,7 @@ "columns": [ "name" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null } ], "triggers": [], @@ -191,8 +184,7 @@ "table": "posts", "columns": [ "user_id" - ], - "comment": "" + ] } ], "constraints": [ @@ -205,8 +197,7 @@ "columns": [ "id" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null }, { "name": "- (Foreign key ID: 0)", @@ -219,8 +210,7 @@ ], "referenced_columns": [ "id" - ], - "comment": "" + ] }, { "name": "- (Foreign key ID: 1)", @@ -233,15 +223,13 @@ ], "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 TRIGGER update_posts_updated AFTER UPDATE ON posts FOR EACH ROW\nBEGIN\n UPDATE posts SET updated = current_timestamp WHERE id = OLD.id;\nEND" } ], "def": "CREATE TABLE posts (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n user_id INTEGER NOT NULL,\n category_id INTEGER NOT NULL,\n title TEXT NOT NULL,\n CONSTRAINT posts_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE,\n CONSTRAINT posts_category_id_fk FOREIGN KEY(category_id) REFERENCES categories(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE\n)", @@ -290,8 +278,7 @@ "columns": [ "id" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null }, { "name": "- (Foreign key ID: 0)", @@ -304,8 +291,7 @@ ], "referenced_columns": [ "id" - ], - "comment": "" + ] } ], "triggers": [], @@ -352,8 +338,7 @@ "columns": [ "id" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null } ], "triggers": [], diff --git a/testdata/modify_schema_relations.golden b/testdata/modify_schema_relations.golden index ff057712..c0f20d58 100644 --- a/testdata/modify_schema_relations.golden +++ b/testdata/modify_schema_relations.golden @@ -29,8 +29,7 @@ "table": "users", "columns": [ "username" - ], - "comment": "" + ] } ], "constraints": [ @@ -43,8 +42,7 @@ "columns": [ "id" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null }, { "name": "sqlite_autoindex_users_1", @@ -55,8 +53,7 @@ "columns": [ "username" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null }, { "name": "-", @@ -67,8 +64,7 @@ "columns": [ "username" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null } ], "triggers": [], @@ -107,8 +103,7 @@ "table": "categories", "columns": [ "name" - ], - "comment": "" + ] } ], "constraints": [ @@ -121,8 +116,7 @@ "columns": [ "id" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null }, { "name": "sqlite_autoindex_categories_1", @@ -133,8 +127,7 @@ "columns": [ "name" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null } ], "triggers": [], @@ -191,8 +184,7 @@ "table": "posts", "columns": [ "user_id" - ], - "comment": "" + ] } ], "constraints": [ @@ -205,8 +197,7 @@ "columns": [ "id" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null }, { "name": "- (Foreign key ID: 0)", @@ -219,8 +210,7 @@ ], "referenced_columns": [ "id" - ], - "comment": "" + ] }, { "name": "- (Foreign key ID: 1)", @@ -233,15 +223,13 @@ ], "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 TRIGGER update_posts_updated AFTER UPDATE ON posts FOR EACH ROW\nBEGIN\n UPDATE posts SET updated = current_timestamp WHERE id = OLD.id;\nEND" } ], "def": "CREATE TABLE posts (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n user_id INTEGER NOT NULL,\n category_id INTEGER NOT NULL,\n title TEXT NOT NULL,\n CONSTRAINT posts_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE,\n CONSTRAINT posts_category_id_fk FOREIGN KEY(category_id) REFERENCES categories(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE\n)", @@ -290,8 +278,7 @@ "columns": [ "id" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null }, { "name": "- (Foreign key ID: 0)", @@ -304,8 +291,7 @@ ], "referenced_columns": [ "id" - ], - "comment": "" + ] } ], "triggers": [], @@ -352,8 +338,7 @@ "columns": [ "id" ], - "referenced_columns": null, - "comment": "" + "referenced_columns": null } ], "triggers": [], diff --git a/testdata/yaml_output_schema.golden b/testdata/yaml_output_schema.golden index e976bb8e..09ffd6de 100644 --- a/testdata/yaml_output_schema.golden +++ b/testdata/yaml_output_schema.golden @@ -1,5 +1,4 @@ name: testschema -desc: "" tables: - name: a type: "" @@ -21,7 +20,6 @@ tables: table: a columns: - a - comment: "" constraints: - name: PRIMARY type: "" @@ -30,11 +28,9 @@ tables: referencedTable: null columns: [] referencedColumns: [] - comment: "" triggers: - name: update_a_a2 def: CREATE CONSTRAINT TRIGGER update_a_a2 AFTER INSERT OR UPDATE ON a - comment: "" def: "" labels: - name: blue @@ -91,7 +87,6 @@ relations: parentCardinality: Exactly one def: FOREIGN KEY (b) REFERENCES a(a) virtual: false -functions: [] enums: - name: enum values: From 19fcc82907780752921fc9bda6cf3c86b745033e Mon Sep 17 00:00:00 2001 From: k1LoW Date: Fri, 24 Jan 2025 00:13:50 +0900 Subject: [PATCH 03/13] fix: Update depsdev --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 0515c476..34ff0b5a 100644 --- a/Makefile +++ b/Makefile @@ -158,9 +158,9 @@ build: go build -tags timetzdata -ldflags="$(BUILD_LDFLAGS)" depsdev: - go install github.com/linyows/git-semv/cmd/git-semv@v1.2.0 - go install github.com/Songmu/ghch/cmd/ghch@v0.10.2 - go install github.com/xo/usql@v0.9.5 + go install github.com/linyows/git-semv/cmd/git-semv@latest + go install github.com/Songmu/ghch/cmd/ghch@latest + go install github.com/xo/usql@latest go install github.com/Songmu/gocredits/cmd/gocredits@latest go install github.com/securego/gosec/v2/cmd/gosec@latest From cdc4e24a1ad10fc72fcc74a101fdafdd4e897ac2 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Fri, 24 Jan 2025 00:14:22 +0900 Subject: [PATCH 04/13] fix: Set omitempty --- sample/adjust/README.md | 2 +- sample/adjust/schema.json | 2 +- sample/clickhouse/schema.json | 2 +- sample/detect_relations/schema.json | 2 +- sample/detect_relations_singular/schema.json | 2 +- sample/dict/schema.json | 2 +- sample/dynamodb/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/schema.json | 2 +- sample/mongo/schema.json | 2 +- sample/mssql/schema.json | 2 +- sample/mysql/schema.json | 2 +- sample/mysql56/schema.json | 2 +- sample/number/schema.json | 2 +- sample/png/schema.json | 2 +- sample/postgres/README.md | 2 +- sample/postgres/schema.json | 2 +- sample/postgres95/schema.json | 2 +- sample/sqlite/schema.json | 2 +- sample/viewpoints/schema.json | 2 +- schema/json.go | 68 ++----------- schema/schema.go | 4 +- schema/yaml.go | 42 ++++---- testdata/json_output_schema.golden | 19 +--- testdata/modify_schema_.golden | 97 ++++--------------- .../modify_schema_mod_name_and_desc.golden | 96 ++++-------------- testdata/modify_schema_not_override.golden | 97 ++++--------------- testdata/modify_schema_override.golden | 97 ++++--------------- testdata/modify_schema_relations.golden | 97 ++++--------------- testdata/yaml_output_schema.golden | 15 --- 34 files changed, 160 insertions(+), 520 deletions(-) diff --git a/sample/adjust/README.md b/sample/adjust/README.md index 699dc4b1..b599b32d 100644 --- a/sample/adjust/README.md +++ b/sample/adjust/README.md @@ -36,6 +36,7 @@ Sample PostgreSQL database document. | Name | ReturnType | Arguments | Type | | ------------------------- | ---------- | ------------------------- | --------- | +| public.reset_comment | void | IN comment_id integer | PROCEDURE | | public.uuid_nil | uuid | | FUNCTION | | public.uuid_ns_dns | uuid | | FUNCTION | | public.uuid_ns_url | uuid | | FUNCTION | @@ -47,7 +48,6 @@ Sample PostgreSQL database document. | public.uuid_generate_v4 | uuid | | FUNCTION | | public.uuid_generate_v5 | uuid | namespace uuid, name text | FUNCTION | | public.update_updated | trigger | | FUNCTION | -| public.reset_comment | void | IN comment_id integer | PROCEDURE | ## Enums diff --git a/sample/adjust/schema.json b/sample/adjust/schema.json index e6549018..1339f542 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":["user_id","title"],"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":["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":"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"}],"enums":[{"name":"public.post_types","values":["draft","private","public"]}],"driver":{"name":"postgres","database_version":"PostgreSQL 15.10 (Debian 15.10-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit","meta":{"current_schema":"public","search_paths":["postgres","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}},"viewpoints":[{"name":"post","desc":"for post","tables":["public.post*"]},{"name":"administrator","desc":"administrator schema only","tables":["administrator.*"]}]} +{"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},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"users_pkey","def":"CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)","table":"public.users","columns":["id"]},{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)","table":"public.users","columns":["username"]},{"name":"users_email_key","def":"CREATE UNIQUE INDEX users_email_key ON public.users USING btree (email)","table":"public.users","columns":["email"]}],"constraints":[{"name":"users_username_check","type":"CHECK","def":"CHECK ((char_length((username)::text) \u003e 4))","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.users","referenced_table":"","columns":["id"]},{"name":"users_username_key","type":"UNIQUE","def":"UNIQUE (username)","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_email_key","type":"UNIQUE","def":"UNIQUE (email)","table":"public.users","referenced_table":"","columns":["email"]}],"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"}]},{"name":"public.user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"integer","nullable":false},{"name":"show_email","type":"boolean","nullable":false,"default":"false","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}]},{"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},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'::character varying","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"post_types","nullable":false,"comment":"public/private/draft"},{"name":"labels","type":"varchar(50)[]","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CREATE UNIQUE INDEX posts_id_pk ON public.posts USING btree (id)","table":"public.posts","columns":["id"]},{"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":["user_id","title"]},{"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"]},{"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"]},{"name":"posts_user_id_title_key","type":"UNIQUE","def":"UNIQUE (user_id, title)","table":"public.posts","referenced_table":"","columns":["user_id","title"]}],"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"}]},{"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},{"name":"user_id","type":"integer","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (post_id * '-1'::integer) STORED"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CREATE UNIQUE INDEX comments_id_pk ON public.comments USING btree (id)","table":"public.comments","columns":["id"]},{"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"]},{"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"]}],"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"]},{"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"]},{"name":"comments_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.comments","referenced_table":"","columns":["id"]},{"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"]}]},{"name":"public.comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"user_id","type":"integer","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"integer","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","table":"public.comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id)","table":"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"]},{"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"]}]},{"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},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"uuid","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false}]},{"name":"public.post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"timestamp without time zone","nullable":true,"comment":"comments.created"},{"name":"updated","type":"timestamp without time zone","nullable":true,"comment":"comments.updated"}],"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","columns":[{"name":"id","type":"uuid","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"comment_star_user","type":"varchar(50)","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false}],"indexes":[{"name":"CamelizeTable_id_key","def":"CREATE UNIQUE INDEX \"CamelizeTable_id_key\" ON public.\"CamelizeTable\" USING btree (id)","table":"public.CamelizeTable","columns":["id"]}],"constraints":[{"name":"CamelizeTable_id_key","type":"UNIQUE","def":"UNIQUE (id)","table":"public.CamelizeTable","referenced_table":"","columns":["id"]}]},{"name":"public.hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"hyphen-column","type":"text","nullable":false},{"name":"CamelizeTableId","type":"uuid","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false}],"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"]}],"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"]},{"name":"hyphen-table_hyphen-column_key","type":"UNIQUE","def":"UNIQUE (\"hyphen-column\")","table":"public.hyphen-table","referenced_table":"","columns":["hyphen-column"]}]},{"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},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON administrator.blogs USING btree (id)","table":"administrator.blogs","columns":["id"]}],"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"]},{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"administrator.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blogs","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blogs_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false},{"name":"dump","type":"text","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON backup.blogs USING btree (id)","table":"backup.blogs","columns":["id"]}],"constraints":[{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blog_options","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blog_options_id_seq'::regclass)","comment":""},{"name":"blog_id","type":"integer","nullable":false},{"name":"label","type":"text","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}],"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"]},{"name":"blog_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blog_options","referenced_table":"","columns":["id"]}]},{"name":"time.bar","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"indexes":[{"name":"bar_pkey","def":"CREATE UNIQUE INDEX bar_pkey ON \"time\".bar USING btree (id)","table":"time.bar","columns":["id"]}],"constraints":[{"name":"bar_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.bar","referenced_table":"","columns":["id"]}]},{"name":"time.hyphenated-table","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"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"]}],"constraints":[{"name":"hyphenated-table_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.hyphenated-table","referenced_table":"","columns":["id"]}]},{"name":"time.referencing","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false},{"name":"bar_id","type":"integer","nullable":false},{"name":"ht_id","type":"integer","nullable":false}],"indexes":[{"name":"referencing_pkey","def":"CREATE UNIQUE INDEX referencing_pkey ON \"time\".referencing USING btree (id)","table":"time.referencing","columns":["id"]}],"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"]},{"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"]},{"name":"referencing_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.referencing","referenced_table":"","columns":["id"]}]}],"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.reset_comment","return_type":"void","arguments":"IN comment_id integer","type":"PROCEDURE"},{"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"}],"enums":[{"name":"public.post_types","values":["draft","private","public"]}],"driver":{"name":"postgres","database_version":"PostgreSQL 15.10 (Debian 15.10-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit","meta":{"current_schema":"public","search_paths":["postgres","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}},"viewpoints":[{"name":"post","desc":"for post","tables":["public.post*"]},{"name":"administrator","desc":"administrator schema only","tables":["administrator.*"]}]} diff --git a/sample/clickhouse/schema.json b/sample/clickhouse/schema.json index 3f9307a2..1860ea3f 100644 --- a/sample/clickhouse/schema.json +++ b/sample/clickhouse/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"","tables":[{"name":"id_value_dictionary","type":"Dictionary","comment":"","columns":[{"name":"id","type":"UInt64","nullable":false,"default":null,"comment":""},{"name":"value","type":"String","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":"CREATE DICTIONARY testdb.id_value_dictionary (`id` UInt64, `value` String) PRIMARY KEY id SOURCE(CLICKHOUSE(TABLE 'source_table')) LIFETIME(MIN 0 MAX 1000) LAYOUT(FLAT())"},{"name":"materialized_view","type":"MaterializedView","comment":"","columns":[{"name":"name1","type":"UInt64","nullable":false,"default":null,"comment":""},{"name":"name2","type":"Nullable(String)","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":"CREATE MATERIALIZED VIEW testdb.materialized_view (`name1` UInt64, `name2` Nullable(String)) ENGINE = Memory AS SELECT name1, name2 FROM testdb.table_name ORDER BY name1 DESC","referenced_tables":["table_name"]},{"name":"numbers_table","type":"SystemNumbers","comment":"","columns":[{"name":"number","type":"UInt64","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":"CREATE TABLE testdb.numbers_table (`number` UInt64) AS numbers(100)"},{"name":"source_table","type":"MergeTree","comment":"","columns":[{"name":"id","type":"UInt64","nullable":false,"default":null,"comment":""},{"name":"value","type":"String","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[{"name":"sorting key","type":"SORTING KEY","def":"ORDER BY (id)","table":"source_table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""},{"name":"primary key","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"source_table","referenced_table":null,"columns":["id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE testdb.source_table (`id` UInt64, `value` String) ENGINE = MergeTree PRIMARY KEY id ORDER BY id SETTINGS index_granularity = 8192"},{"name":"t1","type":"Memory","comment":"","columns":[{"name":"x","type":"String","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":"CREATE TABLE testdb.t1 (`x` String) ENGINE = Memory"},{"name":"table_name","type":"MergeTree","comment":"comment for table","columns":[{"name":"name1","type":"UInt64","nullable":false,"default":null,"comment":"comment for column 1"},{"name":"name2","type":"Nullable(String)","nullable":false,"default":"DEFAULT 'column 2'","comment":"comment for column 2"},{"name":"name3","type":"LowCardinality(String)","nullable":false,"default":"MATERIALIZED upper(name2)","comment":"comment for column 3"},{"name":"name4","type":"SimpleAggregateFunction(sum, Float64)","nullable":false,"default":null,"comment":""},{"name":"name5","type":"DateTime","nullable":false,"default":"DEFAULT now()","comment":""},{"name":"name6","type":"String","nullable":false,"default":"ALIAS formatReadableSize(name1)","comment":""},{"name":"name7","type":"String","nullable":false,"default":"MATERIALIZED hex(name1)","comment":""},{"name":"name8","type":"FixedString(4)","nullable":false,"default":"DEFAULT unhex(name7)","comment":""}],"indexes":[{"name":"idx1","def":"bloom_filter(0.01)","table":"table_name","columns":["name1"],"comment":""},{"name":"idx2","def":"minmax","table":"table_name","columns":["name1 * 2"],"comment":""},{"name":"idx3","def":"set(1000)","table":"table_name","columns":["name1 * length(name2)"],"comment":""}],"constraints":[{"name":"partition key","type":"PARTITION KEY","def":"PARTITION BY ((name1, name3, name5))","table":"table_name","referenced_table":null,"columns":["name1","name3","name5"],"referenced_columns":null,"comment":""},{"name":"sorting key","type":"SORTING KEY","def":"ORDER BY (name1, name5)","table":"table_name","referenced_table":null,"columns":["name1","name5"],"referenced_columns":null,"comment":""},{"name":"primary key","type":"PRIMARY KEY","def":"PRIMARY KEY (name1, name5)","table":"table_name","referenced_table":null,"columns":["name1","name5"],"referenced_columns":null,"comment":""},{"name":"sampling key","type":"SAMPLING KEY","def":"SAMPLE BY (name1)","table":"table_name","referenced_table":null,"columns":["name1"],"referenced_columns":null,"comment":""}],"triggers":[],"def":"CREATE TABLE testdb.table_name (`name1` UInt64 COMMENT 'comment for column 1', `name2` Nullable(String) DEFAULT 'column 2' COMMENT 'comment for column 2' CODEC(ZSTD(1)), `name3` LowCardinality(String) MATERIALIZED upper(name2) COMMENT 'comment for column 3', `name4` SimpleAggregateFunction(sum, Float64) TTL name5 + toIntervalDay(1), `name5` DateTime DEFAULT now(), `name6` String ALIAS formatReadableSize(name1), `name7` String MATERIALIZED hex(name1), `name8` FixedString(4) DEFAULT unhex(name7), INDEX idx1 name1 TYPE bloom_filter(0.01) GRANULARITY 1, INDEX idx2 name1 * 2 TYPE minmax GRANULARITY 3, INDEX idx3 name1 * length(name2) TYPE set(1000) GRANULARITY 4, PROJECTION projection_name_1 (SELECT name1, name2, name3 ORDER BY name1)) ENGINE = MergeTree PARTITION BY (name1, name3, name5) PRIMARY KEY (name1, name5) ORDER BY (name1, name5) SAMPLE BY name1 SETTINGS index_granularity = 8192 COMMENT 'comment for table'"},{"name":"view","type":"View","comment":"","columns":[{"name":"name1","type":"UInt64","nullable":false,"default":null,"comment":""},{"name":"name2","type":"Nullable(String)","nullable":false,"default":null,"comment":""},{"name":"name4","type":"SimpleAggregateFunction(sum, Float64)","nullable":false,"default":null,"comment":""},{"name":"name5","type":"DateTime","nullable":false,"default":null,"comment":""},{"name":"name8","type":"FixedString(4)","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[],"triggers":[],"def":"CREATE VIEW testdb.view (`name1` UInt64, `name2` Nullable(String), `name4` SimpleAggregateFunction(sum, Float64), `name5` DateTime, `name8` FixedString(4)) AS SELECT * FROM testdb.table_name"}],"relations":[],"functions":[{"name":"linear_equation","return_type":"","arguments":"","type":""}],"driver":{"name":"clickhouse","database_version":"24.4.4.85","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} +{"name":"testdb","tables":[{"name":"id_value_dictionary","type":"Dictionary","columns":[{"name":"id","type":"UInt64","nullable":false},{"name":"value","type":"String","nullable":false}],"def":"CREATE DICTIONARY testdb.id_value_dictionary (`id` UInt64, `value` String) PRIMARY KEY id SOURCE(CLICKHOUSE(TABLE 'source_table')) LIFETIME(MIN 0 MAX 1000) LAYOUT(FLAT())"},{"name":"materialized_view","type":"MaterializedView","columns":[{"name":"name1","type":"UInt64","nullable":false},{"name":"name2","type":"Nullable(String)","nullable":false}],"def":"CREATE MATERIALIZED VIEW testdb.materialized_view (`name1` UInt64, `name2` Nullable(String)) ENGINE = Memory AS SELECT name1, name2 FROM testdb.table_name ORDER BY name1 DESC","referenced_tables":["table_name"]},{"name":"numbers_table","type":"SystemNumbers","columns":[{"name":"number","type":"UInt64","nullable":false}],"def":"CREATE TABLE testdb.numbers_table (`number` UInt64) AS numbers(100)"},{"name":"source_table","type":"MergeTree","columns":[{"name":"id","type":"UInt64","nullable":false},{"name":"value","type":"String","nullable":false}],"constraints":[{"name":"sorting key","type":"SORTING KEY","def":"ORDER BY (id)","table":"source_table","columns":["id"]},{"name":"primary key","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"source_table","columns":["id"]}],"def":"CREATE TABLE testdb.source_table (`id` UInt64, `value` String) ENGINE = MergeTree PRIMARY KEY id ORDER BY id SETTINGS index_granularity = 8192"},{"name":"t1","type":"Memory","columns":[{"name":"x","type":"String","nullable":false}],"def":"CREATE TABLE testdb.t1 (`x` String) ENGINE = Memory"},{"name":"table_name","type":"MergeTree","comment":"comment for table","columns":[{"name":"name1","type":"UInt64","nullable":false,"comment":"comment for column 1"},{"name":"name2","type":"Nullable(String)","nullable":false,"default":"DEFAULT 'column 2'","comment":"comment for column 2"},{"name":"name3","type":"LowCardinality(String)","nullable":false,"default":"MATERIALIZED upper(name2)","comment":"comment for column 3"},{"name":"name4","type":"SimpleAggregateFunction(sum, Float64)","nullable":false},{"name":"name5","type":"DateTime","nullable":false,"default":"DEFAULT now()","comment":""},{"name":"name6","type":"String","nullable":false,"default":"ALIAS formatReadableSize(name1)","comment":""},{"name":"name7","type":"String","nullable":false,"default":"MATERIALIZED hex(name1)","comment":""},{"name":"name8","type":"FixedString(4)","nullable":false,"default":"DEFAULT unhex(name7)","comment":""}],"indexes":[{"name":"idx1","def":"bloom_filter(0.01)","table":"table_name","columns":["name1"]},{"name":"idx2","def":"minmax","table":"table_name","columns":["name1 * 2"]},{"name":"idx3","def":"set(1000)","table":"table_name","columns":["name1 * length(name2)"]}],"constraints":[{"name":"partition key","type":"PARTITION KEY","def":"PARTITION BY ((name1, name3, name5))","table":"table_name","columns":["name1","name3","name5"]},{"name":"sorting key","type":"SORTING KEY","def":"ORDER BY (name1, name5)","table":"table_name","columns":["name1","name5"]},{"name":"primary key","type":"PRIMARY KEY","def":"PRIMARY KEY (name1, name5)","table":"table_name","columns":["name1","name5"]},{"name":"sampling key","type":"SAMPLING KEY","def":"SAMPLE BY (name1)","table":"table_name","columns":["name1"]}],"def":"CREATE TABLE testdb.table_name (`name1` UInt64 COMMENT 'comment for column 1', `name2` Nullable(String) DEFAULT 'column 2' COMMENT 'comment for column 2' CODEC(ZSTD(1)), `name3` LowCardinality(String) MATERIALIZED upper(name2) COMMENT 'comment for column 3', `name4` SimpleAggregateFunction(sum, Float64) TTL name5 + toIntervalDay(1), `name5` DateTime DEFAULT now(), `name6` String ALIAS formatReadableSize(name1), `name7` String MATERIALIZED hex(name1), `name8` FixedString(4) DEFAULT unhex(name7), INDEX idx1 name1 TYPE bloom_filter(0.01) GRANULARITY 1, INDEX idx2 name1 * 2 TYPE minmax GRANULARITY 3, INDEX idx3 name1 * length(name2) TYPE set(1000) GRANULARITY 4, PROJECTION projection_name_1 (SELECT name1, name2, name3 ORDER BY name1)) ENGINE = MergeTree PARTITION BY (name1, name3, name5) PRIMARY KEY (name1, name5) ORDER BY (name1, name5) SAMPLE BY name1 SETTINGS index_granularity = 8192 COMMENT 'comment for table'"},{"name":"view","type":"View","columns":[{"name":"name1","type":"UInt64","nullable":false},{"name":"name2","type":"Nullable(String)","nullable":false},{"name":"name4","type":"SimpleAggregateFunction(sum, Float64)","nullable":false},{"name":"name5","type":"DateTime","nullable":false},{"name":"name8","type":"FixedString(4)","nullable":false}],"def":"CREATE VIEW testdb.view (`name1` UInt64, `name2` Nullable(String), `name4` SimpleAggregateFunction(sum, Float64), `name5` DateTime, `name8` FixedString(4)) AS SELECT * FROM testdb.table_name"}],"functions":[{"name":"linear_equation","return_type":"","arguments":"","type":""}],"driver":{"name":"clickhouse","database_version":"24.4.4.113","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} diff --git a/sample/detect_relations/schema.json b/sample/detect_relations/schema.json index b89cf0e4..79599b81 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.4.3","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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"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,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`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,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL,\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},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]}],"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.4.4","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 15dbdc49..47b71f04 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.4.3","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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment","type":"BASE TABLE","comment":"Comment\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"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"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comment","columns":["post_id","user_id"]}],"constraints":[{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comment","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment","columns":["id"]}],"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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_star","columns":["id"]},{"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"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_star","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_star","columns":["user_id","comment_post_id","comment_user_id"]}],"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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"log","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"log","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"log","columns":["id"]}],"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,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"post_user_id_idx","def":"KEY post_user_id_idx (id) USING BTREE","table":"post","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"post","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"post","columns":["user_id","title"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"post","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"post","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON post\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"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,"comment":"post.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"post.user.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comment.user.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comment.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comment.updated"}],"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,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"user","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"user","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"user","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"user","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"user","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"user","columns":["username"]}],"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},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_option","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_option","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_option","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_option","columns":["user_id"]},{"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"]}],"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.4.4","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 36ecf78f..cb1687d6 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.4.0","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} +{"name":"testdb","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"VIEW","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"post_user","type":"varchar(50)","nullable":true},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"created","type":"datetime","nullable":true},{"name":"updated","type":"datetime","nullable":true}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'"},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} diff --git a/sample/dynamodb/schema.json b/sample/dynamodb/schema.json index eded7859..09206c41 100644 --- a/sample/dynamodb/schema.json +++ b/sample/dynamodb/schema.json @@ -1 +1 @@ -{"name":"Amazon DynamoDB (ap-northeast-1)","desc":"","tables":[{"name":"Forum","type":"BASIC TABLE","comment":"","columns":[{"name":"Name","type":"S","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[{"name":"Primary Key","type":"Partition key","def":"[{ AttributeName: \"Name\", KeyType: \"HASH\" }]","table":null,"referenced_table":null,"columns":["Name"],"referenced_columns":null,"comment":""}],"triggers":[],"def":""},{"name":"ProductCatalog","type":"BASIC TABLE","comment":"","columns":[{"name":"Id","type":"N","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[{"name":"Primary Key","type":"Partition key","def":"[{ AttributeName: \"Id\", KeyType: \"HASH\" }]","table":null,"referenced_table":null,"columns":["Id"],"referenced_columns":null,"comment":""}],"triggers":[],"def":""},{"name":"Reply","type":"BASIC TABLE","comment":"","columns":[{"name":"Id","type":"S","nullable":false,"default":null,"comment":""},{"name":"ReplyDateTime","type":"S","nullable":false,"default":null,"comment":""},{"name":"PostedBy","type":"S","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"PostedBy-index","def":"LocalSecondaryIndex { [{ AttributeName: \"Id\", KeyType: \"HASH\" } { AttributeName: \"PostedBy\", KeyType: \"RANGE\" }], { ProjectionType: \"KEYS_ONLY\" } }","table":null,"columns":null,"comment":""}],"constraints":[{"name":"Primary Key","type":"Partition key and sort key","def":"[{ AttributeName: \"Id\", KeyType: \"HASH\" } { AttributeName: \"ReplyDateTime\", KeyType: \"RANGE\" }]","table":null,"referenced_table":null,"columns":["Id","ReplyDateTime"],"referenced_columns":null,"comment":""}],"triggers":[],"def":""},{"name":"Thread","type":"BASIC TABLE","comment":"","columns":[{"name":"ForumName","type":"S","nullable":false,"default":null,"comment":""},{"name":"Subject","type":"S","nullable":false,"default":null,"comment":""}],"indexes":[],"constraints":[{"name":"Primary Key","type":"Partition key and sort key","def":"[{ AttributeName: \"ForumName\", KeyType: \"HASH\" } { AttributeName: \"Subject\", KeyType: \"RANGE\" }]","table":null,"referenced_table":null,"columns":["ForumName","Subject"],"referenced_columns":null,"comment":""}],"triggers":[],"def":""}],"relations":[{"table":"Thread","columns":["ForumName"],"cardinality":"Zero or more","parent_table":"Forum","parent_columns":["Name"],"parent_cardinality":"Exactly one","def":"Thread-\u003eForum","virtual":true}],"functions":null,"driver":{"name":"dynamodb","database_version":"","meta":{"dict":{"Column":"Attribute","Columns":"Attributes","Constraints":"Primary Key","Indexes":"Secondary Indexes"}}}} +{"name":"Amazon DynamoDB (ap-northeast-1)","tables":[{"name":"Forum","type":"BASIC TABLE","columns":[{"name":"Name","type":"S","nullable":false}],"constraints":[{"name":"Primary Key","type":"Partition key","def":"[{ AttributeName: \"Name\", KeyType: \"HASH\" }]","table":null,"columns":["Name"]}]},{"name":"ProductCatalog","type":"BASIC TABLE","columns":[{"name":"Id","type":"N","nullable":false}],"constraints":[{"name":"Primary Key","type":"Partition key","def":"[{ AttributeName: \"Id\", KeyType: \"HASH\" }]","table":null,"columns":["Id"]}]},{"name":"Reply","type":"BASIC TABLE","columns":[{"name":"Id","type":"S","nullable":false},{"name":"ReplyDateTime","type":"S","nullable":false},{"name":"PostedBy","type":"S","nullable":false}],"indexes":[{"name":"PostedBy-index","def":"LocalSecondaryIndex { [{ AttributeName: \"Id\", KeyType: \"HASH\" } { AttributeName: \"PostedBy\", KeyType: \"RANGE\" }], { ProjectionType: \"KEYS_ONLY\" } }","table":null,"columns":null}],"constraints":[{"name":"Primary Key","type":"Partition key and sort key","def":"[{ AttributeName: \"Id\", KeyType: \"HASH\" } { AttributeName: \"ReplyDateTime\", KeyType: \"RANGE\" }]","table":null,"columns":["Id","ReplyDateTime"]}]},{"name":"Thread","type":"BASIC TABLE","columns":[{"name":"ForumName","type":"S","nullable":false},{"name":"Subject","type":"S","nullable":false}],"constraints":[{"name":"Primary Key","type":"Partition key and sort key","def":"[{ AttributeName: \"ForumName\", KeyType: \"HASH\" } { AttributeName: \"Subject\", KeyType: \"RANGE\" }]","table":null,"columns":["ForumName","Subject"]}]}],"relations":[{"table":"Thread","columns":["ForumName"],"cardinality":"Zero or more","parent_table":"Forum","parent_columns":["Name"],"parent_cardinality":"Exactly one","def":"Thread-\u003eForum","virtual":true}],"driver":{"name":"dynamodb","meta":{"dict":{"Column":"Attribute","Columns":"Attributes","Constraints":"Primary Key","Indexes":"Secondary Indexes"}}}} diff --git a/sample/exclude/schema.json b/sample/exclude/schema.json index fa48428b..4a93971d 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.4.0","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} +{"name":"testdb","tables":[{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'"},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} diff --git a/sample/font/schema.json b/sample/font/schema.json index a58645c5..da36da3b 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.4.0","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"サンプル","Virtual":true},{"Name":"tbls","Virtual":true}]} +{"name":"testdb","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"エントリ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"本文"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'"},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"サンプル","Virtual":true},{"Name":"tbls","Virtual":true}]} diff --git a/sample/hide/schema.json b/sample/hide/schema.json index f7f4be04..51ad7513 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.4.0","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"Name":"green","Virtual":true},{"Name":"red","Virtual":true},{"Name":"blue","Virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} diff --git a/sample/hide_not_related_column/schema.json b/sample/hide_not_related_column/schema.json index f8216558..5b78e785 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.4.0","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"Name":"green","Virtual":true},{"Name":"red","Virtual":true},{"Name":"blue","Virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com","labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","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 7caa6275..f36ec1f6 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":"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.27-MariaDB-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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint(20)","nullable":false},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment","type":"text","nullable":false,"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},{"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"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment_post_id","type":"bigint(20)","nullable":false},{"name":"comment_user_id","type":"int(11)","nullable":false},{"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"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"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}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true,"default":"NULL","comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint(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,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":"NULL","comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS ((select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on(`p`.`id` = `c`.`post_id`)) left join `testdb`.`users` `u` on(`u`.`id` = `p`.`user_id`)) left join `testdb`.`users` `u2` on(`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"same_name_constraints","type":"BASE TABLE","columns":[{"name":"id","type":"bigint(20)","nullable":true,"default":"NULL","comment":""},{"name":"user_id","type":"int(11)","nullable":false}],"indexes":[{"name":"same_name","def":"UNIQUE KEY same_name (user_id, id) USING BTREE","table":"same_name_constraints","columns":["user_id","id"]}],"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"]},{"name":"same_name","type":"UNIQUE","def":"UNIQUE KEY same_name (user_id, id)","table":"same_name_constraints","columns":["user_id","id"]}],"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,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"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"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]}],"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},{"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"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int(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}],"driver":{"name":"mariadb","database_version":"10.5.27-MariaDB-ubu2004","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} diff --git a/sample/mermaid/schema.json b/sample/mermaid/schema.json index 4ccf8603..4ab5ba50 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":"Exactly one","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.0","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"Name":"green","Virtual":true},{"Name":"red","Virtual":true},{"Name":"blue","Virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com","labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} diff --git a/sample/mongo/schema.json b/sample/mongo/schema.json index 92e3b8b9..63f47bc3 100644 --- a/sample/mongo/schema.json +++ b/sample/mongo/schema.json @@ -1 +1 @@ -{"name":"","desc":"","tables":[{"name":"test.restaurants","type":"collection","comment":"Count of documents is 149","columns":[{"name":"_id","type":"objectId","nullable":false,"default":null,"comment":""},{"name":"address","type":"document","nullable":false,"default":null,"comment":""},{"name":"borough","type":"string","nullable":false,"default":null,"comment":""},{"name":"cuisine","type":"string","nullable":false,"default":null,"comment":""},{"name":"grades","type":"array","nullable":false,"default":null,"comment":""},{"name":"name","type":"string","nullable":false,"default":null,"comment":""},{"name":"restaurant_id","type":"string","nullable":false,"default":null,"comment":""}],"indexes":[{"name":"_id_","def":"{\"_id\": {\"$numberInt\":\"1\"}}","table":null,"columns":null,"comment":"Non-unique, Version 2"}],"constraints":[],"triggers":[],"def":""}],"relations":[],"functions":null,"driver":{"name":"mongodb","database_version":"","meta":{"dict":{"Column":"Attribute","Columns":"Attributes","Indexes":"Indexes"}}}} +{"tables":[{"name":"test.restaurants","type":"collection","comment":"Count of documents is 149","columns":[{"name":"_id","type":"objectId","nullable":false},{"name":"address","type":"document","nullable":false},{"name":"borough","type":"string","nullable":false},{"name":"cuisine","type":"string","nullable":false},{"name":"grades","type":"array","nullable":false},{"name":"name","type":"string","nullable":false},{"name":"restaurant_id","type":"string","nullable":false}],"indexes":[{"name":"_id_","def":"{\"_id\": {\"$numberInt\":\"1\"}}","table":null,"columns":null,"comment":"Non-unique, Version 2"}]}],"driver":{"name":"mongodb","meta":{"dict":{"Column":"Attribute","Columns":"Attributes","Indexes":"Indexes"}}}} diff --git a/sample/mssql/schema.json b/sample/mssql/schema.json index be1f9871..37d6c508 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 2019 (RTM-CU30) (KB5049235) - 15.0.4415.2 (X64) \n\tNov 18 2024 17:45:37 \n\tCopyright (C) 2019 Microsoft Corporation\n\tDeveloper Edition (64-bit) on Linux (Ubuntu 20.04.6 LTS) \u003cX64\u003e","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"users","type":"BASIC TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"comment":"long long long long long long long long long long long long long long long long long long long long long description"},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"PK__users_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"users","columns":["id"]},{"name":"UQ__users_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ email ]","table":"users","columns":["email"]},{"name":"UQ__users_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ username ]","table":"users","columns":["username"]}],"constraints":[{"name":"PK__users_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"users","columns":["id"]},{"name":"UQ__users_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ email ]","table":"users","columns":["email"]},{"name":"UQ__users_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ username ]","table":"users","columns":["username"]},{"name":"CK__users__username_*","type":"CHECK","def":"CHECK(len([username])\u003e(4))","table":"users","columns":null}],"triggers":[{"name":"update_users_updated","def":"CREATE TRIGGER update_users_updated\nON users\nAFTER UPDATE\nAS\nBEGIN\n UPDATE users SET updated = GETDATE()\n WHERE id = ( SELECT id FROM deleted)\nEND;"}]},{"name":"user_options","type":"BASIC TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"bit","nullable":false,"default":"((0))","comment":""},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"PK__user_opt_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ user_id ]","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PK__user_opt_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ user_id ]","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE CASCADE","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}]},{"name":"posts","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"posts","columns":["id"]},{"name":"UQ__posts_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, title ]","table":"posts","columns":["user_id","title"]},{"name":"posts_user_id_idx","def":"NONCLUSTERED, [ user_id ]","table":"posts","columns":["user_id"]}],"constraints":[{"name":"posts_id_pk","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"posts","columns":["id"]},{"name":"UQ__posts_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, title ]","table":"posts","columns":["user_id","title"]},{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE CASCADE","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated\nON posts\nAFTER UPDATE\nAS\nBEGIN\n UPDATE users SET updated = GETDATE()\n WHERE id = ( SELECT user_id FROM deleted)\nEND;"}],"labels":[{"Name":"green","Virtual":true},{"Name":"red","Virtual":true},{"Name":"blue","Virtual":true}]},{"name":"comments","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"post_id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"comments","columns":["id"]},{"name":"UQ__comments_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"]},{"name":"comments_post_id_user_id_idx","def":"NONCLUSTERED, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_id_pk","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"comments","columns":["id"]},{"name":"UQ__comments_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"]},{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(post_id) REFERENCES posts(id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}]},{"name":"comment_stars","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"int","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"UQ__comment__*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, comment_post_id, comment_user_id ]","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"UQ__comment__*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, comment_post_id, comment_user_id ]","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]},{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(comment_user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]}]},{"name":"logs","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"int","nullable":true},{"name":"comment_id","type":"int","nullable":true},{"name":"comment_star_id","type":"int","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"date","nullable":false}]},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"int","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"date","nullable":true,"comment":"comments.created"},{"name":"updated","type":"date","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (\n SELECT c.id, p.title, u2.username AS post_user, c.comment, u2.username AS comment_user, c.created, c.updated\n FROM posts AS p\n LEFT JOIN comments AS c on p.id = c.post_id\n LEFT JOIN users AS u on u.id = p.user_id\n LEFT JOIN users AS u2 on u2.id = c.user_id\n);","referenced_tables":["posts","comments","users"]},{"name":"CamelizeTable","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"created","type":"date","nullable":false}]},{"name":"hyphen-table","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"date","nullable":false}]},{"name":"administrator.blogs","type":"BASIC TABLE","comment":"admin blogs","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"PK__blogs_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"administrator.blogs","columns":["id"]}],"constraints":[{"name":"PK__blogs_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"administrator.blogs","columns":["id"]},{"name":"blogs_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE CASCADE","table":"administrator.blogs","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}]},{"name":"name with spaces","type":"VIEW","columns":[{"name":"title","type":"varchar(255)","nullable":false}],"def":"CREATE VIEW \"name with spaces\" AS (\n SELECT TOP 1 p.title\n FROM posts AS p\n);","referenced_tables":["posts"]},{"name":"Sales.Product","type":"BASIC TABLE","columns":[{"name":"ProductID","type":"int","nullable":false},{"name":"SalesPersonID","type":"int","nullable":true}],"indexes":[{"name":"PK__Product_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ ProductID ]","table":"Sales.Product","columns":["ProductID"]},{"name":"UQ__Product_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ SalesPersonID ]","table":"Sales.Product","columns":["SalesPersonID"]}],"constraints":[{"name":"PK__Product_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ ProductID ]","table":"Sales.Product","columns":["ProductID"]},{"name":"UQ__Product_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ SalesPersonID ]","table":"Sales.Product","columns":["SalesPersonID"]}]},{"name":"Rabbits.Running","type":"BASIC TABLE","columns":[{"name":"LocationID","type":"int","nullable":false},{"name":"ProductID","type":"int","nullable":true},{"name":"EmployeeID","type":"int","nullable":true}],"indexes":[{"name":"PK__Running_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ LocationID ]","table":"Rabbits.Running","columns":["LocationID"]},{"name":"UQ__Running_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ EmployeeID ]","table":"Rabbits.Running","columns":["EmployeeID"]},{"name":"UQ__Running_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ ProductID ]","table":"Rabbits.Running","columns":["ProductID"]}],"constraints":[{"name":"PK__Running_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ LocationID ]","table":"Rabbits.Running","columns":["LocationID"]},{"name":"UQ__Running_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ EmployeeID ]","table":"Rabbits.Running","columns":["EmployeeID"]},{"name":"UQ__Running_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ ProductID ]","table":"Rabbits.Running","columns":["ProductID"]},{"name":"FK_TempSales_SalesReason","type":"FOREIGN KEY","def":"FOREIGN KEY(ProductID) REFERENCES Sales.Product(SalesPersonID) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"Rabbits.Running","referenced_table":"Sales.Product","columns":["ProductID"],"referenced_columns":["SalesPersonID"]}]}],"relations":[{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","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 2019 (RTM-CU30) (KB5049235) - 15.0.4415.2 (X64) \n\tNov 18 2024 17:45:37 \n\tCopyright (C) 2019 Microsoft Corporation\n\tDeveloper Edition (64-bit) on Linux (Ubuntu 20.04.6 LTS) \u003cX64\u003e","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} diff --git a/sample/mysql/schema.json b/sample/mysql/schema.json index 2f10a4e5..4ab5ba50 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":"Exactly one","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.3","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"Name":"green","Virtual":true},{"Name":"red","Virtual":true},{"Name":"blue","Virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com","labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","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 9947cf84..e98b719e 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":"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}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment_post_id","type":"bigint(20)","nullable":false},{"name":"comment_user_id","type":"int(11)","nullable":false},{"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"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint(20)","nullable":false},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"post_id","type":"bigint(20)","nullable":true},{"name":"comment_id","type":"bigint(20)","nullable":true},{"name":"comment_star_id","type":"bigint(20)","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint(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,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS ((select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`)))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint(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},{"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"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int(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,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"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"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]}],"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}],"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 451af408..9154a375 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.4.0","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"Name":"green","Virtual":true},{"Name":"red","Virtual":true},{"Name":"blue","Virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} diff --git a/sample/png/schema.json b/sample/png/schema.json index 4ccf8603..4ab5ba50 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":"Exactly one","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.0","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"Name":"green","Virtual":true},{"Name":"red","Virtual":true},{"Name":"blue","Virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com","labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} diff --git a/sample/postgres/README.md b/sample/postgres/README.md index c2e9124a..c9f150f2 100644 --- a/sample/postgres/README.md +++ b/sample/postgres/README.md @@ -36,6 +36,7 @@ Sample PostgreSQL database document. | Name | ReturnType | Arguments | Type | | ---- | ------- | ------- | ---- | +| public.reset_comment | void | IN comment_id integer | PROCEDURE | | public.uuid_nil | uuid | | FUNCTION | | public.uuid_ns_dns | uuid | | FUNCTION | | public.uuid_ns_url | uuid | | FUNCTION | @@ -47,7 +48,6 @@ Sample PostgreSQL database document. | public.uuid_generate_v4 | uuid | | FUNCTION | | public.uuid_generate_v5 | uuid | namespace uuid, name text | FUNCTION | | public.update_updated | trigger | | FUNCTION | -| public.reset_comment | void | IN comment_id integer | PROCEDURE | ## Enums diff --git a/sample/postgres/schema.json b/sample/postgres/schema.json index e6549018..1339f542 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":["user_id","title"],"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":["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":"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"}],"enums":[{"name":"public.post_types","values":["draft","private","public"]}],"driver":{"name":"postgres","database_version":"PostgreSQL 15.10 (Debian 15.10-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit","meta":{"current_schema":"public","search_paths":["postgres","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}},"viewpoints":[{"name":"post","desc":"for post","tables":["public.post*"]},{"name":"administrator","desc":"administrator schema only","tables":["administrator.*"]}]} +{"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},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"users_pkey","def":"CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)","table":"public.users","columns":["id"]},{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)","table":"public.users","columns":["username"]},{"name":"users_email_key","def":"CREATE UNIQUE INDEX users_email_key ON public.users USING btree (email)","table":"public.users","columns":["email"]}],"constraints":[{"name":"users_username_check","type":"CHECK","def":"CHECK ((char_length((username)::text) \u003e 4))","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.users","referenced_table":"","columns":["id"]},{"name":"users_username_key","type":"UNIQUE","def":"UNIQUE (username)","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_email_key","type":"UNIQUE","def":"UNIQUE (email)","table":"public.users","referenced_table":"","columns":["email"]}],"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"}]},{"name":"public.user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"integer","nullable":false},{"name":"show_email","type":"boolean","nullable":false,"default":"false","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}]},{"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},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'::character varying","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"post_types","nullable":false,"comment":"public/private/draft"},{"name":"labels","type":"varchar(50)[]","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CREATE UNIQUE INDEX posts_id_pk ON public.posts USING btree (id)","table":"public.posts","columns":["id"]},{"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":["user_id","title"]},{"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"]},{"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"]},{"name":"posts_user_id_title_key","type":"UNIQUE","def":"UNIQUE (user_id, title)","table":"public.posts","referenced_table":"","columns":["user_id","title"]}],"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"}]},{"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},{"name":"user_id","type":"integer","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (post_id * '-1'::integer) STORED"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CREATE UNIQUE INDEX comments_id_pk ON public.comments USING btree (id)","table":"public.comments","columns":["id"]},{"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"]},{"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"]}],"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"]},{"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"]},{"name":"comments_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.comments","referenced_table":"","columns":["id"]},{"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"]}]},{"name":"public.comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"user_id","type":"integer","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"integer","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","table":"public.comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id)","table":"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"]},{"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"]}]},{"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},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"uuid","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false}]},{"name":"public.post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"timestamp without time zone","nullable":true,"comment":"comments.created"},{"name":"updated","type":"timestamp without time zone","nullable":true,"comment":"comments.updated"}],"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","columns":[{"name":"id","type":"uuid","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"comment_star_user","type":"varchar(50)","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false}],"indexes":[{"name":"CamelizeTable_id_key","def":"CREATE UNIQUE INDEX \"CamelizeTable_id_key\" ON public.\"CamelizeTable\" USING btree (id)","table":"public.CamelizeTable","columns":["id"]}],"constraints":[{"name":"CamelizeTable_id_key","type":"UNIQUE","def":"UNIQUE (id)","table":"public.CamelizeTable","referenced_table":"","columns":["id"]}]},{"name":"public.hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"hyphen-column","type":"text","nullable":false},{"name":"CamelizeTableId","type":"uuid","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false}],"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"]}],"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"]},{"name":"hyphen-table_hyphen-column_key","type":"UNIQUE","def":"UNIQUE (\"hyphen-column\")","table":"public.hyphen-table","referenced_table":"","columns":["hyphen-column"]}]},{"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},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON administrator.blogs USING btree (id)","table":"administrator.blogs","columns":["id"]}],"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"]},{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"administrator.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blogs","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blogs_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false},{"name":"dump","type":"text","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON backup.blogs USING btree (id)","table":"backup.blogs","columns":["id"]}],"constraints":[{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blog_options","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blog_options_id_seq'::regclass)","comment":""},{"name":"blog_id","type":"integer","nullable":false},{"name":"label","type":"text","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}],"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"]},{"name":"blog_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blog_options","referenced_table":"","columns":["id"]}]},{"name":"time.bar","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"indexes":[{"name":"bar_pkey","def":"CREATE UNIQUE INDEX bar_pkey ON \"time\".bar USING btree (id)","table":"time.bar","columns":["id"]}],"constraints":[{"name":"bar_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.bar","referenced_table":"","columns":["id"]}]},{"name":"time.hyphenated-table","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"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"]}],"constraints":[{"name":"hyphenated-table_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.hyphenated-table","referenced_table":"","columns":["id"]}]},{"name":"time.referencing","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false},{"name":"bar_id","type":"integer","nullable":false},{"name":"ht_id","type":"integer","nullable":false}],"indexes":[{"name":"referencing_pkey","def":"CREATE UNIQUE INDEX referencing_pkey ON \"time\".referencing USING btree (id)","table":"time.referencing","columns":["id"]}],"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"]},{"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"]},{"name":"referencing_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.referencing","referenced_table":"","columns":["id"]}]}],"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.reset_comment","return_type":"void","arguments":"IN comment_id integer","type":"PROCEDURE"},{"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"}],"enums":[{"name":"public.post_types","values":["draft","private","public"]}],"driver":{"name":"postgres","database_version":"PostgreSQL 15.10 (Debian 15.10-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit","meta":{"current_schema":"public","search_paths":["postgres","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}},"viewpoints":[{"name":"post","desc":"for post","tables":["public.post*"]},{"name":"administrator","desc":"administrator schema only","tables":["administrator.*"]}]} diff --git a/sample/postgres95/schema.json b/sample/postgres95/schema.json index 56e8ed5d..559e4f41 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":["user_id","title"],"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":["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":"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"}],"enums":[{"name":"public.post_types","values":["draft","private","public"]}],"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":["postgres","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}},"viewpoints":[{"name":"post","desc":"for post","tables":["public.post*"]},{"name":"administrator","desc":"administrator schema only","tables":["administrator.*"]}]} +{"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},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"users_pkey","def":"CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)","table":"public.users","columns":["id"]},{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)","table":"public.users","columns":["username"]},{"name":"users_email_key","def":"CREATE UNIQUE INDEX users_email_key ON public.users USING btree (email)","table":"public.users","columns":["email"]}],"constraints":[{"name":"users_username_check","type":"CHECK","def":"CHECK ((char_length((username)::text) \u003e 4))","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.users","referenced_table":"","columns":["id"]},{"name":"users_username_key","type":"UNIQUE","def":"UNIQUE (username)","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_email_key","type":"UNIQUE","def":"UNIQUE (email)","table":"public.users","referenced_table":"","columns":["email"]}],"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"}]},{"name":"public.user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"integer","nullable":false},{"name":"show_email","type":"boolean","nullable":false,"default":"false","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}]},{"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},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'::character varying","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"post_types","nullable":false,"comment":"public/private/draft"},{"name":"labels","type":"varchar(50)[]","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CREATE UNIQUE INDEX posts_id_pk ON public.posts USING btree (id)","table":"public.posts","columns":["id"]},{"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":["user_id","title"]},{"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","tableoid","cmax","xmax","cmin","xmin","ctid","id","user_id","title","body","post_type","labels","created"]},{"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"]},{"name":"posts_user_id_title_key","type":"UNIQUE","def":"UNIQUE (user_id, title)","table":"public.posts","referenced_table":"","columns":["user_id","title"]}],"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"}]},{"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},{"name":"user_id","type":"integer","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CREATE UNIQUE INDEX comments_id_pk ON public.comments USING btree (id)","table":"public.comments","columns":["id"]},{"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"]},{"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"]}],"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"]},{"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"]},{"name":"comments_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.comments","referenced_table":"","columns":["id"]},{"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"]}]},{"name":"public.comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"user_id","type":"integer","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"integer","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","table":"public.comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id)","table":"public.comment_stars","referenced_table":"comments","columns":["comment_user_id","comment_post_id","comment_user_id","comment_post_id"],"referenced_columns":["post_id","user_id","user_id","post_id"]},{"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"]}]},{"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},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"uuid","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false}]},{"name":"public.post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"timestamp without time zone","nullable":true,"comment":"comments.created"},{"name":"updated","type":"timestamp without time zone","nullable":true,"comment":"comments.updated"}],"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","columns":[{"name":"id","type":"uuid","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"comment_star_user","type":"varchar(50)","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false}],"indexes":[{"name":"CamelizeTable_id_key","def":"CREATE UNIQUE INDEX \"CamelizeTable_id_key\" ON public.\"CamelizeTable\" USING btree (id)","table":"public.CamelizeTable","columns":["id"]}],"constraints":[{"name":"CamelizeTable_id_key","type":"UNIQUE","def":"UNIQUE (id)","table":"public.CamelizeTable","referenced_table":"","columns":["id"]}]},{"name":"public.hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"hyphen-column","type":"text","nullable":false},{"name":"CamelizeTableId","type":"uuid","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false}],"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"]}],"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"]},{"name":"hyphen-table_hyphen-column_key","type":"UNIQUE","def":"UNIQUE (\"hyphen-column\")","table":"public.hyphen-table","referenced_table":"","columns":["hyphen-column"]}]},{"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},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON administrator.blogs USING btree (id)","table":"administrator.blogs","columns":["id"]}],"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"]},{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"administrator.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blogs","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blogs_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false},{"name":"dump","type":"text","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON backup.blogs USING btree (id)","table":"backup.blogs","columns":["id"]}],"constraints":[{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blog_options","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blog_options_id_seq'::regclass)","comment":""},{"name":"blog_id","type":"integer","nullable":false},{"name":"label","type":"text","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}],"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"]},{"name":"blog_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blog_options","referenced_table":"","columns":["id"]}]},{"name":"time.bar","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"indexes":[{"name":"bar_pkey","def":"CREATE UNIQUE INDEX bar_pkey ON \"time\".bar USING btree (id)","table":"time.bar","columns":["id"]}],"constraints":[{"name":"bar_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.bar","referenced_table":"","columns":["id"]}]},{"name":"time.hyphenated-table","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"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"]}],"constraints":[{"name":"hyphenated-table_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.hyphenated-table","referenced_table":"","columns":["id"]}]},{"name":"time.referencing","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false},{"name":"bar_id","type":"integer","nullable":false},{"name":"ht_id","type":"integer","nullable":false}],"indexes":[{"name":"referencing_pkey","def":"CREATE UNIQUE INDEX referencing_pkey ON \"time\".referencing USING btree (id)","table":"time.referencing","columns":["id"]}],"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"]},{"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"]},{"name":"referencing_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.referencing","referenced_table":"","columns":["id"]}]}],"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"}],"enums":[{"name":"public.post_types","values":["draft","private","public"]}],"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":["postgres","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}},"viewpoints":[{"name":"post","desc":"for post","tables":["public.post*"]},{"name":"administrator","desc":"administrator schema only","tables":["administrator.*"]}]} diff --git a/sample/sqlite/schema.json b/sample/sqlite/schema.json index 0805c255..5040cbbb 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":"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.46.1","meta":{}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} +{"name":"testdb.sqlite3","desc":"Sample database document.","tables":[{"name":"users","type":"table","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"username","type":"TEXT","nullable":false},{"name":"password","type":"TEXT","nullable":false,"labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"TEXT","nullable":false,"labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"indexes":[{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON users(username)","table":"users","columns":["username"]},{"name":"sqlite_autoindex_users_2","def":"UNIQUE (email)","table":"users","columns":["email"]},{"name":"sqlite_autoindex_users_1","def":"UNIQUE (username)","table":"users","columns":["username"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"sqlite_autoindex_users_2","type":"UNIQUE","def":"UNIQUE (email)","table":"users","columns":["email"]},{"name":"sqlite_autoindex_users_1","type":"UNIQUE","def":"UNIQUE (username)","table":"users","columns":["username"]},{"name":"-","type":"CHECK","def":"CHECK(length(username) \u003e 4)","table":"users","columns":["username"]}],"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","columns":[{"name":"user_id","type":"INTEGER","nullable":true},{"name":"show_email","type":"INTEGER","nullable":false,"default":"0","comment":""},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"constraints":[{"name":"user_id","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"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"]}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"title","type":"TEXT","nullable":false},{"name":"body","type":"TEXT","nullable":false,"comment":"post body"},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"CREATE INDEX posts_user_id_idx ON posts(user_id)","table":"posts","columns":["user_id"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"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"]}],"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"}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"post_id","type":"INTEGER","nullable":false},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"comment","type":"TEXT","nullable":false},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"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"]},{"name":"sqlite_autoindex_comments_1","def":"UNIQUE (post_id, user_id)","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]},{"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"]},{"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"]},{"name":"sqlite_autoindex_comments_1","type":"UNIQUE","def":"UNIQUE (post_id, user_id)","table":"comments","columns":["post_id","user_id"]}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"comment_post_id","type":"INTEGER","nullable":false},{"name":"comment_user_id","type":"INTEGER","nullable":false},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"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"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"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"]},{"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"]},{"name":"sqlite_autoindex_comment_stars_1","type":"UNIQUE","def":"UNIQUE (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE comment_stars (\n id 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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"post_id","type":"INTEGER","nullable":true},{"name":"comment_id","type":"INTEGER","nullable":true},{"name":"comment_star_id","type":"INTEGER","nullable":true},{"name":"payload","type":"TEXT","nullable":true},{"name":"created","type":"NUMERIC","nullable":false}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"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,"comment":"comments.id"},{"name":"title","type":"TEXT","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"TEXT","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"TEXT","nullable":true},{"name":"comment_user","type":"TEXT","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"NUMERIC","nullable":true,"comment":"comments.created"},{"name":"updated","type":"NUMERIC","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS\n SELECT c.id, p.title, u2.username AS post_user, c.comment, u2.username AS comment_user, c.created, c.updated\n FROM posts AS p\n LEFT JOIN comments AS c on p.id = c.post_id\n LEFT JOIN users AS u on u.id = p.user_id\n LEFT JOIN users AS u2 on u2.id = c.user_id","referenced_tables":["posts","comments","users"]},{"name":"CamelizeTable","type":"table","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"created","type":"NUMERIC","nullable":false}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE CamelizeTable (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n created NUMERIC NOT NULL\n)"},{"name":"hyphen-table","type":"table","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"hyphen-column","type":"TEXT","nullable":false},{"name":"created","type":"NUMERIC","nullable":false}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"col","type":"TEXT","nullable":true},{"name":"brackets","type":"TEXT","nullable":false},{"name":"checkcheck","type":"TEXT","nullable":false},{"name":"downcase","type":"TEXT","nullable":false},{"name":"nl","type":"TEXT","nullable":false}],"indexes":[{"name":"sqlite_autoindex_check_constraints_4","def":"UNIQUE (nl)","table":"check_constraints","columns":["nl"]},{"name":"sqlite_autoindex_check_constraints_3","def":"UNIQUE (downcase)","table":"check_constraints","columns":["downcase"]},{"name":"sqlite_autoindex_check_constraints_2","def":"UNIQUE (checkcheck)","table":"check_constraints","columns":["checkcheck"]},{"name":"sqlite_autoindex_check_constraints_1","def":"UNIQUE (brackets)","table":"check_constraints","columns":["brackets"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"check_constraints","columns":["id"]},{"name":"sqlite_autoindex_check_constraints_4","type":"UNIQUE","def":"UNIQUE (nl)","table":"check_constraints","columns":["nl"]},{"name":"sqlite_autoindex_check_constraints_3","type":"UNIQUE","def":"UNIQUE (downcase)","table":"check_constraints","columns":["downcase"]},{"name":"sqlite_autoindex_check_constraints_2","type":"UNIQUE","def":"UNIQUE (checkcheck)","table":"check_constraints","columns":["checkcheck"]},{"name":"sqlite_autoindex_check_constraints_1","type":"UNIQUE","def":"UNIQUE (brackets)","table":"check_constraints","columns":["brackets"]},{"name":"-","type":"CHECK","def":"CHECK(length(col) \u003e 4)","table":"check_constraints","columns":["col"]},{"name":"-","type":"CHECK","def":"CHECK(((length(brackets) \u003e 4)))","table":"check_constraints","columns":["brackets"]},{"name":"-","type":"CHECK","def":"CHECK(length(checkcheck) \u003e 4)","table":"check_constraints","columns":["checkcheck"]},{"name":"-","type":"CHECK","def":"check(length(downcase) \u003e 4)","table":"check_constraints","columns":["downcase"]},{"name":"-","type":"CHECK","def":"check(length(nl) \u003e 4 OR nl != 'ln')","table":"check_constraints","columns":["nl"]}],"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","columns":[{"name":"logs","type":"","nullable":true}],"def":"CREATE VIRTUAL TABLE syslog USING fts3(logs)"},{"name":"access_log","type":"virtual table","columns":[{"name":"logs","type":"","nullable":true}],"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}],"driver":{"name":"sqlite","database_version":"3.46.1"},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} diff --git a/sample/viewpoints/schema.json b/sample/viewpoints/schema.json index 8cf732f0..0f55212f 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.4.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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"labels":[{"Name":"user","Virtual":true}]},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci","labels":[{"Name":"content","Virtual":true}]},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false,"labels":[{"Name":"user","Virtual":true}]},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'","labels":[{"Name":"content","Virtual":true}]},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","labels":[{"Name":"content","Virtual":true}],"referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"labels":[{"Name":"user","Virtual":true}]},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"Name":"content","Virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'","labels":[{"Name":"user","Virtual":true}]},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com","labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'","labels":[{"Name":"user","Virtual":true}]}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}],"viewpoints":[{"name":"Content","desc":"Content as an asset for blogging services","labels":["content"]},{"name":"Ops","desc":"Tables to be referenced during operation","tables":["logs","users","posts"]},{"name":"Around the users table","desc":"Tables related to the users table","tables":["users"],"distance":1,"groups":[{"name":"Content","desc":"Content as an asset for blogging services","labels":["content"]}]},{"name":"Secure data","desc":"Tables with secure data","labels":["secure"]}]} diff --git a/schema/json.go b/schema/json.go index 05c875be..5ef0d5b3 100644 --- a/schema/json.go +++ b/schema/json.go @@ -9,9 +9,6 @@ func (s Schema) MarshalJSON() ([]byte, error) { if len(s.Tables) == 0 { s.Tables = []*Table{} } - if len(s.Relations) == 0 { - s.Relations = []*Relation{} - } return json.Marshal(&struct { Name string `json:"name,omitempty"` @@ -36,62 +33,11 @@ func (s Schema) MarshalJSON() ([]byte, error) { }) } -// MarshalJSON return custom JSON byte -func (d Function) MarshalJSON() ([]byte, error) { - return json.Marshal(&struct { - Name string `json:"name"` - ReturnType string `json:"return_type"` - Arguments string `json:"arguments"` - Type string `json:"type"` - }{ - Name: d.Name, - ReturnType: d.ReturnType, - Arguments: d.Arguments, - Type: d.Type, - }) -} - -// MarshalJSON return custom JSON byte -func (e Enum) MarshalJSON() ([]byte, error) { - return json.Marshal(&struct { - Name string `json:"name"` - Values []string `json:"values"` - }{ - Name: e.Name, - Values: e.Values, - }) -} - -// MarshalJSON return custom JSON byte -func (d Driver) MarshalJSON() ([]byte, error) { - if d.Meta == nil { - d.Meta = &DriverMeta{} - } - return json.Marshal(&struct { - Name string `json:"name"` - DatabaseVersion string `json:"database_version,omitempty"` - Meta *DriverMeta `json:"meta,omitempty"` - }{ - Name: d.Name, - DatabaseVersion: d.DatabaseVersion, - Meta: d.Meta, - }) -} - // MarshalJSON return custom JSON byte func (t Table) MarshalJSON() ([]byte, error) { if len(t.Columns) == 0 { t.Columns = []*Column{} } - if len(t.Indexes) == 0 { - t.Indexes = []*Index{} - } - if len(t.Constraints) == 0 { - t.Constraints = []*Constraint{} - } - if len(t.Triggers) == 0 { - t.Triggers = []*Trigger{} - } referencedTables := []string{} for _, rt := range t.ReferencedTables { @@ -106,7 +52,7 @@ func (t Table) MarshalJSON() ([]byte, error) { Indexes []*Index `json:"indexes,omitempty"` Constraints []*Constraint `json:"constraints,omitempty"` Triggers []*Trigger `json:"triggers,omitempty"` - Def string `json:"def"` + Def string `json:"def,omitempty"` Labels Labels `json:"labels,omitempty"` ReferencedTables []string `json:"referenced_tables,omitempty"` }{ @@ -130,7 +76,7 @@ func (c Column) MarshalJSON() ([]byte, error) { Name string `json:"name"` Type string `json:"type"` Nullable bool `json:"nullable"` - Default string `json:"default"` + Default *string `json:"default,omitempty"` ExtraDef string `json:"extra_def,omitempty"` Labels Labels `json:"labels,omitempty"` Comment string `json:"comment"` @@ -140,7 +86,7 @@ func (c Column) MarshalJSON() ([]byte, error) { Name: c.Name, Type: c.Type, Nullable: c.Nullable, - Default: c.Default.String, + Default: &c.Default.String, Comment: c.Comment, ExtraDef: c.ExtraDef, Labels: c.Labels, @@ -152,8 +98,8 @@ func (c Column) MarshalJSON() ([]byte, error) { Name string `json:"name"` Type string `json:"type"` Nullable bool `json:"nullable"` - Default *string `json:"default"` - Comment string `json:"comment"` + Default *string `json:"default,omitempty"` + Comment string `json:"comment,omitempty"` ExtraDef string `json:"extra_def,omitempty"` Labels Labels `json:"labels,omitempty"` ParentRelations []*Relation `json:"-"` @@ -185,10 +131,10 @@ func (r Relation) MarshalJSON() ([]byte, error) { return json.Marshal(&struct { Table string `json:"table"` Columns []string `json:"columns"` - Cardinality string `json:"cardinality"` + Cardinality string `json:"cardinality,omitempty"` ParentTable string `json:"parent_table"` ParentColumns []string `json:"parent_columns"` - ParentCardinality string `json:"parent_cardinality"` + ParentCardinality string `json:"parent_cardinality,omitempty"` Def string `json:"def"` Virtual bool `json:"virtual"` }{ diff --git a/schema/schema.go b/schema/schema.go index 3a7308da..dc593a76 100644 --- a/schema/schema.go +++ b/schema/schema.go @@ -101,9 +101,9 @@ type Constraint struct { Type string `json:"type"` Def string `json:"def"` Table *string `json:"table"` - ReferencedTable *string `json:"referenced_table" yaml:"referencedTable"` + ReferencedTable *string `json:"referenced_table,omitempty" yaml:"referencedTable,omitempty"` Columns []string `json:"columns"` - ReferencedColumns []string `json:"referenced_columns" yaml:"referencedColumns"` + ReferencedColumns []string `json:"referenced_columns,omitempty" yaml:"referencedColumns,omitempty"` Comment string `json:"comment,omitempty"` } diff --git a/schema/yaml.go b/schema/yaml.go index 8f40ed04..81ebe01c 100644 --- a/schema/yaml.go +++ b/schema/yaml.go @@ -27,12 +27,12 @@ func (t Table) MarshalYAML() ([]byte, error) { return yaml.Marshal(&struct { Name string `yaml:"name"` Type string `yaml:"type"` - Comment string `yaml:"comment"` + Comment string `yaml:"comment,omitempty"` Columns []*Column `yaml:"columns"` - Indexes []*Index `yaml:"indexes"` - Constraints []*Constraint `yaml:"constraints"` - Triggers []*Trigger `yaml:"triggers"` - Def string `yaml:"def"` + Indexes []*Index `yaml:"indexes,omitempty"` + Constraints []*Constraint `yaml:"constraints,omitempty"` + Triggers []*Trigger `yaml:"triggers,omitempty"` + Def string `yaml:"def,omitempty"` Labels Labels `yaml:"labels,omitempty"` ReferencedTables []string `yaml:"referencedTables,omitempty"` }{ @@ -56,17 +56,17 @@ func (c Column) MarshalYAML() ([]byte, error) { Name string `yaml:"name"` Type string `yaml:"type"` Nullable bool `yaml:"nullable"` - Default string `yaml:"default"` + Default *string `yaml:"default,omitempty"` ExtraDef string `yaml:"extraDef,omitempty"` Labels Labels `yaml:"labels,omitempty"` - Comment string `yaml:"comment"` + Comment string `yaml:"comment,omitempty"` ParentRelations []*Relation `yaml:"-"` ChildRelations []*Relation `yaml:"-"` }{ Name: c.Name, Type: c.Type, Nullable: c.Nullable, - Default: c.Default.String, + Default: &c.Default.String, Comment: c.Comment, ExtraDef: c.ExtraDef, Labels: c.Labels, @@ -78,10 +78,10 @@ func (c Column) MarshalYAML() ([]byte, error) { Name string `yaml:"name"` Type string `yaml:"type"` Nullable bool `yaml:"nullable"` - Default *string `yaml:"default"` + Default *string `yaml:"default,omitempty"` ExtraDef string `yaml:"extraDef,omitempty"` Labels Labels `yaml:"labels,omitempty"` - Comment string `yaml:"comment"` + Comment string `yaml:"comment,omitempty"` ParentRelations []*Relation `yaml:"-"` ChildRelations []*Relation `yaml:"-"` }{ @@ -111,10 +111,10 @@ func (r Relation) MarshalYAML() ([]byte, error) { return yaml.Marshal(&struct { Table string `yaml:"table"` Columns []string `yaml:"columns"` - Cardinality string `yaml:"cardinality"` + Cardinality string `yaml:"cardinality,omitempty"` ParentTable string `yaml:"parentTable"` ParentColumns []string `yaml:"parentColumns"` - ParentCardinality string `yaml:"parentCardinality"` + ParentCardinality string `yaml:"parentCardinality,omitempty"` Def string `yaml:"def"` Virtual bool `yaml:"virtual"` }{ @@ -134,12 +134,12 @@ func (t *Table) UnmarshalYAML(data []byte) error { s := struct { Name string `yaml:"name"` Type string `yaml:"type"` - Comment string `yaml:"comment"` + Comment string `yaml:"comment,omitempty"` Columns []*Column `yaml:"columns"` - Indexes []*Index `yaml:"indexes"` - Constraints []*Constraint `yaml:"constraints"` - Triggers []*Trigger `yaml:"triggers"` - Def string `yaml:"def"` + Indexes []*Index `yaml:"indexes,omitempty"` + Constraints []*Constraint `yaml:"constraints,omitempty"` + Triggers []*Trigger `yaml:"triggers,omitempty"` + Def string `yaml:"def,omitempty"` Labels Labels `yaml:"labels,omitempty"` ReferencedTables []string `yaml:"referencedTables,omitempty"` }{} @@ -170,8 +170,8 @@ func (c *Column) UnmarshalYAML(data []byte) error { Name string `yaml:"name"` Type string `yaml:"type"` Nullable bool `yaml:"nullable"` - Default *string `yaml:"default"` - Comment string `yaml:"comment"` + Default *string `yaml:"default,omitempty"` + Comment string `yaml:"comment,omitempty"` ExtraDef string `yaml:"extraDef,omitempty"` Labels Labels `yaml:"labels,omitempty"` ParentRelations []*Relation `yaml:"-"` @@ -203,10 +203,10 @@ func (r *Relation) UnmarshalYAML(data []byte) error { s := struct { Table string `yaml:"table"` Columns []string `yaml:"columns"` - Cardinality string `yaml:"cardinality"` + Cardinality string `yaml:"cardinality,omitempty"` ParentTable string `yaml:"parentTable"` ParentColumns []string `yaml:"parentColumns"` - ParentCardinality string `yaml:"parentCardinality"` + ParentCardinality string `yaml:"parentCardinality,omitempty"` Def string `yaml:"def"` Virtual bool `yaml:"virtual"` }{} diff --git a/testdata/json_output_schema.golden b/testdata/json_output_schema.golden index e1b323bd..b82d5b90 100644 --- a/testdata/json_output_schema.golden +++ b/testdata/json_output_schema.golden @@ -1,6 +1,5 @@ { "name": "testschema", - "desc": "", "tables": [ { "name": "a", @@ -11,14 +10,12 @@ "name": "a", "type": "INTEGER", "nullable": false, - "default": null, "comment": "column a" }, { "name": "a2", "type": "TEXT", "nullable": false, - "default": null, "comment": "column a2" } ], @@ -38,9 +35,7 @@ "type": "", "def": "PRIMARY KEY (a)", "table": "a", - "referenced_table": null, - "columns": null, - "referenced_columns": null + "columns": null } ], "triggers": [ @@ -49,7 +44,6 @@ "def": "CREATE CONSTRAINT TRIGGER update_a_a2 AFTER INSERT OR UPDATE ON a" } ], - "def": "", "labels": [ { "Name": "blue", @@ -70,21 +64,15 @@ "name": "b", "type": "INTEGER", "nullable": false, - "default": null, "comment": "column b" }, { "name": "b2", "type": "TEXT", "nullable": false, - "default": null, "comment": "column b2" } ], - "indexes": [], - "constraints": [], - "triggers": [], - "def": "", "labels": [ { "Name": "red", @@ -105,13 +93,9 @@ "name": "view_column", "type": "INTEGER", "nullable": false, - "default": null, "comment": "column of view" } ], - "indexes": [], - "constraints": [], - "triggers": [], "def": "CREATE VIEW view AS SELECT a, b FROM a JOIN b ON a.a = b.b", "referenced_tables": [ "a", @@ -135,7 +119,6 @@ "virtual": false } ], - "functions": null, "enums": [ { "name": "enum", diff --git a/testdata/modify_schema_.golden b/testdata/modify_schema_.golden index 472b60f9..2e6070e2 100644 --- a/testdata/modify_schema_.golden +++ b/testdata/modify_schema_.golden @@ -1,25 +1,19 @@ { "name": "testdb.sqlite3", - "desc": "", "tables": [ { "name": "users", "type": "table", - "comment": "", "columns": [ { "name": "id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "username", "type": "TEXT", - "nullable": false, - "default": null, - "comment": "" + "nullable": false } ], "indexes": [ @@ -38,36 +32,29 @@ "type": "PRIMARY KEY", "def": "PRIMARY KEY (id)", "table": "users", - "referenced_table": null, "columns": [ "id" - ], - "referenced_columns": null + ] }, { "name": "sqlite_autoindex_users_1", "type": "UNIQUE", "def": "UNIQUE (username)", "table": "users", - "referenced_table": null, "columns": [ "username" - ], - "referenced_columns": null + ] }, { "name": "-", "type": "CHECK", "def": "CHECK(length(username) \u003e 4)", "table": "users", - "referenced_table": null, "columns": [ "username" - ], - "referenced_columns": null + ] } ], - "triggers": [], "def": "CREATE TABLE users (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n username TEXT UNIQUE NOT NULL CHECK(length(username) \u003e 4)\n)", "labels": [ { @@ -79,21 +66,16 @@ { "name": "categories", "type": "table", - "comment": "", "columns": [ { "name": "id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "name", "type": "TEXT", - "nullable": false, - "default": null, - "comment": "" + "nullable": false } ], "indexes": [ @@ -112,25 +94,20 @@ "type": "PRIMARY KEY", "def": "PRIMARY KEY (id)", "table": "categories", - "referenced_table": null, "columns": [ "id" - ], - "referenced_columns": null + ] }, { "name": "sqlite_autoindex_categories_1", "type": "UNIQUE", "def": "UNIQUE (name)", "table": "categories", - "referenced_table": null, "columns": [ "name" - ], - "referenced_columns": null + ] } ], - "triggers": [], "def": "CREATE TABLE categories (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n name TEXT UNIQUE NOT NULL\n)", "labels": [ { @@ -146,35 +123,26 @@ { "name": "posts", "type": "table", - "comment": "", "columns": [ { "name": "id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "user_id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "category_id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "title", "type": "TEXT", - "nullable": false, - "default": null, - "comment": "" + "nullable": false } ], "indexes": [ @@ -193,11 +161,9 @@ "type": "PRIMARY KEY", "def": "PRIMARY KEY (id)", "table": "posts", - "referenced_table": null, "columns": [ "id" - ], - "referenced_columns": null + ] }, { "name": "- (Foreign key ID: 0)", @@ -243,42 +209,32 @@ { "name": "user_options", "type": "table", - "comment": "", "columns": [ { "name": "id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "user_id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "email", "type": "TEXT", - "nullable": false, - "default": null, - "comment": "" + "nullable": false } ], - "indexes": [], "constraints": [ { "name": "id", "type": "PRIMARY KEY", "def": "PRIMARY KEY (id)", "table": "user_options", - "referenced_table": null, "columns": [ "id" - ], - "referenced_columns": null + ] }, { "name": "- (Foreign key ID: 0)", @@ -294,7 +250,6 @@ ] } ], - "triggers": [], "def": "CREATE TABLE user_options (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n user_id INTEGER NOT NULL,\n email TEXT NOT NULL,\n CONSTRAINT user_options_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE\n)", "labels": [ { @@ -310,38 +265,29 @@ { "name": "schema_migrations", "type": "table", - "comment": "", "columns": [ { "name": "id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "name", "type": "TEXT", - "nullable": false, - "default": null, - "comment": "" + "nullable": false } ], - "indexes": [], "constraints": [ { "name": "id", "type": "PRIMARY KEY", "def": "PRIMARY KEY (id)", "table": "schema_migrations", - "referenced_table": null, "columns": [ "id" - ], - "referenced_columns": null + ] } ], - "triggers": [], "def": "CREATE TABLE schema_migrations (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n name TEXT NOT NULL\n)" } ], @@ -389,7 +335,6 @@ "virtual": false } ], - "functions": null, "driver": { "name": "sqlite", "database_version": "3.39.4", diff --git a/testdata/modify_schema_mod_name_and_desc.golden b/testdata/modify_schema_mod_name_and_desc.golden index 8a7cf498..91623405 100644 --- a/testdata/modify_schema_mod_name_and_desc.golden +++ b/testdata/modify_schema_mod_name_and_desc.golden @@ -5,21 +5,16 @@ { "name": "users", "type": "table", - "comment": "", "columns": [ { "name": "id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "username", "type": "TEXT", - "nullable": false, - "default": null, - "comment": "" + "nullable": false } ], "indexes": [ @@ -38,36 +33,29 @@ "type": "PRIMARY KEY", "def": "PRIMARY KEY (id)", "table": "users", - "referenced_table": null, "columns": [ "id" - ], - "referenced_columns": null + ] }, { "name": "sqlite_autoindex_users_1", "type": "UNIQUE", "def": "UNIQUE (username)", "table": "users", - "referenced_table": null, "columns": [ "username" - ], - "referenced_columns": null + ] }, { "name": "-", "type": "CHECK", "def": "CHECK(length(username) \u003e 4)", "table": "users", - "referenced_table": null, "columns": [ "username" - ], - "referenced_columns": null + ] } ], - "triggers": [], "def": "CREATE TABLE users (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n username TEXT UNIQUE NOT NULL CHECK(length(username) \u003e 4)\n)", "labels": [ { @@ -79,21 +67,16 @@ { "name": "categories", "type": "table", - "comment": "", "columns": [ { "name": "id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "name", "type": "TEXT", - "nullable": false, - "default": null, - "comment": "" + "nullable": false } ], "indexes": [ @@ -112,25 +95,20 @@ "type": "PRIMARY KEY", "def": "PRIMARY KEY (id)", "table": "categories", - "referenced_table": null, "columns": [ "id" - ], - "referenced_columns": null + ] }, { "name": "sqlite_autoindex_categories_1", "type": "UNIQUE", "def": "UNIQUE (name)", "table": "categories", - "referenced_table": null, "columns": [ "name" - ], - "referenced_columns": null + ] } ], - "triggers": [], "def": "CREATE TABLE categories (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n name TEXT UNIQUE NOT NULL\n)", "labels": [ { @@ -146,35 +124,26 @@ { "name": "posts", "type": "table", - "comment": "", "columns": [ { "name": "id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "user_id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "category_id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "title", "type": "TEXT", - "nullable": false, - "default": null, - "comment": "" + "nullable": false } ], "indexes": [ @@ -193,11 +162,9 @@ "type": "PRIMARY KEY", "def": "PRIMARY KEY (id)", "table": "posts", - "referenced_table": null, "columns": [ "id" - ], - "referenced_columns": null + ] }, { "name": "- (Foreign key ID: 0)", @@ -243,42 +210,32 @@ { "name": "user_options", "type": "table", - "comment": "", "columns": [ { "name": "id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "user_id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "email", "type": "TEXT", - "nullable": false, - "default": null, - "comment": "" + "nullable": false } ], - "indexes": [], "constraints": [ { "name": "id", "type": "PRIMARY KEY", "def": "PRIMARY KEY (id)", "table": "user_options", - "referenced_table": null, "columns": [ "id" - ], - "referenced_columns": null + ] }, { "name": "- (Foreign key ID: 0)", @@ -294,7 +251,6 @@ ] } ], - "triggers": [], "def": "CREATE TABLE user_options (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n user_id INTEGER NOT NULL,\n email TEXT NOT NULL,\n CONSTRAINT user_options_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE\n)", "labels": [ { @@ -310,38 +266,29 @@ { "name": "schema_migrations", "type": "table", - "comment": "", "columns": [ { "name": "id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "name", "type": "TEXT", - "nullable": false, - "default": null, - "comment": "" + "nullable": false } ], - "indexes": [], "constraints": [ { "name": "id", "type": "PRIMARY KEY", "def": "PRIMARY KEY (id)", "table": "schema_migrations", - "referenced_table": null, "columns": [ "id" - ], - "referenced_columns": null + ] } ], - "triggers": [], "def": "CREATE TABLE schema_migrations (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n name TEXT NOT NULL\n)" } ], @@ -389,7 +336,6 @@ "virtual": false } ], - "functions": null, "driver": { "name": "sqlite", "database_version": "3.39.4", diff --git a/testdata/modify_schema_not_override.golden b/testdata/modify_schema_not_override.golden index bc9a74d6..67496341 100644 --- a/testdata/modify_schema_not_override.golden +++ b/testdata/modify_schema_not_override.golden @@ -1,25 +1,19 @@ { "name": "not_override", - "desc": "", "tables": [ { "name": "users", "type": "table", - "comment": "", "columns": [ { "name": "id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "username", "type": "TEXT", - "nullable": false, - "default": null, - "comment": "" + "nullable": false } ], "indexes": [ @@ -38,36 +32,29 @@ "type": "PRIMARY KEY", "def": "PRIMARY KEY (id)", "table": "users", - "referenced_table": null, "columns": [ "id" - ], - "referenced_columns": null + ] }, { "name": "sqlite_autoindex_users_1", "type": "UNIQUE", "def": "UNIQUE (username)", "table": "users", - "referenced_table": null, "columns": [ "username" - ], - "referenced_columns": null + ] }, { "name": "-", "type": "CHECK", "def": "CHECK(length(username) \u003e 4)", "table": "users", - "referenced_table": null, "columns": [ "username" - ], - "referenced_columns": null + ] } ], - "triggers": [], "def": "CREATE TABLE users (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n username TEXT UNIQUE NOT NULL CHECK(length(username) \u003e 4)\n)", "labels": [ { @@ -79,21 +66,16 @@ { "name": "categories", "type": "table", - "comment": "", "columns": [ { "name": "id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "name", "type": "TEXT", - "nullable": false, - "default": null, - "comment": "" + "nullable": false } ], "indexes": [ @@ -112,25 +94,20 @@ "type": "PRIMARY KEY", "def": "PRIMARY KEY (id)", "table": "categories", - "referenced_table": null, "columns": [ "id" - ], - "referenced_columns": null + ] }, { "name": "sqlite_autoindex_categories_1", "type": "UNIQUE", "def": "UNIQUE (name)", "table": "categories", - "referenced_table": null, "columns": [ "name" - ], - "referenced_columns": null + ] } ], - "triggers": [], "def": "CREATE TABLE categories (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n name TEXT UNIQUE NOT NULL\n)", "labels": [ { @@ -146,35 +123,26 @@ { "name": "posts", "type": "table", - "comment": "", "columns": [ { "name": "id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "user_id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "category_id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "title", "type": "TEXT", - "nullable": false, - "default": null, - "comment": "" + "nullable": false } ], "indexes": [ @@ -193,11 +161,9 @@ "type": "PRIMARY KEY", "def": "PRIMARY KEY (id)", "table": "posts", - "referenced_table": null, "columns": [ "id" - ], - "referenced_columns": null + ] }, { "name": "- (Foreign key ID: 0)", @@ -243,42 +209,32 @@ { "name": "user_options", "type": "table", - "comment": "", "columns": [ { "name": "id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "user_id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "email", "type": "TEXT", - "nullable": false, - "default": null, - "comment": "" + "nullable": false } ], - "indexes": [], "constraints": [ { "name": "id", "type": "PRIMARY KEY", "def": "PRIMARY KEY (id)", "table": "user_options", - "referenced_table": null, "columns": [ "id" - ], - "referenced_columns": null + ] }, { "name": "- (Foreign key ID: 0)", @@ -294,7 +250,6 @@ ] } ], - "triggers": [], "def": "CREATE TABLE user_options (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n user_id INTEGER NOT NULL,\n email TEXT NOT NULL,\n CONSTRAINT user_options_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE\n)", "labels": [ { @@ -310,38 +265,29 @@ { "name": "schema_migrations", "type": "table", - "comment": "", "columns": [ { "name": "id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "name", "type": "TEXT", - "nullable": false, - "default": null, - "comment": "" + "nullable": false } ], - "indexes": [], "constraints": [ { "name": "id", "type": "PRIMARY KEY", "def": "PRIMARY KEY (id)", "table": "schema_migrations", - "referenced_table": null, "columns": [ "id" - ], - "referenced_columns": null + ] } ], - "triggers": [], "def": "CREATE TABLE schema_migrations (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n name TEXT NOT NULL\n)" } ], @@ -403,7 +349,6 @@ "virtual": true } ], - "functions": null, "driver": { "name": "sqlite", "database_version": "3.39.4", diff --git a/testdata/modify_schema_override.golden b/testdata/modify_schema_override.golden index 216fdd2d..42178132 100644 --- a/testdata/modify_schema_override.golden +++ b/testdata/modify_schema_override.golden @@ -1,25 +1,19 @@ { "name": "override", - "desc": "", "tables": [ { "name": "users", "type": "table", - "comment": "", "columns": [ { "name": "id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "username", "type": "TEXT", - "nullable": false, - "default": null, - "comment": "" + "nullable": false } ], "indexes": [ @@ -38,36 +32,29 @@ "type": "PRIMARY KEY", "def": "PRIMARY KEY (id)", "table": "users", - "referenced_table": null, "columns": [ "id" - ], - "referenced_columns": null + ] }, { "name": "sqlite_autoindex_users_1", "type": "UNIQUE", "def": "UNIQUE (username)", "table": "users", - "referenced_table": null, "columns": [ "username" - ], - "referenced_columns": null + ] }, { "name": "-", "type": "CHECK", "def": "CHECK(length(username) \u003e 4)", "table": "users", - "referenced_table": null, "columns": [ "username" - ], - "referenced_columns": null + ] } ], - "triggers": [], "def": "CREATE TABLE users (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n username TEXT UNIQUE NOT NULL CHECK(length(username) \u003e 4)\n)", "labels": [ { @@ -79,21 +66,16 @@ { "name": "categories", "type": "table", - "comment": "", "columns": [ { "name": "id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "name", "type": "TEXT", - "nullable": false, - "default": null, - "comment": "" + "nullable": false } ], "indexes": [ @@ -112,25 +94,20 @@ "type": "PRIMARY KEY", "def": "PRIMARY KEY (id)", "table": "categories", - "referenced_table": null, "columns": [ "id" - ], - "referenced_columns": null + ] }, { "name": "sqlite_autoindex_categories_1", "type": "UNIQUE", "def": "UNIQUE (name)", "table": "categories", - "referenced_table": null, "columns": [ "name" - ], - "referenced_columns": null + ] } ], - "triggers": [], "def": "CREATE TABLE categories (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n name TEXT UNIQUE NOT NULL\n)", "labels": [ { @@ -146,35 +123,26 @@ { "name": "posts", "type": "table", - "comment": "", "columns": [ { "name": "id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "user_id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "category_id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "title", "type": "TEXT", - "nullable": false, - "default": null, - "comment": "" + "nullable": false } ], "indexes": [ @@ -193,11 +161,9 @@ "type": "PRIMARY KEY", "def": "PRIMARY KEY (id)", "table": "posts", - "referenced_table": null, "columns": [ "id" - ], - "referenced_columns": null + ] }, { "name": "- (Foreign key ID: 0)", @@ -243,42 +209,32 @@ { "name": "user_options", "type": "table", - "comment": "", "columns": [ { "name": "id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "user_id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "email", "type": "TEXT", - "nullable": false, - "default": null, - "comment": "" + "nullable": false } ], - "indexes": [], "constraints": [ { "name": "id", "type": "PRIMARY KEY", "def": "PRIMARY KEY (id)", "table": "user_options", - "referenced_table": null, "columns": [ "id" - ], - "referenced_columns": null + ] }, { "name": "- (Foreign key ID: 0)", @@ -294,7 +250,6 @@ ] } ], - "triggers": [], "def": "CREATE TABLE user_options (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n user_id INTEGER NOT NULL,\n email TEXT NOT NULL,\n CONSTRAINT user_options_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE\n)", "labels": [ { @@ -310,38 +265,29 @@ { "name": "schema_migrations", "type": "table", - "comment": "", "columns": [ { "name": "id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "name", "type": "TEXT", - "nullable": false, - "default": null, - "comment": "" + "nullable": false } ], - "indexes": [], "constraints": [ { "name": "id", "type": "PRIMARY KEY", "def": "PRIMARY KEY (id)", "table": "schema_migrations", - "referenced_table": null, "columns": [ "id" - ], - "referenced_columns": null + ] } ], - "triggers": [], "def": "CREATE TABLE schema_migrations (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n name TEXT NOT NULL\n)" } ], @@ -389,7 +335,6 @@ "virtual": false } ], - "functions": null, "driver": { "name": "sqlite", "database_version": "3.39.4", diff --git a/testdata/modify_schema_relations.golden b/testdata/modify_schema_relations.golden index c0f20d58..4d9424b2 100644 --- a/testdata/modify_schema_relations.golden +++ b/testdata/modify_schema_relations.golden @@ -1,25 +1,19 @@ { "name": "relations", - "desc": "", "tables": [ { "name": "users", "type": "table", - "comment": "", "columns": [ { "name": "id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "username", "type": "TEXT", - "nullable": false, - "default": null, - "comment": "" + "nullable": false } ], "indexes": [ @@ -38,36 +32,29 @@ "type": "PRIMARY KEY", "def": "PRIMARY KEY (id)", "table": "users", - "referenced_table": null, "columns": [ "id" - ], - "referenced_columns": null + ] }, { "name": "sqlite_autoindex_users_1", "type": "UNIQUE", "def": "UNIQUE (username)", "table": "users", - "referenced_table": null, "columns": [ "username" - ], - "referenced_columns": null + ] }, { "name": "-", "type": "CHECK", "def": "CHECK(length(username) \u003e 4)", "table": "users", - "referenced_table": null, "columns": [ "username" - ], - "referenced_columns": null + ] } ], - "triggers": [], "def": "CREATE TABLE users (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n username TEXT UNIQUE NOT NULL CHECK(length(username) \u003e 4)\n)", "labels": [ { @@ -79,21 +66,16 @@ { "name": "categories", "type": "table", - "comment": "", "columns": [ { "name": "id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "name", "type": "TEXT", - "nullable": false, - "default": null, - "comment": "" + "nullable": false } ], "indexes": [ @@ -112,25 +94,20 @@ "type": "PRIMARY KEY", "def": "PRIMARY KEY (id)", "table": "categories", - "referenced_table": null, "columns": [ "id" - ], - "referenced_columns": null + ] }, { "name": "sqlite_autoindex_categories_1", "type": "UNIQUE", "def": "UNIQUE (name)", "table": "categories", - "referenced_table": null, "columns": [ "name" - ], - "referenced_columns": null + ] } ], - "triggers": [], "def": "CREATE TABLE categories (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n name TEXT UNIQUE NOT NULL\n)", "labels": [ { @@ -146,35 +123,26 @@ { "name": "posts", "type": "table", - "comment": "", "columns": [ { "name": "id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "user_id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "category_id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "title", "type": "TEXT", - "nullable": false, - "default": null, - "comment": "" + "nullable": false } ], "indexes": [ @@ -193,11 +161,9 @@ "type": "PRIMARY KEY", "def": "PRIMARY KEY (id)", "table": "posts", - "referenced_table": null, "columns": [ "id" - ], - "referenced_columns": null + ] }, { "name": "- (Foreign key ID: 0)", @@ -243,42 +209,32 @@ { "name": "user_options", "type": "table", - "comment": "", "columns": [ { "name": "id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "user_id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "email", "type": "TEXT", - "nullable": false, - "default": null, - "comment": "" + "nullable": false } ], - "indexes": [], "constraints": [ { "name": "id", "type": "PRIMARY KEY", "def": "PRIMARY KEY (id)", "table": "user_options", - "referenced_table": null, "columns": [ "id" - ], - "referenced_columns": null + ] }, { "name": "- (Foreign key ID: 0)", @@ -294,7 +250,6 @@ ] } ], - "triggers": [], "def": "CREATE TABLE user_options (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n user_id INTEGER NOT NULL,\n email TEXT NOT NULL,\n CONSTRAINT user_options_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE\n)", "labels": [ { @@ -310,38 +265,29 @@ { "name": "schema_migrations", "type": "table", - "comment": "", "columns": [ { "name": "id", "type": "INTEGER", - "nullable": false, - "default": null, - "comment": "" + "nullable": false }, { "name": "name", "type": "TEXT", - "nullable": false, - "default": null, - "comment": "" + "nullable": false } ], - "indexes": [], "constraints": [ { "name": "id", "type": "PRIMARY KEY", "def": "PRIMARY KEY (id)", "table": "schema_migrations", - "referenced_table": null, "columns": [ "id" - ], - "referenced_columns": null + ] } ], - "triggers": [], "def": "CREATE TABLE schema_migrations (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n name TEXT NOT NULL\n)" } ], @@ -403,7 +349,6 @@ "virtual": true } ], - "functions": null, "driver": { "name": "sqlite", "database_version": "3.39.4", diff --git a/testdata/yaml_output_schema.golden b/testdata/yaml_output_schema.golden index 09ffd6de..6b6ba818 100644 --- a/testdata/yaml_output_schema.golden +++ b/testdata/yaml_output_schema.golden @@ -7,12 +7,10 @@ tables: - name: a type: INTEGER nullable: false - default: null comment: column a - name: a2 type: TEXT nullable: false - default: null comment: column a2 indexes: - name: PRIMARY KEY @@ -25,13 +23,10 @@ tables: type: "" def: PRIMARY KEY (a) table: a - referencedTable: null columns: [] - referencedColumns: [] triggers: - name: update_a_a2 def: CREATE CONSTRAINT TRIGGER update_a_a2 AFTER INSERT OR UPDATE ON a - def: "" labels: - name: blue virtual: false @@ -44,17 +39,11 @@ tables: - name: b type: INTEGER nullable: false - default: null comment: column b - name: b2 type: TEXT nullable: false - default: null comment: column b2 - indexes: [] - constraints: [] - triggers: [] - def: "" labels: - name: red virtual: false @@ -67,11 +56,7 @@ tables: - name: view_column type: INTEGER nullable: false - default: null comment: column of view - indexes: [] - constraints: [] - triggers: [] def: CREATE VIEW view AS SELECT a, b FROM a JOIN b ON a.a = b.b referencedTables: - a From a423bd5562a3a796e246595945ea8830353ab1f5 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Fri, 24 Jan 2025 00:37:20 +0900 Subject: [PATCH 05/13] fix: bonsai --- sample/adjust/README.md | 2 +- sample/adjust/schema.json | 2 +- sample/postgres/README.md | 2 +- sample/postgres/schema.json | 2 +- sample/postgres95/schema.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sample/adjust/README.md b/sample/adjust/README.md index b599b32d..699dc4b1 100644 --- a/sample/adjust/README.md +++ b/sample/adjust/README.md @@ -36,7 +36,6 @@ Sample PostgreSQL database document. | Name | ReturnType | Arguments | Type | | ------------------------- | ---------- | ------------------------- | --------- | -| public.reset_comment | void | IN comment_id integer | PROCEDURE | | public.uuid_nil | uuid | | FUNCTION | | public.uuid_ns_dns | uuid | | FUNCTION | | public.uuid_ns_url | uuid | | FUNCTION | @@ -48,6 +47,7 @@ Sample PostgreSQL database document. | public.uuid_generate_v4 | uuid | | FUNCTION | | public.uuid_generate_v5 | uuid | namespace uuid, name text | FUNCTION | | public.update_updated | trigger | | FUNCTION | +| public.reset_comment | void | IN comment_id integer | PROCEDURE | ## Enums diff --git a/sample/adjust/schema.json b/sample/adjust/schema.json index 1339f542..ac529da7 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},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"users_pkey","def":"CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)","table":"public.users","columns":["id"]},{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)","table":"public.users","columns":["username"]},{"name":"users_email_key","def":"CREATE UNIQUE INDEX users_email_key ON public.users USING btree (email)","table":"public.users","columns":["email"]}],"constraints":[{"name":"users_username_check","type":"CHECK","def":"CHECK ((char_length((username)::text) \u003e 4))","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.users","referenced_table":"","columns":["id"]},{"name":"users_username_key","type":"UNIQUE","def":"UNIQUE (username)","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_email_key","type":"UNIQUE","def":"UNIQUE (email)","table":"public.users","referenced_table":"","columns":["email"]}],"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"}]},{"name":"public.user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"integer","nullable":false},{"name":"show_email","type":"boolean","nullable":false,"default":"false","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}]},{"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},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'::character varying","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"post_types","nullable":false,"comment":"public/private/draft"},{"name":"labels","type":"varchar(50)[]","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CREATE UNIQUE INDEX posts_id_pk ON public.posts USING btree (id)","table":"public.posts","columns":["id"]},{"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":["user_id","title"]},{"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"]},{"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"]},{"name":"posts_user_id_title_key","type":"UNIQUE","def":"UNIQUE (user_id, title)","table":"public.posts","referenced_table":"","columns":["user_id","title"]}],"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"}]},{"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},{"name":"user_id","type":"integer","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (post_id * '-1'::integer) STORED"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CREATE UNIQUE INDEX comments_id_pk ON public.comments USING btree (id)","table":"public.comments","columns":["id"]},{"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"]},{"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"]}],"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"]},{"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"]},{"name":"comments_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.comments","referenced_table":"","columns":["id"]},{"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"]}]},{"name":"public.comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"user_id","type":"integer","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"integer","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","table":"public.comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id)","table":"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"]},{"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"]}]},{"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},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"uuid","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false}]},{"name":"public.post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"timestamp without time zone","nullable":true,"comment":"comments.created"},{"name":"updated","type":"timestamp without time zone","nullable":true,"comment":"comments.updated"}],"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","columns":[{"name":"id","type":"uuid","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"comment_star_user","type":"varchar(50)","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false}],"indexes":[{"name":"CamelizeTable_id_key","def":"CREATE UNIQUE INDEX \"CamelizeTable_id_key\" ON public.\"CamelizeTable\" USING btree (id)","table":"public.CamelizeTable","columns":["id"]}],"constraints":[{"name":"CamelizeTable_id_key","type":"UNIQUE","def":"UNIQUE (id)","table":"public.CamelizeTable","referenced_table":"","columns":["id"]}]},{"name":"public.hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"hyphen-column","type":"text","nullable":false},{"name":"CamelizeTableId","type":"uuid","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false}],"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"]}],"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"]},{"name":"hyphen-table_hyphen-column_key","type":"UNIQUE","def":"UNIQUE (\"hyphen-column\")","table":"public.hyphen-table","referenced_table":"","columns":["hyphen-column"]}]},{"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},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON administrator.blogs USING btree (id)","table":"administrator.blogs","columns":["id"]}],"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"]},{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"administrator.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blogs","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blogs_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false},{"name":"dump","type":"text","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON backup.blogs USING btree (id)","table":"backup.blogs","columns":["id"]}],"constraints":[{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blog_options","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blog_options_id_seq'::regclass)","comment":""},{"name":"blog_id","type":"integer","nullable":false},{"name":"label","type":"text","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}],"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"]},{"name":"blog_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blog_options","referenced_table":"","columns":["id"]}]},{"name":"time.bar","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"indexes":[{"name":"bar_pkey","def":"CREATE UNIQUE INDEX bar_pkey ON \"time\".bar USING btree (id)","table":"time.bar","columns":["id"]}],"constraints":[{"name":"bar_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.bar","referenced_table":"","columns":["id"]}]},{"name":"time.hyphenated-table","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"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"]}],"constraints":[{"name":"hyphenated-table_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.hyphenated-table","referenced_table":"","columns":["id"]}]},{"name":"time.referencing","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false},{"name":"bar_id","type":"integer","nullable":false},{"name":"ht_id","type":"integer","nullable":false}],"indexes":[{"name":"referencing_pkey","def":"CREATE UNIQUE INDEX referencing_pkey ON \"time\".referencing USING btree (id)","table":"time.referencing","columns":["id"]}],"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"]},{"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"]},{"name":"referencing_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.referencing","referenced_table":"","columns":["id"]}]}],"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.reset_comment","return_type":"void","arguments":"IN comment_id integer","type":"PROCEDURE"},{"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"}],"enums":[{"name":"public.post_types","values":["draft","private","public"]}],"driver":{"name":"postgres","database_version":"PostgreSQL 15.10 (Debian 15.10-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit","meta":{"current_schema":"public","search_paths":["postgres","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}},"viewpoints":[{"name":"post","desc":"for post","tables":["public.post*"]},{"name":"administrator","desc":"administrator schema only","tables":["administrator.*"]}]} +{"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},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"users_pkey","def":"CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)","table":"public.users","columns":["id"]},{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)","table":"public.users","columns":["username"]},{"name":"users_email_key","def":"CREATE UNIQUE INDEX users_email_key ON public.users USING btree (email)","table":"public.users","columns":["email"]}],"constraints":[{"name":"users_username_check","type":"CHECK","def":"CHECK ((char_length((username)::text) \u003e 4))","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.users","referenced_table":"","columns":["id"]},{"name":"users_username_key","type":"UNIQUE","def":"UNIQUE (username)","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_email_key","type":"UNIQUE","def":"UNIQUE (email)","table":"public.users","referenced_table":"","columns":["email"]}],"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"}]},{"name":"public.user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"integer","nullable":false},{"name":"show_email","type":"boolean","nullable":false,"default":"false","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}]},{"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},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'::character varying","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"post_types","nullable":false,"comment":"public/private/draft"},{"name":"labels","type":"varchar(50)[]","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CREATE UNIQUE INDEX posts_id_pk ON public.posts USING btree (id)","table":"public.posts","columns":["id"]},{"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":["user_id","title"]},{"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"]},{"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"]},{"name":"posts_user_id_title_key","type":"UNIQUE","def":"UNIQUE (user_id, title)","table":"public.posts","referenced_table":"","columns":["user_id","title"]}],"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"}]},{"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},{"name":"user_id","type":"integer","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (post_id * '-1'::integer) STORED"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CREATE UNIQUE INDEX comments_id_pk ON public.comments USING btree (id)","table":"public.comments","columns":["id"]},{"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"]},{"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"]}],"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"]},{"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"]},{"name":"comments_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.comments","referenced_table":"","columns":["id"]},{"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"]}]},{"name":"public.comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"user_id","type":"integer","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"integer","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","table":"public.comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id)","table":"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"]},{"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"]}]},{"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},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"uuid","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false}]},{"name":"public.post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"timestamp without time zone","nullable":true,"comment":"comments.created"},{"name":"updated","type":"timestamp without time zone","nullable":true,"comment":"comments.updated"}],"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","columns":[{"name":"id","type":"uuid","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"comment_star_user","type":"varchar(50)","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false}],"indexes":[{"name":"CamelizeTable_id_key","def":"CREATE UNIQUE INDEX \"CamelizeTable_id_key\" ON public.\"CamelizeTable\" USING btree (id)","table":"public.CamelizeTable","columns":["id"]}],"constraints":[{"name":"CamelizeTable_id_key","type":"UNIQUE","def":"UNIQUE (id)","table":"public.CamelizeTable","referenced_table":"","columns":["id"]}]},{"name":"public.hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"hyphen-column","type":"text","nullable":false},{"name":"CamelizeTableId","type":"uuid","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false}],"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"]}],"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"]},{"name":"hyphen-table_hyphen-column_key","type":"UNIQUE","def":"UNIQUE (\"hyphen-column\")","table":"public.hyphen-table","referenced_table":"","columns":["hyphen-column"]}]},{"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},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON administrator.blogs USING btree (id)","table":"administrator.blogs","columns":["id"]}],"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"]},{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"administrator.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blogs","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blogs_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false},{"name":"dump","type":"text","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON backup.blogs USING btree (id)","table":"backup.blogs","columns":["id"]}],"constraints":[{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blog_options","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blog_options_id_seq'::regclass)","comment":""},{"name":"blog_id","type":"integer","nullable":false},{"name":"label","type":"text","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}],"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"]},{"name":"blog_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blog_options","referenced_table":"","columns":["id"]}]},{"name":"time.bar","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"indexes":[{"name":"bar_pkey","def":"CREATE UNIQUE INDEX bar_pkey ON \"time\".bar USING btree (id)","table":"time.bar","columns":["id"]}],"constraints":[{"name":"bar_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.bar","referenced_table":"","columns":["id"]}]},{"name":"time.hyphenated-table","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"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"]}],"constraints":[{"name":"hyphenated-table_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.hyphenated-table","referenced_table":"","columns":["id"]}]},{"name":"time.referencing","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false},{"name":"bar_id","type":"integer","nullable":false},{"name":"ht_id","type":"integer","nullable":false}],"indexes":[{"name":"referencing_pkey","def":"CREATE UNIQUE INDEX referencing_pkey ON \"time\".referencing USING btree (id)","table":"time.referencing","columns":["id"]}],"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"]},{"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"]},{"name":"referencing_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.referencing","referenced_table":"","columns":["id"]}]}],"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"}],"enums":[{"name":"public.post_types","values":["draft","private","public"]}],"driver":{"name":"postgres","database_version":"PostgreSQL 15.10 (Debian 15.10-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit","meta":{"current_schema":"public","search_paths":["postgres","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}},"viewpoints":[{"name":"post","desc":"for post","tables":["public.post*"]},{"name":"administrator","desc":"administrator schema only","tables":["administrator.*"]}]} diff --git a/sample/postgres/README.md b/sample/postgres/README.md index c9f150f2..c2e9124a 100644 --- a/sample/postgres/README.md +++ b/sample/postgres/README.md @@ -36,7 +36,6 @@ Sample PostgreSQL database document. | Name | ReturnType | Arguments | Type | | ---- | ------- | ------- | ---- | -| public.reset_comment | void | IN comment_id integer | PROCEDURE | | public.uuid_nil | uuid | | FUNCTION | | public.uuid_ns_dns | uuid | | FUNCTION | | public.uuid_ns_url | uuid | | FUNCTION | @@ -48,6 +47,7 @@ Sample PostgreSQL database document. | public.uuid_generate_v4 | uuid | | FUNCTION | | public.uuid_generate_v5 | uuid | namespace uuid, name text | FUNCTION | | public.update_updated | trigger | | FUNCTION | +| public.reset_comment | void | IN comment_id integer | PROCEDURE | ## Enums diff --git a/sample/postgres/schema.json b/sample/postgres/schema.json index 1339f542..ac529da7 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},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"users_pkey","def":"CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)","table":"public.users","columns":["id"]},{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)","table":"public.users","columns":["username"]},{"name":"users_email_key","def":"CREATE UNIQUE INDEX users_email_key ON public.users USING btree (email)","table":"public.users","columns":["email"]}],"constraints":[{"name":"users_username_check","type":"CHECK","def":"CHECK ((char_length((username)::text) \u003e 4))","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.users","referenced_table":"","columns":["id"]},{"name":"users_username_key","type":"UNIQUE","def":"UNIQUE (username)","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_email_key","type":"UNIQUE","def":"UNIQUE (email)","table":"public.users","referenced_table":"","columns":["email"]}],"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"}]},{"name":"public.user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"integer","nullable":false},{"name":"show_email","type":"boolean","nullable":false,"default":"false","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}]},{"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},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'::character varying","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"post_types","nullable":false,"comment":"public/private/draft"},{"name":"labels","type":"varchar(50)[]","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CREATE UNIQUE INDEX posts_id_pk ON public.posts USING btree (id)","table":"public.posts","columns":["id"]},{"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":["user_id","title"]},{"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"]},{"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"]},{"name":"posts_user_id_title_key","type":"UNIQUE","def":"UNIQUE (user_id, title)","table":"public.posts","referenced_table":"","columns":["user_id","title"]}],"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"}]},{"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},{"name":"user_id","type":"integer","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (post_id * '-1'::integer) STORED"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CREATE UNIQUE INDEX comments_id_pk ON public.comments USING btree (id)","table":"public.comments","columns":["id"]},{"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"]},{"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"]}],"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"]},{"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"]},{"name":"comments_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.comments","referenced_table":"","columns":["id"]},{"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"]}]},{"name":"public.comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"user_id","type":"integer","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"integer","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","table":"public.comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id)","table":"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"]},{"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"]}]},{"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},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"uuid","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false}]},{"name":"public.post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"timestamp without time zone","nullable":true,"comment":"comments.created"},{"name":"updated","type":"timestamp without time zone","nullable":true,"comment":"comments.updated"}],"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","columns":[{"name":"id","type":"uuid","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"comment_star_user","type":"varchar(50)","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false}],"indexes":[{"name":"CamelizeTable_id_key","def":"CREATE UNIQUE INDEX \"CamelizeTable_id_key\" ON public.\"CamelizeTable\" USING btree (id)","table":"public.CamelizeTable","columns":["id"]}],"constraints":[{"name":"CamelizeTable_id_key","type":"UNIQUE","def":"UNIQUE (id)","table":"public.CamelizeTable","referenced_table":"","columns":["id"]}]},{"name":"public.hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"hyphen-column","type":"text","nullable":false},{"name":"CamelizeTableId","type":"uuid","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false}],"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"]}],"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"]},{"name":"hyphen-table_hyphen-column_key","type":"UNIQUE","def":"UNIQUE (\"hyphen-column\")","table":"public.hyphen-table","referenced_table":"","columns":["hyphen-column"]}]},{"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},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON administrator.blogs USING btree (id)","table":"administrator.blogs","columns":["id"]}],"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"]},{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"administrator.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blogs","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blogs_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false},{"name":"dump","type":"text","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON backup.blogs USING btree (id)","table":"backup.blogs","columns":["id"]}],"constraints":[{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blog_options","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blog_options_id_seq'::regclass)","comment":""},{"name":"blog_id","type":"integer","nullable":false},{"name":"label","type":"text","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}],"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"]},{"name":"blog_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blog_options","referenced_table":"","columns":["id"]}]},{"name":"time.bar","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"indexes":[{"name":"bar_pkey","def":"CREATE UNIQUE INDEX bar_pkey ON \"time\".bar USING btree (id)","table":"time.bar","columns":["id"]}],"constraints":[{"name":"bar_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.bar","referenced_table":"","columns":["id"]}]},{"name":"time.hyphenated-table","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"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"]}],"constraints":[{"name":"hyphenated-table_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.hyphenated-table","referenced_table":"","columns":["id"]}]},{"name":"time.referencing","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false},{"name":"bar_id","type":"integer","nullable":false},{"name":"ht_id","type":"integer","nullable":false}],"indexes":[{"name":"referencing_pkey","def":"CREATE UNIQUE INDEX referencing_pkey ON \"time\".referencing USING btree (id)","table":"time.referencing","columns":["id"]}],"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"]},{"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"]},{"name":"referencing_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.referencing","referenced_table":"","columns":["id"]}]}],"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.reset_comment","return_type":"void","arguments":"IN comment_id integer","type":"PROCEDURE"},{"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"}],"enums":[{"name":"public.post_types","values":["draft","private","public"]}],"driver":{"name":"postgres","database_version":"PostgreSQL 15.10 (Debian 15.10-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit","meta":{"current_schema":"public","search_paths":["postgres","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}},"viewpoints":[{"name":"post","desc":"for post","tables":["public.post*"]},{"name":"administrator","desc":"administrator schema only","tables":["administrator.*"]}]} +{"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},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"users_pkey","def":"CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)","table":"public.users","columns":["id"]},{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)","table":"public.users","columns":["username"]},{"name":"users_email_key","def":"CREATE UNIQUE INDEX users_email_key ON public.users USING btree (email)","table":"public.users","columns":["email"]}],"constraints":[{"name":"users_username_check","type":"CHECK","def":"CHECK ((char_length((username)::text) \u003e 4))","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.users","referenced_table":"","columns":["id"]},{"name":"users_username_key","type":"UNIQUE","def":"UNIQUE (username)","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_email_key","type":"UNIQUE","def":"UNIQUE (email)","table":"public.users","referenced_table":"","columns":["email"]}],"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"}]},{"name":"public.user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"integer","nullable":false},{"name":"show_email","type":"boolean","nullable":false,"default":"false","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}]},{"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},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'::character varying","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"post_types","nullable":false,"comment":"public/private/draft"},{"name":"labels","type":"varchar(50)[]","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CREATE UNIQUE INDEX posts_id_pk ON public.posts USING btree (id)","table":"public.posts","columns":["id"]},{"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":["user_id","title"]},{"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"]},{"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"]},{"name":"posts_user_id_title_key","type":"UNIQUE","def":"UNIQUE (user_id, title)","table":"public.posts","referenced_table":"","columns":["user_id","title"]}],"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"}]},{"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},{"name":"user_id","type":"integer","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (post_id * '-1'::integer) STORED"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CREATE UNIQUE INDEX comments_id_pk ON public.comments USING btree (id)","table":"public.comments","columns":["id"]},{"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"]},{"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"]}],"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"]},{"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"]},{"name":"comments_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.comments","referenced_table":"","columns":["id"]},{"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"]}]},{"name":"public.comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"user_id","type":"integer","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"integer","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","table":"public.comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id)","table":"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"]},{"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"]}]},{"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},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"uuid","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false}]},{"name":"public.post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"timestamp without time zone","nullable":true,"comment":"comments.created"},{"name":"updated","type":"timestamp without time zone","nullable":true,"comment":"comments.updated"}],"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","columns":[{"name":"id","type":"uuid","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"comment_star_user","type":"varchar(50)","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false}],"indexes":[{"name":"CamelizeTable_id_key","def":"CREATE UNIQUE INDEX \"CamelizeTable_id_key\" ON public.\"CamelizeTable\" USING btree (id)","table":"public.CamelizeTable","columns":["id"]}],"constraints":[{"name":"CamelizeTable_id_key","type":"UNIQUE","def":"UNIQUE (id)","table":"public.CamelizeTable","referenced_table":"","columns":["id"]}]},{"name":"public.hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"hyphen-column","type":"text","nullable":false},{"name":"CamelizeTableId","type":"uuid","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false}],"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"]}],"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"]},{"name":"hyphen-table_hyphen-column_key","type":"UNIQUE","def":"UNIQUE (\"hyphen-column\")","table":"public.hyphen-table","referenced_table":"","columns":["hyphen-column"]}]},{"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},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON administrator.blogs USING btree (id)","table":"administrator.blogs","columns":["id"]}],"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"]},{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"administrator.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blogs","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blogs_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false},{"name":"dump","type":"text","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON backup.blogs USING btree (id)","table":"backup.blogs","columns":["id"]}],"constraints":[{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blog_options","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blog_options_id_seq'::regclass)","comment":""},{"name":"blog_id","type":"integer","nullable":false},{"name":"label","type":"text","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}],"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"]},{"name":"blog_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blog_options","referenced_table":"","columns":["id"]}]},{"name":"time.bar","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"indexes":[{"name":"bar_pkey","def":"CREATE UNIQUE INDEX bar_pkey ON \"time\".bar USING btree (id)","table":"time.bar","columns":["id"]}],"constraints":[{"name":"bar_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.bar","referenced_table":"","columns":["id"]}]},{"name":"time.hyphenated-table","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"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"]}],"constraints":[{"name":"hyphenated-table_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.hyphenated-table","referenced_table":"","columns":["id"]}]},{"name":"time.referencing","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false},{"name":"bar_id","type":"integer","nullable":false},{"name":"ht_id","type":"integer","nullable":false}],"indexes":[{"name":"referencing_pkey","def":"CREATE UNIQUE INDEX referencing_pkey ON \"time\".referencing USING btree (id)","table":"time.referencing","columns":["id"]}],"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"]},{"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"]},{"name":"referencing_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.referencing","referenced_table":"","columns":["id"]}]}],"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"}],"enums":[{"name":"public.post_types","values":["draft","private","public"]}],"driver":{"name":"postgres","database_version":"PostgreSQL 15.10 (Debian 15.10-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit","meta":{"current_schema":"public","search_paths":["postgres","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}},"viewpoints":[{"name":"post","desc":"for post","tables":["public.post*"]},{"name":"administrator","desc":"administrator schema only","tables":["administrator.*"]}]} diff --git a/sample/postgres95/schema.json b/sample/postgres95/schema.json index 559e4f41..5b3953ed 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},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"users_pkey","def":"CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)","table":"public.users","columns":["id"]},{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)","table":"public.users","columns":["username"]},{"name":"users_email_key","def":"CREATE UNIQUE INDEX users_email_key ON public.users USING btree (email)","table":"public.users","columns":["email"]}],"constraints":[{"name":"users_username_check","type":"CHECK","def":"CHECK ((char_length((username)::text) \u003e 4))","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.users","referenced_table":"","columns":["id"]},{"name":"users_username_key","type":"UNIQUE","def":"UNIQUE (username)","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_email_key","type":"UNIQUE","def":"UNIQUE (email)","table":"public.users","referenced_table":"","columns":["email"]}],"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"}]},{"name":"public.user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"integer","nullable":false},{"name":"show_email","type":"boolean","nullable":false,"default":"false","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}]},{"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},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'::character varying","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"post_types","nullable":false,"comment":"public/private/draft"},{"name":"labels","type":"varchar(50)[]","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CREATE UNIQUE INDEX posts_id_pk ON public.posts USING btree (id)","table":"public.posts","columns":["id"]},{"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":["user_id","title"]},{"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","tableoid","cmax","xmax","cmin","xmin","ctid","id","user_id","title","body","post_type","labels","created"]},{"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"]},{"name":"posts_user_id_title_key","type":"UNIQUE","def":"UNIQUE (user_id, title)","table":"public.posts","referenced_table":"","columns":["user_id","title"]}],"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"}]},{"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},{"name":"user_id","type":"integer","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CREATE UNIQUE INDEX comments_id_pk ON public.comments USING btree (id)","table":"public.comments","columns":["id"]},{"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"]},{"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"]}],"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"]},{"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"]},{"name":"comments_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.comments","referenced_table":"","columns":["id"]},{"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"]}]},{"name":"public.comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"user_id","type":"integer","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"integer","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","table":"public.comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id)","table":"public.comment_stars","referenced_table":"comments","columns":["comment_user_id","comment_post_id","comment_user_id","comment_post_id"],"referenced_columns":["post_id","user_id","user_id","post_id"]},{"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"]}]},{"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},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"uuid","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false}]},{"name":"public.post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"timestamp without time zone","nullable":true,"comment":"comments.created"},{"name":"updated","type":"timestamp without time zone","nullable":true,"comment":"comments.updated"}],"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","columns":[{"name":"id","type":"uuid","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"comment_star_user","type":"varchar(50)","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false}],"indexes":[{"name":"CamelizeTable_id_key","def":"CREATE UNIQUE INDEX \"CamelizeTable_id_key\" ON public.\"CamelizeTable\" USING btree (id)","table":"public.CamelizeTable","columns":["id"]}],"constraints":[{"name":"CamelizeTable_id_key","type":"UNIQUE","def":"UNIQUE (id)","table":"public.CamelizeTable","referenced_table":"","columns":["id"]}]},{"name":"public.hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"hyphen-column","type":"text","nullable":false},{"name":"CamelizeTableId","type":"uuid","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false}],"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"]}],"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"]},{"name":"hyphen-table_hyphen-column_key","type":"UNIQUE","def":"UNIQUE (\"hyphen-column\")","table":"public.hyphen-table","referenced_table":"","columns":["hyphen-column"]}]},{"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},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON administrator.blogs USING btree (id)","table":"administrator.blogs","columns":["id"]}],"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"]},{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"administrator.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blogs","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blogs_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false},{"name":"dump","type":"text","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON backup.blogs USING btree (id)","table":"backup.blogs","columns":["id"]}],"constraints":[{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blog_options","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blog_options_id_seq'::regclass)","comment":""},{"name":"blog_id","type":"integer","nullable":false},{"name":"label","type":"text","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}],"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"]},{"name":"blog_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blog_options","referenced_table":"","columns":["id"]}]},{"name":"time.bar","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"indexes":[{"name":"bar_pkey","def":"CREATE UNIQUE INDEX bar_pkey ON \"time\".bar USING btree (id)","table":"time.bar","columns":["id"]}],"constraints":[{"name":"bar_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.bar","referenced_table":"","columns":["id"]}]},{"name":"time.hyphenated-table","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"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"]}],"constraints":[{"name":"hyphenated-table_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.hyphenated-table","referenced_table":"","columns":["id"]}]},{"name":"time.referencing","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false},{"name":"bar_id","type":"integer","nullable":false},{"name":"ht_id","type":"integer","nullable":false}],"indexes":[{"name":"referencing_pkey","def":"CREATE UNIQUE INDEX referencing_pkey ON \"time\".referencing USING btree (id)","table":"time.referencing","columns":["id"]}],"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"]},{"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"]},{"name":"referencing_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.referencing","referenced_table":"","columns":["id"]}]}],"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"}],"enums":[{"name":"public.post_types","values":["draft","private","public"]}],"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":["postgres","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}},"viewpoints":[{"name":"post","desc":"for post","tables":["public.post*"]},{"name":"administrator","desc":"administrator schema only","tables":["administrator.*"]}]} +{"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},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"users_pkey","def":"CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)","table":"public.users","columns":["id"]},{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)","table":"public.users","columns":["username"]},{"name":"users_email_key","def":"CREATE UNIQUE INDEX users_email_key ON public.users USING btree (email)","table":"public.users","columns":["email"]}],"constraints":[{"name":"users_username_check","type":"CHECK","def":"CHECK ((char_length((username)::text) \u003e 4))","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.users","referenced_table":"","columns":["id"]},{"name":"users_username_key","type":"UNIQUE","def":"UNIQUE (username)","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_email_key","type":"UNIQUE","def":"UNIQUE (email)","table":"public.users","referenced_table":"","columns":["email"]}],"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"}]},{"name":"public.user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"integer","nullable":false},{"name":"show_email","type":"boolean","nullable":false,"default":"false","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}]},{"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},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'::character varying","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"post_types","nullable":false,"comment":"public/private/draft"},{"name":"labels","type":"varchar(50)[]","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CREATE UNIQUE INDEX posts_id_pk ON public.posts USING btree (id)","table":"public.posts","columns":["id"]},{"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":["user_id","title"]},{"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"]},{"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"]},{"name":"posts_user_id_title_key","type":"UNIQUE","def":"UNIQUE (user_id, title)","table":"public.posts","referenced_table":"","columns":["user_id","title"]}],"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"}]},{"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},{"name":"user_id","type":"integer","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CREATE UNIQUE INDEX comments_id_pk ON public.comments USING btree (id)","table":"public.comments","columns":["id"]},{"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"]},{"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"]}],"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"]},{"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"]},{"name":"comments_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.comments","referenced_table":"","columns":["id"]},{"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"]}]},{"name":"public.comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"user_id","type":"integer","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"integer","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","table":"public.comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id)","table":"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"]},{"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"]}]},{"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},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"uuid","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false}]},{"name":"public.post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"timestamp without time zone","nullable":true,"comment":"comments.created"},{"name":"updated","type":"timestamp without time zone","nullable":true,"comment":"comments.updated"}],"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","columns":[{"name":"id","type":"uuid","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"comment_star_user","type":"varchar(50)","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false}],"indexes":[{"name":"CamelizeTable_id_key","def":"CREATE UNIQUE INDEX \"CamelizeTable_id_key\" ON public.\"CamelizeTable\" USING btree (id)","table":"public.CamelizeTable","columns":["id"]}],"constraints":[{"name":"CamelizeTable_id_key","type":"UNIQUE","def":"UNIQUE (id)","table":"public.CamelizeTable","referenced_table":"","columns":["id"]}]},{"name":"public.hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"hyphen-column","type":"text","nullable":false},{"name":"CamelizeTableId","type":"uuid","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false}],"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"]}],"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"]},{"name":"hyphen-table_hyphen-column_key","type":"UNIQUE","def":"UNIQUE (\"hyphen-column\")","table":"public.hyphen-table","referenced_table":"","columns":["hyphen-column"]}]},{"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},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON administrator.blogs USING btree (id)","table":"administrator.blogs","columns":["id"]}],"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"]},{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"administrator.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blogs","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blogs_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false},{"name":"dump","type":"text","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON backup.blogs USING btree (id)","table":"backup.blogs","columns":["id"]}],"constraints":[{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blog_options","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blog_options_id_seq'::regclass)","comment":""},{"name":"blog_id","type":"integer","nullable":false},{"name":"label","type":"text","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}],"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"]},{"name":"blog_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blog_options","referenced_table":"","columns":["id"]}]},{"name":"time.bar","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"indexes":[{"name":"bar_pkey","def":"CREATE UNIQUE INDEX bar_pkey ON \"time\".bar USING btree (id)","table":"time.bar","columns":["id"]}],"constraints":[{"name":"bar_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.bar","referenced_table":"","columns":["id"]}]},{"name":"time.hyphenated-table","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"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"]}],"constraints":[{"name":"hyphenated-table_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.hyphenated-table","referenced_table":"","columns":["id"]}]},{"name":"time.referencing","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false},{"name":"bar_id","type":"integer","nullable":false},{"name":"ht_id","type":"integer","nullable":false}],"indexes":[{"name":"referencing_pkey","def":"CREATE UNIQUE INDEX referencing_pkey ON \"time\".referencing USING btree (id)","table":"time.referencing","columns":["id"]}],"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"]},{"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"]},{"name":"referencing_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.referencing","referenced_table":"","columns":["id"]}]}],"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"}],"enums":[{"name":"public.post_types","values":["draft","private","public"]}],"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":["postgres","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}},"viewpoints":[{"name":"post","desc":"for post","tables":["public.post*"]},{"name":"administrator","desc":"administrator schema only","tables":["administrator.*"]}]} From cc71a09434abd4591750c9078f6e6e8122ff0ae5 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Fri, 24 Jan 2025 00:56:48 +0900 Subject: [PATCH 06/13] fix: Set tag --- sample/detect_relations/schema.json | 2 +- sample/detect_relations_singular/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/schema.json | 2 +- sample/mssql/schema.json | 2 +- sample/mysql/schema.json | 2 +- sample/mysql56/schema.json | 2 +- sample/number/schema.json | 2 +- sample/png/schema.json | 2 +- sample/sqlite/schema.json | 2 +- sample/viewpoints/schema.json | 2 +- schema/schema.go | 4 ++-- testdata/json_output_schema.golden | 14 +++++------ testdata/modify_schema_.golden | 24 +++++++++---------- .../modify_schema_mod_name_and_desc.golden | 24 +++++++++---------- testdata/modify_schema_not_override.golden | 24 +++++++++---------- testdata/modify_schema_override.golden | 24 +++++++++---------- testdata/modify_schema_relations.golden | 24 +++++++++---------- testdata/yaml_output_schema.golden | 2 -- 22 files changed, 82 insertions(+), 86 deletions(-) diff --git a/sample/detect_relations/schema.json b/sample/detect_relations/schema.json index 79599b81..303f126d 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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"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,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`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,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL,\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},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]}],"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.4.4","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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"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,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`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,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL,\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},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]}],"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.4.4","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 47b71f04..65e562f6 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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment","type":"BASE TABLE","comment":"Comment\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"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"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comment","columns":["post_id","user_id"]}],"constraints":[{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comment","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment","columns":["id"]}],"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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_star","columns":["id"]},{"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"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_star","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_star","columns":["user_id","comment_post_id","comment_user_id"]}],"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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"log","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"log","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"log","columns":["id"]}],"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,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"post_user_id_idx","def":"KEY post_user_id_idx (id) USING BTREE","table":"post","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"post","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"post","columns":["user_id","title"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"post","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"post","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON post\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"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,"comment":"post.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"post.user.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comment.user.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comment.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comment.updated"}],"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,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"user","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"user","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"user","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"user","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"user","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"user","columns":["username"]}],"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},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_option","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_option","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_option","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_option","columns":["user_id"]},{"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"]}],"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.4.4","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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment","type":"BASE TABLE","comment":"Comment\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"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"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comment","columns":["post_id","user_id"]}],"constraints":[{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comment","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment","columns":["id"]}],"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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_star","columns":["id"]},{"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"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_star","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_star","columns":["user_id","comment_post_id","comment_user_id"]}],"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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"log","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"log","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"log","columns":["id"]}],"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,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"post_user_id_idx","def":"KEY post_user_id_idx (id) USING BTREE","table":"post","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"post","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"post","columns":["user_id","title"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"post","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"post","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON post\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"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,"comment":"post.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"post.user.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comment.user.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comment.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comment.updated"}],"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,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"user","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"user","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"user","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"user","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"user","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"user","columns":["username"]}],"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},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_option","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_option","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_option","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_option","columns":["user_id"]},{"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"]}],"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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/font/schema.json b/sample/font/schema.json index da36da3b..536d65b6 100644 --- a/sample/font/schema.json +++ b/sample/font/schema.json @@ -1 +1 @@ -{"name":"testdb","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"エントリ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"本文"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'"},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"サンプル","Virtual":true},{"Name":"tbls","Virtual":true}]} +{"name":"testdb","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"エントリ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"本文"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'"},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"サンプル","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/hide/schema.json b/sample/hide/schema.json index 51ad7513..3e1bbbdb 100644 --- a/sample/hide/schema.json +++ b/sample/hide/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"Name":"green","Virtual":true},{"Name":"red","Virtual":true},{"Name":"blue","Virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} diff --git a/sample/hide_not_related_column/schema.json b/sample/hide_not_related_column/schema.json index 5b78e785..d02b537c 100644 --- a/sample/hide_not_related_column/schema.json +++ b/sample/hide_not_related_column/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"Name":"green","Virtual":true},{"Name":"red","Virtual":true},{"Name":"blue","Virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com","labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com","labels":[{"name":"secure","virtual":true}]},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","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 f36ec1f6..1a71cacf 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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint(20)","nullable":false},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment","type":"text","nullable":false,"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},{"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"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment_post_id","type":"bigint(20)","nullable":false},{"name":"comment_user_id","type":"int(11)","nullable":false},{"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"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"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}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true,"default":"NULL","comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint(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,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":"NULL","comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS ((select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on(`p`.`id` = `c`.`post_id`)) left join `testdb`.`users` `u` on(`u`.`id` = `p`.`user_id`)) left join `testdb`.`users` `u2` on(`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"same_name_constraints","type":"BASE TABLE","columns":[{"name":"id","type":"bigint(20)","nullable":true,"default":"NULL","comment":""},{"name":"user_id","type":"int(11)","nullable":false}],"indexes":[{"name":"same_name","def":"UNIQUE KEY same_name (user_id, id) USING BTREE","table":"same_name_constraints","columns":["user_id","id"]}],"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"]},{"name":"same_name","type":"UNIQUE","def":"UNIQUE KEY same_name (user_id, id)","table":"same_name_constraints","columns":["user_id","id"]}],"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,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"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"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]}],"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},{"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"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int(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}],"driver":{"name":"mariadb","database_version":"10.5.27-MariaDB-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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint(20)","nullable":false},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment","type":"text","nullable":false,"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},{"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"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment_post_id","type":"bigint(20)","nullable":false},{"name":"comment_user_id","type":"int(11)","nullable":false},{"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"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"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}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true,"default":"NULL","comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint(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,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":"NULL","comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS ((select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on(`p`.`id` = `c`.`post_id`)) left join `testdb`.`users` `u` on(`u`.`id` = `p`.`user_id`)) left join `testdb`.`users` `u2` on(`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"same_name_constraints","type":"BASE TABLE","columns":[{"name":"id","type":"bigint(20)","nullable":true,"default":"NULL","comment":""},{"name":"user_id","type":"int(11)","nullable":false}],"indexes":[{"name":"same_name","def":"UNIQUE KEY same_name (user_id, id) USING BTREE","table":"same_name_constraints","columns":["user_id","id"]}],"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"]},{"name":"same_name","type":"UNIQUE","def":"UNIQUE KEY same_name (user_id, id)","table":"same_name_constraints","columns":["user_id","id"]}],"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,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"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"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]}],"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},{"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"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int(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}],"driver":{"name":"mariadb","database_version":"10.5.27-MariaDB-ubu2004","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/mermaid/schema.json b/sample/mermaid/schema.json index 4ab5ba50..b0a5c42b 100644 --- a/sample/mermaid/schema.json +++ b/sample/mermaid/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"Name":"green","Virtual":true},{"Name":"red","Virtual":true},{"Name":"blue","Virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com","labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com","labels":[{"name":"secure","virtual":true}]},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/mssql/schema.json b/sample/mssql/schema.json index 37d6c508..fc920a06 100644 --- a/sample/mssql/schema.json +++ b/sample/mssql/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"users","type":"BASIC TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"comment":"long long long long long long long long long long long long long long long long long long long long long description"},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"PK__users_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"users","columns":["id"]},{"name":"UQ__users_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ email ]","table":"users","columns":["email"]},{"name":"UQ__users_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ username ]","table":"users","columns":["username"]}],"constraints":[{"name":"PK__users_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"users","columns":["id"]},{"name":"UQ__users_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ email ]","table":"users","columns":["email"]},{"name":"UQ__users_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ username ]","table":"users","columns":["username"]},{"name":"CK__users__username_*","type":"CHECK","def":"CHECK(len([username])\u003e(4))","table":"users","columns":null}],"triggers":[{"name":"update_users_updated","def":"CREATE TRIGGER update_users_updated\nON users\nAFTER UPDATE\nAS\nBEGIN\n UPDATE users SET updated = GETDATE()\n WHERE id = ( SELECT id FROM deleted)\nEND;"}]},{"name":"user_options","type":"BASIC TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"bit","nullable":false,"default":"((0))","comment":""},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"PK__user_opt_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ user_id ]","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PK__user_opt_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ user_id ]","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE CASCADE","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}]},{"name":"posts","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"posts","columns":["id"]},{"name":"UQ__posts_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, title ]","table":"posts","columns":["user_id","title"]},{"name":"posts_user_id_idx","def":"NONCLUSTERED, [ user_id ]","table":"posts","columns":["user_id"]}],"constraints":[{"name":"posts_id_pk","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"posts","columns":["id"]},{"name":"UQ__posts_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, title ]","table":"posts","columns":["user_id","title"]},{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE CASCADE","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated\nON posts\nAFTER UPDATE\nAS\nBEGIN\n UPDATE users SET updated = GETDATE()\n WHERE id = ( SELECT user_id FROM deleted)\nEND;"}],"labels":[{"Name":"green","Virtual":true},{"Name":"red","Virtual":true},{"Name":"blue","Virtual":true}]},{"name":"comments","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"post_id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"comments","columns":["id"]},{"name":"UQ__comments_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"]},{"name":"comments_post_id_user_id_idx","def":"NONCLUSTERED, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_id_pk","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"comments","columns":["id"]},{"name":"UQ__comments_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"]},{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(post_id) REFERENCES posts(id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}]},{"name":"comment_stars","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"int","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"UQ__comment__*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, comment_post_id, comment_user_id ]","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"UQ__comment__*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, comment_post_id, comment_user_id ]","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]},{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(comment_user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]}]},{"name":"logs","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"int","nullable":true},{"name":"comment_id","type":"int","nullable":true},{"name":"comment_star_id","type":"int","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"date","nullable":false}]},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"int","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"date","nullable":true,"comment":"comments.created"},{"name":"updated","type":"date","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (\n SELECT c.id, p.title, u2.username AS post_user, c.comment, u2.username AS comment_user, c.created, c.updated\n FROM posts AS p\n LEFT JOIN comments AS c on p.id = c.post_id\n LEFT JOIN users AS u on u.id = p.user_id\n LEFT JOIN users AS u2 on u2.id = c.user_id\n);","referenced_tables":["posts","comments","users"]},{"name":"CamelizeTable","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"created","type":"date","nullable":false}]},{"name":"hyphen-table","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"date","nullable":false}]},{"name":"administrator.blogs","type":"BASIC TABLE","comment":"admin blogs","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"PK__blogs_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"administrator.blogs","columns":["id"]}],"constraints":[{"name":"PK__blogs_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"administrator.blogs","columns":["id"]},{"name":"blogs_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE CASCADE","table":"administrator.blogs","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}]},{"name":"name with spaces","type":"VIEW","columns":[{"name":"title","type":"varchar(255)","nullable":false}],"def":"CREATE VIEW \"name with spaces\" AS (\n SELECT TOP 1 p.title\n FROM posts AS p\n);","referenced_tables":["posts"]},{"name":"Sales.Product","type":"BASIC TABLE","columns":[{"name":"ProductID","type":"int","nullable":false},{"name":"SalesPersonID","type":"int","nullable":true}],"indexes":[{"name":"PK__Product_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ ProductID ]","table":"Sales.Product","columns":["ProductID"]},{"name":"UQ__Product_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ SalesPersonID ]","table":"Sales.Product","columns":["SalesPersonID"]}],"constraints":[{"name":"PK__Product_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ ProductID ]","table":"Sales.Product","columns":["ProductID"]},{"name":"UQ__Product_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ SalesPersonID ]","table":"Sales.Product","columns":["SalesPersonID"]}]},{"name":"Rabbits.Running","type":"BASIC TABLE","columns":[{"name":"LocationID","type":"int","nullable":false},{"name":"ProductID","type":"int","nullable":true},{"name":"EmployeeID","type":"int","nullable":true}],"indexes":[{"name":"PK__Running_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ LocationID ]","table":"Rabbits.Running","columns":["LocationID"]},{"name":"UQ__Running_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ EmployeeID ]","table":"Rabbits.Running","columns":["EmployeeID"]},{"name":"UQ__Running_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ ProductID ]","table":"Rabbits.Running","columns":["ProductID"]}],"constraints":[{"name":"PK__Running_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ LocationID ]","table":"Rabbits.Running","columns":["LocationID"]},{"name":"UQ__Running_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ EmployeeID ]","table":"Rabbits.Running","columns":["EmployeeID"]},{"name":"UQ__Running_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ ProductID ]","table":"Rabbits.Running","columns":["ProductID"]},{"name":"FK_TempSales_SalesReason","type":"FOREIGN KEY","def":"FOREIGN KEY(ProductID) REFERENCES Sales.Product(SalesPersonID) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"Rabbits.Running","referenced_table":"Sales.Product","columns":["ProductID"],"referenced_columns":["SalesPersonID"]}]}],"relations":[{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","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 2019 (RTM-CU30) (KB5049235) - 15.0.4415.2 (X64) \n\tNov 18 2024 17:45:37 \n\tCopyright (C) 2019 Microsoft Corporation\n\tDeveloper Edition (64-bit) on Linux (Ubuntu 20.04.6 LTS) \u003cX64\u003e","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"users","type":"BASIC TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"comment":"long long long long long long long long long long long long long long long long long long long long long description"},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"PK__users_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"users","columns":["id"]},{"name":"UQ__users_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ email ]","table":"users","columns":["email"]},{"name":"UQ__users_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ username ]","table":"users","columns":["username"]}],"constraints":[{"name":"PK__users_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"users","columns":["id"]},{"name":"UQ__users_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ email ]","table":"users","columns":["email"]},{"name":"UQ__users_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ username ]","table":"users","columns":["username"]},{"name":"CK__users__username_*","type":"CHECK","def":"CHECK(len([username])\u003e(4))","table":"users","columns":null}],"triggers":[{"name":"update_users_updated","def":"CREATE TRIGGER update_users_updated\nON users\nAFTER UPDATE\nAS\nBEGIN\n UPDATE users SET updated = GETDATE()\n WHERE id = ( SELECT id FROM deleted)\nEND;"}]},{"name":"user_options","type":"BASIC TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"bit","nullable":false,"default":"((0))","comment":""},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"PK__user_opt_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ user_id ]","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PK__user_opt_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ user_id ]","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE CASCADE","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}]},{"name":"posts","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"posts","columns":["id"]},{"name":"UQ__posts_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, title ]","table":"posts","columns":["user_id","title"]},{"name":"posts_user_id_idx","def":"NONCLUSTERED, [ user_id ]","table":"posts","columns":["user_id"]}],"constraints":[{"name":"posts_id_pk","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"posts","columns":["id"]},{"name":"UQ__posts_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, title ]","table":"posts","columns":["user_id","title"]},{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE CASCADE","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated\nON posts\nAFTER UPDATE\nAS\nBEGIN\n UPDATE users SET updated = GETDATE()\n WHERE id = ( SELECT user_id FROM deleted)\nEND;"}],"labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"comments","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"post_id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"comments","columns":["id"]},{"name":"UQ__comments_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"]},{"name":"comments_post_id_user_id_idx","def":"NONCLUSTERED, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_id_pk","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"comments","columns":["id"]},{"name":"UQ__comments_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"]},{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(post_id) REFERENCES posts(id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}]},{"name":"comment_stars","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"int","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"UQ__comment__*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, comment_post_id, comment_user_id ]","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"UQ__comment__*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, comment_post_id, comment_user_id ]","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]},{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(comment_user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]}]},{"name":"logs","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"int","nullable":true},{"name":"comment_id","type":"int","nullable":true},{"name":"comment_star_id","type":"int","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"date","nullable":false}]},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"int","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"date","nullable":true,"comment":"comments.created"},{"name":"updated","type":"date","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (\n SELECT c.id, p.title, u2.username AS post_user, c.comment, u2.username AS comment_user, c.created, c.updated\n FROM posts AS p\n LEFT JOIN comments AS c on p.id = c.post_id\n LEFT JOIN users AS u on u.id = p.user_id\n LEFT JOIN users AS u2 on u2.id = c.user_id\n);","referenced_tables":["posts","comments","users"]},{"name":"CamelizeTable","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"created","type":"date","nullable":false}]},{"name":"hyphen-table","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"date","nullable":false}]},{"name":"administrator.blogs","type":"BASIC TABLE","comment":"admin blogs","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"PK__blogs_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"administrator.blogs","columns":["id"]}],"constraints":[{"name":"PK__blogs_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"administrator.blogs","columns":["id"]},{"name":"blogs_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE CASCADE","table":"administrator.blogs","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}]},{"name":"name with spaces","type":"VIEW","columns":[{"name":"title","type":"varchar(255)","nullable":false}],"def":"CREATE VIEW \"name with spaces\" AS (\n SELECT TOP 1 p.title\n FROM posts AS p\n);","referenced_tables":["posts"]},{"name":"Sales.Product","type":"BASIC TABLE","columns":[{"name":"ProductID","type":"int","nullable":false},{"name":"SalesPersonID","type":"int","nullable":true}],"indexes":[{"name":"PK__Product_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ ProductID ]","table":"Sales.Product","columns":["ProductID"]},{"name":"UQ__Product_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ SalesPersonID ]","table":"Sales.Product","columns":["SalesPersonID"]}],"constraints":[{"name":"PK__Product_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ ProductID ]","table":"Sales.Product","columns":["ProductID"]},{"name":"UQ__Product_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ SalesPersonID ]","table":"Sales.Product","columns":["SalesPersonID"]}]},{"name":"Rabbits.Running","type":"BASIC TABLE","columns":[{"name":"LocationID","type":"int","nullable":false},{"name":"ProductID","type":"int","nullable":true},{"name":"EmployeeID","type":"int","nullable":true}],"indexes":[{"name":"PK__Running_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ LocationID ]","table":"Rabbits.Running","columns":["LocationID"]},{"name":"UQ__Running_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ EmployeeID ]","table":"Rabbits.Running","columns":["EmployeeID"]},{"name":"UQ__Running_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ ProductID ]","table":"Rabbits.Running","columns":["ProductID"]}],"constraints":[{"name":"PK__Running_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ LocationID ]","table":"Rabbits.Running","columns":["LocationID"]},{"name":"UQ__Running_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ EmployeeID ]","table":"Rabbits.Running","columns":["EmployeeID"]},{"name":"UQ__Running_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ ProductID ]","table":"Rabbits.Running","columns":["ProductID"]},{"name":"FK_TempSales_SalesReason","type":"FOREIGN KEY","def":"FOREIGN KEY(ProductID) REFERENCES Sales.Product(SalesPersonID) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"Rabbits.Running","referenced_table":"Sales.Product","columns":["ProductID"],"referenced_columns":["SalesPersonID"]}]}],"relations":[{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","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 2019 (RTM-CU30) (KB5049235) - 15.0.4415.2 (X64) \n\tNov 18 2024 17:45:37 \n\tCopyright (C) 2019 Microsoft Corporation\n\tDeveloper Edition (64-bit) on Linux (Ubuntu 20.04.6 LTS) \u003cX64\u003e","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/mysql/schema.json b/sample/mysql/schema.json index 4ab5ba50..b0a5c42b 100644 --- a/sample/mysql/schema.json +++ b/sample/mysql/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"Name":"green","Virtual":true},{"Name":"red","Virtual":true},{"Name":"blue","Virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com","labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com","labels":[{"name":"secure","virtual":true}]},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","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 e98b719e..f46741c8 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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment_post_id","type":"bigint(20)","nullable":false},{"name":"comment_user_id","type":"int(11)","nullable":false},{"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"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint(20)","nullable":false},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"post_id","type":"bigint(20)","nullable":true},{"name":"comment_id","type":"bigint(20)","nullable":true},{"name":"comment_star_id","type":"bigint(20)","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint(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,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS ((select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`)))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint(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},{"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"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int(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,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"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"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]}],"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}],"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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment_post_id","type":"bigint(20)","nullable":false},{"name":"comment_user_id","type":"int(11)","nullable":false},{"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"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint(20)","nullable":false},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"post_id","type":"bigint(20)","nullable":true},{"name":"comment_id","type":"bigint(20)","nullable":true},{"name":"comment_star_id","type":"bigint(20)","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint(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,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS ((select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`)))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint(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},{"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"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int(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,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"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"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]}],"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}],"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 9154a375..3dfc1329 100644 --- a/sample/number/schema.json +++ b/sample/number/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"Name":"green","Virtual":true},{"Name":"red","Virtual":true},{"Name":"blue","Virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/png/schema.json b/sample/png/schema.json index 4ab5ba50..b0a5c42b 100644 --- a/sample/png/schema.json +++ b/sample/png/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"Name":"green","Virtual":true},{"Name":"red","Virtual":true},{"Name":"blue","Virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com","labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com","labels":[{"name":"secure","virtual":true}]},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/sqlite/schema.json b/sample/sqlite/schema.json index 5040cbbb..06d41d63 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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"username","type":"TEXT","nullable":false},{"name":"password","type":"TEXT","nullable":false,"labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"TEXT","nullable":false,"labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"indexes":[{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON users(username)","table":"users","columns":["username"]},{"name":"sqlite_autoindex_users_2","def":"UNIQUE (email)","table":"users","columns":["email"]},{"name":"sqlite_autoindex_users_1","def":"UNIQUE (username)","table":"users","columns":["username"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"sqlite_autoindex_users_2","type":"UNIQUE","def":"UNIQUE (email)","table":"users","columns":["email"]},{"name":"sqlite_autoindex_users_1","type":"UNIQUE","def":"UNIQUE (username)","table":"users","columns":["username"]},{"name":"-","type":"CHECK","def":"CHECK(length(username) \u003e 4)","table":"users","columns":["username"]}],"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","columns":[{"name":"user_id","type":"INTEGER","nullable":true},{"name":"show_email","type":"INTEGER","nullable":false,"default":"0","comment":""},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"constraints":[{"name":"user_id","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"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"]}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"title","type":"TEXT","nullable":false},{"name":"body","type":"TEXT","nullable":false,"comment":"post body"},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"CREATE INDEX posts_user_id_idx ON posts(user_id)","table":"posts","columns":["user_id"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"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"]}],"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"}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"post_id","type":"INTEGER","nullable":false},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"comment","type":"TEXT","nullable":false},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"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"]},{"name":"sqlite_autoindex_comments_1","def":"UNIQUE (post_id, user_id)","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]},{"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"]},{"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"]},{"name":"sqlite_autoindex_comments_1","type":"UNIQUE","def":"UNIQUE (post_id, user_id)","table":"comments","columns":["post_id","user_id"]}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"comment_post_id","type":"INTEGER","nullable":false},{"name":"comment_user_id","type":"INTEGER","nullable":false},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"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"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"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"]},{"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"]},{"name":"sqlite_autoindex_comment_stars_1","type":"UNIQUE","def":"UNIQUE (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE comment_stars (\n id 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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"post_id","type":"INTEGER","nullable":true},{"name":"comment_id","type":"INTEGER","nullable":true},{"name":"comment_star_id","type":"INTEGER","nullable":true},{"name":"payload","type":"TEXT","nullable":true},{"name":"created","type":"NUMERIC","nullable":false}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"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,"comment":"comments.id"},{"name":"title","type":"TEXT","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"TEXT","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"TEXT","nullable":true},{"name":"comment_user","type":"TEXT","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"NUMERIC","nullable":true,"comment":"comments.created"},{"name":"updated","type":"NUMERIC","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS\n SELECT c.id, p.title, u2.username AS post_user, c.comment, u2.username AS comment_user, c.created, c.updated\n FROM posts AS p\n LEFT JOIN comments AS c on p.id = c.post_id\n LEFT JOIN users AS u on u.id = p.user_id\n LEFT JOIN users AS u2 on u2.id = c.user_id","referenced_tables":["posts","comments","users"]},{"name":"CamelizeTable","type":"table","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"created","type":"NUMERIC","nullable":false}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE CamelizeTable (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n created NUMERIC NOT NULL\n)"},{"name":"hyphen-table","type":"table","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"hyphen-column","type":"TEXT","nullable":false},{"name":"created","type":"NUMERIC","nullable":false}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"col","type":"TEXT","nullable":true},{"name":"brackets","type":"TEXT","nullable":false},{"name":"checkcheck","type":"TEXT","nullable":false},{"name":"downcase","type":"TEXT","nullable":false},{"name":"nl","type":"TEXT","nullable":false}],"indexes":[{"name":"sqlite_autoindex_check_constraints_4","def":"UNIQUE (nl)","table":"check_constraints","columns":["nl"]},{"name":"sqlite_autoindex_check_constraints_3","def":"UNIQUE (downcase)","table":"check_constraints","columns":["downcase"]},{"name":"sqlite_autoindex_check_constraints_2","def":"UNIQUE (checkcheck)","table":"check_constraints","columns":["checkcheck"]},{"name":"sqlite_autoindex_check_constraints_1","def":"UNIQUE (brackets)","table":"check_constraints","columns":["brackets"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"check_constraints","columns":["id"]},{"name":"sqlite_autoindex_check_constraints_4","type":"UNIQUE","def":"UNIQUE (nl)","table":"check_constraints","columns":["nl"]},{"name":"sqlite_autoindex_check_constraints_3","type":"UNIQUE","def":"UNIQUE (downcase)","table":"check_constraints","columns":["downcase"]},{"name":"sqlite_autoindex_check_constraints_2","type":"UNIQUE","def":"UNIQUE (checkcheck)","table":"check_constraints","columns":["checkcheck"]},{"name":"sqlite_autoindex_check_constraints_1","type":"UNIQUE","def":"UNIQUE (brackets)","table":"check_constraints","columns":["brackets"]},{"name":"-","type":"CHECK","def":"CHECK(length(col) \u003e 4)","table":"check_constraints","columns":["col"]},{"name":"-","type":"CHECK","def":"CHECK(((length(brackets) \u003e 4)))","table":"check_constraints","columns":["brackets"]},{"name":"-","type":"CHECK","def":"CHECK(length(checkcheck) \u003e 4)","table":"check_constraints","columns":["checkcheck"]},{"name":"-","type":"CHECK","def":"check(length(downcase) \u003e 4)","table":"check_constraints","columns":["downcase"]},{"name":"-","type":"CHECK","def":"check(length(nl) \u003e 4 OR nl != 'ln')","table":"check_constraints","columns":["nl"]}],"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","columns":[{"name":"logs","type":"","nullable":true}],"def":"CREATE VIRTUAL TABLE syslog USING fts3(logs)"},{"name":"access_log","type":"virtual table","columns":[{"name":"logs","type":"","nullable":true}],"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}],"driver":{"name":"sqlite","database_version":"3.46.1"},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}]} +{"name":"testdb.sqlite3","desc":"Sample database document.","tables":[{"name":"users","type":"table","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"username","type":"TEXT","nullable":false},{"name":"password","type":"TEXT","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"TEXT","nullable":false,"labels":[{"name":"secure","virtual":true}]},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"indexes":[{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON users(username)","table":"users","columns":["username"]},{"name":"sqlite_autoindex_users_2","def":"UNIQUE (email)","table":"users","columns":["email"]},{"name":"sqlite_autoindex_users_1","def":"UNIQUE (username)","table":"users","columns":["username"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"sqlite_autoindex_users_2","type":"UNIQUE","def":"UNIQUE (email)","table":"users","columns":["email"]},{"name":"sqlite_autoindex_users_1","type":"UNIQUE","def":"UNIQUE (username)","table":"users","columns":["username"]},{"name":"-","type":"CHECK","def":"CHECK(length(username) \u003e 4)","table":"users","columns":["username"]}],"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","columns":[{"name":"user_id","type":"INTEGER","nullable":true},{"name":"show_email","type":"INTEGER","nullable":false,"default":"0","comment":""},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"constraints":[{"name":"user_id","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"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"]}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"title","type":"TEXT","nullable":false},{"name":"body","type":"TEXT","nullable":false,"comment":"post body"},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"CREATE INDEX posts_user_id_idx ON posts(user_id)","table":"posts","columns":["user_id"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"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"]}],"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"}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"post_id","type":"INTEGER","nullable":false},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"comment","type":"TEXT","nullable":false},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"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"]},{"name":"sqlite_autoindex_comments_1","def":"UNIQUE (post_id, user_id)","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]},{"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"]},{"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"]},{"name":"sqlite_autoindex_comments_1","type":"UNIQUE","def":"UNIQUE (post_id, user_id)","table":"comments","columns":["post_id","user_id"]}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"comment_post_id","type":"INTEGER","nullable":false},{"name":"comment_user_id","type":"INTEGER","nullable":false},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"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"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"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"]},{"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"]},{"name":"sqlite_autoindex_comment_stars_1","type":"UNIQUE","def":"UNIQUE (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE comment_stars (\n id 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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"post_id","type":"INTEGER","nullable":true},{"name":"comment_id","type":"INTEGER","nullable":true},{"name":"comment_star_id","type":"INTEGER","nullable":true},{"name":"payload","type":"TEXT","nullable":true},{"name":"created","type":"NUMERIC","nullable":false}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"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,"comment":"comments.id"},{"name":"title","type":"TEXT","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"TEXT","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"TEXT","nullable":true},{"name":"comment_user","type":"TEXT","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"NUMERIC","nullable":true,"comment":"comments.created"},{"name":"updated","type":"NUMERIC","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS\n SELECT c.id, p.title, u2.username AS post_user, c.comment, u2.username AS comment_user, c.created, c.updated\n FROM posts AS p\n LEFT JOIN comments AS c on p.id = c.post_id\n LEFT JOIN users AS u on u.id = p.user_id\n LEFT JOIN users AS u2 on u2.id = c.user_id","referenced_tables":["posts","comments","users"]},{"name":"CamelizeTable","type":"table","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"created","type":"NUMERIC","nullable":false}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE CamelizeTable (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n created NUMERIC NOT NULL\n)"},{"name":"hyphen-table","type":"table","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"hyphen-column","type":"TEXT","nullable":false},{"name":"created","type":"NUMERIC","nullable":false}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"col","type":"TEXT","nullable":true},{"name":"brackets","type":"TEXT","nullable":false},{"name":"checkcheck","type":"TEXT","nullable":false},{"name":"downcase","type":"TEXT","nullable":false},{"name":"nl","type":"TEXT","nullable":false}],"indexes":[{"name":"sqlite_autoindex_check_constraints_4","def":"UNIQUE (nl)","table":"check_constraints","columns":["nl"]},{"name":"sqlite_autoindex_check_constraints_3","def":"UNIQUE (downcase)","table":"check_constraints","columns":["downcase"]},{"name":"sqlite_autoindex_check_constraints_2","def":"UNIQUE (checkcheck)","table":"check_constraints","columns":["checkcheck"]},{"name":"sqlite_autoindex_check_constraints_1","def":"UNIQUE (brackets)","table":"check_constraints","columns":["brackets"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"check_constraints","columns":["id"]},{"name":"sqlite_autoindex_check_constraints_4","type":"UNIQUE","def":"UNIQUE (nl)","table":"check_constraints","columns":["nl"]},{"name":"sqlite_autoindex_check_constraints_3","type":"UNIQUE","def":"UNIQUE (downcase)","table":"check_constraints","columns":["downcase"]},{"name":"sqlite_autoindex_check_constraints_2","type":"UNIQUE","def":"UNIQUE (checkcheck)","table":"check_constraints","columns":["checkcheck"]},{"name":"sqlite_autoindex_check_constraints_1","type":"UNIQUE","def":"UNIQUE (brackets)","table":"check_constraints","columns":["brackets"]},{"name":"-","type":"CHECK","def":"CHECK(length(col) \u003e 4)","table":"check_constraints","columns":["col"]},{"name":"-","type":"CHECK","def":"CHECK(((length(brackets) \u003e 4)))","table":"check_constraints","columns":["brackets"]},{"name":"-","type":"CHECK","def":"CHECK(length(checkcheck) \u003e 4)","table":"check_constraints","columns":["checkcheck"]},{"name":"-","type":"CHECK","def":"check(length(downcase) \u003e 4)","table":"check_constraints","columns":["downcase"]},{"name":"-","type":"CHECK","def":"check(length(nl) \u003e 4 OR nl != 'ln')","table":"check_constraints","columns":["nl"]}],"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","columns":[{"name":"logs","type":"","nullable":true}],"def":"CREATE VIRTUAL TABLE syslog USING fts3(logs)"},{"name":"access_log","type":"virtual table","columns":[{"name":"logs","type":"","nullable":true}],"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}],"driver":{"name":"sqlite","database_version":"3.46.1"},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/viewpoints/schema.json b/sample/viewpoints/schema.json index 0f55212f..1721081b 100644 --- a/sample/viewpoints/schema.json +++ b/sample/viewpoints/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"labels":[{"Name":"user","Virtual":true}]},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci","labels":[{"Name":"content","Virtual":true}]},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false,"labels":[{"Name":"user","Virtual":true}]},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'","labels":[{"Name":"content","Virtual":true}]},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","labels":[{"Name":"content","Virtual":true}],"referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"labels":[{"Name":"user","Virtual":true}]},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"Name":"content","Virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'","labels":[{"Name":"user","Virtual":true}]},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"Name":"secure","Virtual":true},{"Name":"encrypted","Virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com","labels":[{"Name":"secure","Virtual":true}]},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'","labels":[{"Name":"user","Virtual":true}]}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"Name":"sample","Virtual":true},{"Name":"tbls","Virtual":true}],"viewpoints":[{"name":"Content","desc":"Content as an asset for blogging services","labels":["content"]},{"name":"Ops","desc":"Tables to be referenced during operation","tables":["logs","users","posts"]},{"name":"Around the users table","desc":"Tables related to the users table","tables":["users"],"distance":1,"groups":[{"name":"Content","desc":"Content as an asset for blogging services","labels":["content"]}]},{"name":"Secure data","desc":"Tables with secure data","labels":["secure"]}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"labels":[{"name":"user","virtual":true}]},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci","labels":[{"name":"content","virtual":true}]},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false,"labels":[{"name":"user","virtual":true}]},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'","labels":[{"name":"content","virtual":true}]},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","labels":[{"name":"content","virtual":true}],"referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"labels":[{"name":"user","virtual":true}]},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"content","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'","labels":[{"name":"user","virtual":true}]},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com","labels":[{"name":"secure","virtual":true}]},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'","labels":[{"name":"user","virtual":true}]}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}],"viewpoints":[{"name":"Content","desc":"Content as an asset for blogging services","labels":["content"]},{"name":"Ops","desc":"Tables to be referenced during operation","tables":["logs","users","posts"]},{"name":"Around the users table","desc":"Tables related to the users table","tables":["users"],"distance":1,"groups":[{"name":"Content","desc":"Content as an asset for blogging services","labels":["content"]}]},{"name":"Secure data","desc":"Tables with secure data","labels":["secure"]}]} diff --git a/schema/schema.go b/schema/schema.go index dc593a76..ea797669 100644 --- a/schema/schema.go +++ b/schema/schema.go @@ -31,8 +31,8 @@ var DefaultHideColumns = []string{ColumnExtraDef, ColumnOccurrences, ColumnPerce var HideableColumns = []string{ColumnExtraDef, ColumnOccurrences, ColumnPercents, ColumnChildren, ColumnParents, ColumnComment, ColumnLabels} type Label struct { - Name string - Virtual bool + Name string `json:"name"` + Virtual bool `json:"virtual,omitempty"` } type Labels []*Label diff --git a/testdata/json_output_schema.golden b/testdata/json_output_schema.golden index b82d5b90..60084ee8 100644 --- a/testdata/json_output_schema.golden +++ b/testdata/json_output_schema.golden @@ -46,12 +46,11 @@ ], "labels": [ { - "Name": "blue", - "Virtual": false + "name": "blue" }, { - "Name": "green", - "Virtual": true + "name": "green", + "virtual": true } ] }, @@ -75,12 +74,11 @@ ], "labels": [ { - "Name": "red", - "Virtual": false + "name": "red" }, { - "Name": "green", - "Virtual": true + "name": "green", + "virtual": true } ] }, diff --git a/testdata/modify_schema_.golden b/testdata/modify_schema_.golden index 2e6070e2..3414466f 100644 --- a/testdata/modify_schema_.golden +++ b/testdata/modify_schema_.golden @@ -58,8 +58,8 @@ "def": "CREATE TABLE users (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n username TEXT UNIQUE NOT NULL CHECK(length(username) \u003e 4)\n)", "labels": [ { - "Name": "private", - "Virtual": true + "name": "private", + "virtual": true } ] }, @@ -111,12 +111,12 @@ "def": "CREATE TABLE categories (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n name TEXT UNIQUE NOT NULL\n)", "labels": [ { - "Name": "public", - "Virtual": true + "name": "public", + "virtual": true }, { - "Name": "option", - "Virtual": true + "name": "option", + "virtual": true } ] }, @@ -201,8 +201,8 @@ "def": "CREATE TABLE posts (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n user_id INTEGER NOT NULL,\n category_id INTEGER NOT NULL,\n title TEXT NOT NULL,\n CONSTRAINT posts_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE,\n CONSTRAINT posts_category_id_fk FOREIGN KEY(category_id) REFERENCES categories(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE\n)", "labels": [ { - "Name": "public", - "Virtual": true + "name": "public", + "virtual": true } ] }, @@ -253,12 +253,12 @@ "def": "CREATE TABLE user_options (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n user_id INTEGER NOT NULL,\n email TEXT NOT NULL,\n CONSTRAINT user_options_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE\n)", "labels": [ { - "Name": "private", - "Virtual": true + "name": "private", + "virtual": true }, { - "Name": "option", - "Virtual": true + "name": "option", + "virtual": true } ] }, diff --git a/testdata/modify_schema_mod_name_and_desc.golden b/testdata/modify_schema_mod_name_and_desc.golden index 91623405..575f01b9 100644 --- a/testdata/modify_schema_mod_name_and_desc.golden +++ b/testdata/modify_schema_mod_name_and_desc.golden @@ -59,8 +59,8 @@ "def": "CREATE TABLE users (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n username TEXT UNIQUE NOT NULL CHECK(length(username) \u003e 4)\n)", "labels": [ { - "Name": "private", - "Virtual": true + "name": "private", + "virtual": true } ] }, @@ -112,12 +112,12 @@ "def": "CREATE TABLE categories (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n name TEXT UNIQUE NOT NULL\n)", "labels": [ { - "Name": "public", - "Virtual": true + "name": "public", + "virtual": true }, { - "Name": "option", - "Virtual": true + "name": "option", + "virtual": true } ] }, @@ -202,8 +202,8 @@ "def": "CREATE TABLE posts (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n user_id INTEGER NOT NULL,\n category_id INTEGER NOT NULL,\n title TEXT NOT NULL,\n CONSTRAINT posts_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE,\n CONSTRAINT posts_category_id_fk FOREIGN KEY(category_id) REFERENCES categories(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE\n)", "labels": [ { - "Name": "public", - "Virtual": true + "name": "public", + "virtual": true } ] }, @@ -254,12 +254,12 @@ "def": "CREATE TABLE user_options (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n user_id INTEGER NOT NULL,\n email TEXT NOT NULL,\n CONSTRAINT user_options_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE\n)", "labels": [ { - "Name": "private", - "Virtual": true + "name": "private", + "virtual": true }, { - "Name": "option", - "Virtual": true + "name": "option", + "virtual": true } ] }, diff --git a/testdata/modify_schema_not_override.golden b/testdata/modify_schema_not_override.golden index 67496341..5207f1f0 100644 --- a/testdata/modify_schema_not_override.golden +++ b/testdata/modify_schema_not_override.golden @@ -58,8 +58,8 @@ "def": "CREATE TABLE users (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n username TEXT UNIQUE NOT NULL CHECK(length(username) \u003e 4)\n)", "labels": [ { - "Name": "private", - "Virtual": true + "name": "private", + "virtual": true } ] }, @@ -111,12 +111,12 @@ "def": "CREATE TABLE categories (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n name TEXT UNIQUE NOT NULL\n)", "labels": [ { - "Name": "public", - "Virtual": true + "name": "public", + "virtual": true }, { - "Name": "option", - "Virtual": true + "name": "option", + "virtual": true } ] }, @@ -201,8 +201,8 @@ "def": "CREATE TABLE posts (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n user_id INTEGER NOT NULL,\n category_id INTEGER NOT NULL,\n title TEXT NOT NULL,\n CONSTRAINT posts_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE,\n CONSTRAINT posts_category_id_fk FOREIGN KEY(category_id) REFERENCES categories(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE\n)", "labels": [ { - "Name": "public", - "Virtual": true + "name": "public", + "virtual": true } ] }, @@ -253,12 +253,12 @@ "def": "CREATE TABLE user_options (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n user_id INTEGER NOT NULL,\n email TEXT NOT NULL,\n CONSTRAINT user_options_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE\n)", "labels": [ { - "Name": "private", - "Virtual": true + "name": "private", + "virtual": true }, { - "Name": "option", - "Virtual": true + "name": "option", + "virtual": true } ] }, diff --git a/testdata/modify_schema_override.golden b/testdata/modify_schema_override.golden index 42178132..a4712301 100644 --- a/testdata/modify_schema_override.golden +++ b/testdata/modify_schema_override.golden @@ -58,8 +58,8 @@ "def": "CREATE TABLE users (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n username TEXT UNIQUE NOT NULL CHECK(length(username) \u003e 4)\n)", "labels": [ { - "Name": "private", - "Virtual": true + "name": "private", + "virtual": true } ] }, @@ -111,12 +111,12 @@ "def": "CREATE TABLE categories (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n name TEXT UNIQUE NOT NULL\n)", "labels": [ { - "Name": "public", - "Virtual": true + "name": "public", + "virtual": true }, { - "Name": "option", - "Virtual": true + "name": "option", + "virtual": true } ] }, @@ -201,8 +201,8 @@ "def": "CREATE TABLE posts (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n user_id INTEGER NOT NULL,\n category_id INTEGER NOT NULL,\n title TEXT NOT NULL,\n CONSTRAINT posts_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE,\n CONSTRAINT posts_category_id_fk FOREIGN KEY(category_id) REFERENCES categories(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE\n)", "labels": [ { - "Name": "public", - "Virtual": true + "name": "public", + "virtual": true } ] }, @@ -253,12 +253,12 @@ "def": "CREATE TABLE user_options (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n user_id INTEGER NOT NULL,\n email TEXT NOT NULL,\n CONSTRAINT user_options_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE\n)", "labels": [ { - "Name": "private", - "Virtual": true + "name": "private", + "virtual": true }, { - "Name": "option", - "Virtual": true + "name": "option", + "virtual": true } ] }, diff --git a/testdata/modify_schema_relations.golden b/testdata/modify_schema_relations.golden index 4d9424b2..ccaa058a 100644 --- a/testdata/modify_schema_relations.golden +++ b/testdata/modify_schema_relations.golden @@ -58,8 +58,8 @@ "def": "CREATE TABLE users (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n username TEXT UNIQUE NOT NULL CHECK(length(username) \u003e 4)\n)", "labels": [ { - "Name": "private", - "Virtual": true + "name": "private", + "virtual": true } ] }, @@ -111,12 +111,12 @@ "def": "CREATE TABLE categories (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n name TEXT UNIQUE NOT NULL\n)", "labels": [ { - "Name": "public", - "Virtual": true + "name": "public", + "virtual": true }, { - "Name": "option", - "Virtual": true + "name": "option", + "virtual": true } ] }, @@ -201,8 +201,8 @@ "def": "CREATE TABLE posts (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n user_id INTEGER NOT NULL,\n category_id INTEGER NOT NULL,\n title TEXT NOT NULL,\n CONSTRAINT posts_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE,\n CONSTRAINT posts_category_id_fk FOREIGN KEY(category_id) REFERENCES categories(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE\n)", "labels": [ { - "Name": "public", - "Virtual": true + "name": "public", + "virtual": true } ] }, @@ -253,12 +253,12 @@ "def": "CREATE TABLE user_options (\n id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n user_id INTEGER NOT NULL,\n email TEXT NOT NULL,\n CONSTRAINT user_options_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH NONE ON UPDATE NO ACTION ON DELETE CASCADE\n)", "labels": [ { - "Name": "private", - "Virtual": true + "name": "private", + "virtual": true }, { - "Name": "option", - "Virtual": true + "name": "option", + "virtual": true } ] }, diff --git a/testdata/yaml_output_schema.golden b/testdata/yaml_output_schema.golden index 6b6ba818..2623a4e0 100644 --- a/testdata/yaml_output_schema.golden +++ b/testdata/yaml_output_schema.golden @@ -29,7 +29,6 @@ tables: def: CREATE CONSTRAINT TRIGGER update_a_a2 AFTER INSERT OR UPDATE ON a labels: - name: blue - virtual: false - name: green virtual: true - name: b @@ -46,7 +45,6 @@ tables: comment: column b2 labels: - name: red - virtual: false - name: green virtual: true - name: view From c01ba29e9072a75a39267c148331c521c1afbfd1 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Fri, 24 Jan 2025 15:04:33 +0900 Subject: [PATCH 07/13] fix: Set omitempty --- sample/adjust/schema.json | 2 +- sample/clickhouse/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/schema.json | 2 +- sample/mssql/schema.json | 2 +- 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 +- schema/json.go | 35 +------------------ schema/yaml.go | 13 ------- testdata/json_output_schema.golden | 3 +- testdata/modify_schema_.golden | 9 ++--- .../modify_schema_mod_name_and_desc.golden | 9 ++--- testdata/modify_schema_not_override.golden | 9 ++--- testdata/modify_schema_override.golden | 6 ++-- testdata/modify_schema_relations.golden | 9 ++--- 28 files changed, 36 insertions(+), 97 deletions(-) diff --git a/sample/adjust/schema.json b/sample/adjust/schema.json index ac529da7..b649de22 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},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"users_pkey","def":"CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)","table":"public.users","columns":["id"]},{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)","table":"public.users","columns":["username"]},{"name":"users_email_key","def":"CREATE UNIQUE INDEX users_email_key ON public.users USING btree (email)","table":"public.users","columns":["email"]}],"constraints":[{"name":"users_username_check","type":"CHECK","def":"CHECK ((char_length((username)::text) \u003e 4))","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.users","referenced_table":"","columns":["id"]},{"name":"users_username_key","type":"UNIQUE","def":"UNIQUE (username)","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_email_key","type":"UNIQUE","def":"UNIQUE (email)","table":"public.users","referenced_table":"","columns":["email"]}],"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"}]},{"name":"public.user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"integer","nullable":false},{"name":"show_email","type":"boolean","nullable":false,"default":"false","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}]},{"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},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'::character varying","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"post_types","nullable":false,"comment":"public/private/draft"},{"name":"labels","type":"varchar(50)[]","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CREATE UNIQUE INDEX posts_id_pk ON public.posts USING btree (id)","table":"public.posts","columns":["id"]},{"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":["user_id","title"]},{"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"]},{"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"]},{"name":"posts_user_id_title_key","type":"UNIQUE","def":"UNIQUE (user_id, title)","table":"public.posts","referenced_table":"","columns":["user_id","title"]}],"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"}]},{"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},{"name":"user_id","type":"integer","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (post_id * '-1'::integer) STORED"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CREATE UNIQUE INDEX comments_id_pk ON public.comments USING btree (id)","table":"public.comments","columns":["id"]},{"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"]},{"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"]}],"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"]},{"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"]},{"name":"comments_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.comments","referenced_table":"","columns":["id"]},{"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"]}]},{"name":"public.comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"user_id","type":"integer","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"integer","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","table":"public.comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id)","table":"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"]},{"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"]}]},{"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},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"uuid","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false}]},{"name":"public.post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"timestamp without time zone","nullable":true,"comment":"comments.created"},{"name":"updated","type":"timestamp without time zone","nullable":true,"comment":"comments.updated"}],"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","columns":[{"name":"id","type":"uuid","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"comment_star_user","type":"varchar(50)","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false}],"indexes":[{"name":"CamelizeTable_id_key","def":"CREATE UNIQUE INDEX \"CamelizeTable_id_key\" ON public.\"CamelizeTable\" USING btree (id)","table":"public.CamelizeTable","columns":["id"]}],"constraints":[{"name":"CamelizeTable_id_key","type":"UNIQUE","def":"UNIQUE (id)","table":"public.CamelizeTable","referenced_table":"","columns":["id"]}]},{"name":"public.hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"hyphen-column","type":"text","nullable":false},{"name":"CamelizeTableId","type":"uuid","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false}],"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"]}],"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"]},{"name":"hyphen-table_hyphen-column_key","type":"UNIQUE","def":"UNIQUE (\"hyphen-column\")","table":"public.hyphen-table","referenced_table":"","columns":["hyphen-column"]}]},{"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},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON administrator.blogs USING btree (id)","table":"administrator.blogs","columns":["id"]}],"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"]},{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"administrator.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blogs","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blogs_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false},{"name":"dump","type":"text","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON backup.blogs USING btree (id)","table":"backup.blogs","columns":["id"]}],"constraints":[{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blog_options","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blog_options_id_seq'::regclass)","comment":""},{"name":"blog_id","type":"integer","nullable":false},{"name":"label","type":"text","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}],"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"]},{"name":"blog_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blog_options","referenced_table":"","columns":["id"]}]},{"name":"time.bar","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"indexes":[{"name":"bar_pkey","def":"CREATE UNIQUE INDEX bar_pkey ON \"time\".bar USING btree (id)","table":"time.bar","columns":["id"]}],"constraints":[{"name":"bar_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.bar","referenced_table":"","columns":["id"]}]},{"name":"time.hyphenated-table","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"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"]}],"constraints":[{"name":"hyphenated-table_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.hyphenated-table","referenced_table":"","columns":["id"]}]},{"name":"time.referencing","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false},{"name":"bar_id","type":"integer","nullable":false},{"name":"ht_id","type":"integer","nullable":false}],"indexes":[{"name":"referencing_pkey","def":"CREATE UNIQUE INDEX referencing_pkey ON \"time\".referencing USING btree (id)","table":"time.referencing","columns":["id"]}],"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"]},{"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"]},{"name":"referencing_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.referencing","referenced_table":"","columns":["id"]}]}],"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"}],"enums":[{"name":"public.post_types","values":["draft","private","public"]}],"driver":{"name":"postgres","database_version":"PostgreSQL 15.10 (Debian 15.10-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit","meta":{"current_schema":"public","search_paths":["postgres","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}},"viewpoints":[{"name":"post","desc":"for post","tables":["public.post*"]},{"name":"administrator","desc":"administrator schema only","tables":["administrator.*"]}]} +{"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)"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"users_pkey","def":"CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)","table":"public.users","columns":["id"]},{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)","table":"public.users","columns":["username"]},{"name":"users_email_key","def":"CREATE UNIQUE INDEX users_email_key ON public.users USING btree (email)","table":"public.users","columns":["email"]}],"constraints":[{"name":"users_username_check","type":"CHECK","def":"CHECK ((char_length((username)::text) \u003e 4))","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.users","referenced_table":"","columns":["id"]},{"name":"users_username_key","type":"UNIQUE","def":"UNIQUE (username)","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_email_key","type":"UNIQUE","def":"UNIQUE (email)","table":"public.users","referenced_table":"","columns":["email"]}],"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"}]},{"name":"public.user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"integer","nullable":false},{"name":"show_email","type":"boolean","nullable":false,"default":"false"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}]},{"name":"public.posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"default":"nextval('posts_id_seq'::regclass)"},{"name":"user_id","type":"integer","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'::character varying"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"post_types","nullable":false,"comment":"public/private/draft"},{"name":"labels","type":"varchar(50)[]","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CREATE UNIQUE INDEX posts_id_pk ON public.posts USING btree (id)","table":"public.posts","columns":["id"]},{"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":["user_id","title"]},{"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"]},{"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"]},{"name":"posts_user_id_title_key","type":"UNIQUE","def":"UNIQUE (user_id, title)","table":"public.posts","referenced_table":"","columns":["user_id","title"]}],"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"}]},{"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)"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"integer","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (post_id * '-1'::integer) STORED"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CREATE UNIQUE INDEX comments_id_pk ON public.comments USING btree (id)","table":"public.comments","columns":["id"]},{"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"]},{"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"]}],"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"]},{"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"]},{"name":"comments_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.comments","referenced_table":"","columns":["id"]},{"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"]}]},{"name":"public.comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"user_id","type":"integer","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"integer","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","table":"public.comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id)","table":"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"]},{"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"]}]},{"name":"public.logs","type":"BASE TABLE","comment":"audit log table","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"user_id","type":"integer","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"uuid","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false}]},{"name":"public.post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"timestamp without time zone","nullable":true,"comment":"comments.created"},{"name":"updated","type":"timestamp without time zone","nullable":true,"comment":"comments.updated"}],"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","columns":[{"name":"id","type":"uuid","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"comment_star_user","type":"varchar(50)","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"created","type":"timestamp without time zone","nullable":false}],"indexes":[{"name":"CamelizeTable_id_key","def":"CREATE UNIQUE INDEX \"CamelizeTable_id_key\" ON public.\"CamelizeTable\" USING btree (id)","table":"public.CamelizeTable","columns":["id"]}],"constraints":[{"name":"CamelizeTable_id_key","type":"UNIQUE","def":"UNIQUE (id)","table":"public.CamelizeTable","referenced_table":"","columns":["id"]}]},{"name":"public.hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"CamelizeTableId","type":"uuid","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false}],"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"]}],"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"]},{"name":"hyphen-table_hyphen-column_key","type":"UNIQUE","def":"UNIQUE (\"hyphen-column\")","table":"public.hyphen-table","referenced_table":"","columns":["hyphen-column"]}]},{"name":"administrator.blogs","type":"BASE TABLE","comment":"admin blogs","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('administrator.blogs_id_seq'::regclass)"},{"name":"user_id","type":"integer","nullable":false},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON administrator.blogs USING btree (id)","table":"administrator.blogs","columns":["id"]}],"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"]},{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"administrator.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blogs","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blogs_id_seq'::regclass)"},{"name":"user_id","type":"integer","nullable":false},{"name":"dump","type":"text","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON backup.blogs USING btree (id)","table":"backup.blogs","columns":["id"]}],"constraints":[{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blog_options","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blog_options_id_seq'::regclass)"},{"name":"blog_id","type":"integer","nullable":false},{"name":"label","type":"text","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}],"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"]},{"name":"blog_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blog_options","referenced_table":"","columns":["id"]}]},{"name":"time.bar","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"indexes":[{"name":"bar_pkey","def":"CREATE UNIQUE INDEX bar_pkey ON \"time\".bar USING btree (id)","table":"time.bar","columns":["id"]}],"constraints":[{"name":"bar_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.bar","referenced_table":"","columns":["id"]}]},{"name":"time.hyphenated-table","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"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"]}],"constraints":[{"name":"hyphenated-table_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.hyphenated-table","referenced_table":"","columns":["id"]}]},{"name":"time.referencing","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false},{"name":"bar_id","type":"integer","nullable":false},{"name":"ht_id","type":"integer","nullable":false}],"indexes":[{"name":"referencing_pkey","def":"CREATE UNIQUE INDEX referencing_pkey ON \"time\".referencing USING btree (id)","table":"time.referencing","columns":["id"]}],"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"]},{"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"]},{"name":"referencing_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.referencing","referenced_table":"","columns":["id"]}]}],"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"},{"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)"},{"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)"},{"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)"},{"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)"},{"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)"},{"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"},{"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"},{"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"},{"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)"},{"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)"},{"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"}],"enums":[{"name":"public.post_types","values":["draft","private","public"]}],"driver":{"name":"postgres","database_version":"PostgreSQL 15.10 (Debian 15.10-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit","meta":{"current_schema":"public","search_paths":["postgres","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}},"viewpoints":[{"name":"post","desc":"for post","tables":["public.post*"]},{"name":"administrator","desc":"administrator schema only","tables":["administrator.*"]}]} diff --git a/sample/clickhouse/schema.json b/sample/clickhouse/schema.json index 1860ea3f..eb4dffcb 100644 --- a/sample/clickhouse/schema.json +++ b/sample/clickhouse/schema.json @@ -1 +1 @@ -{"name":"testdb","tables":[{"name":"id_value_dictionary","type":"Dictionary","columns":[{"name":"id","type":"UInt64","nullable":false},{"name":"value","type":"String","nullable":false}],"def":"CREATE DICTIONARY testdb.id_value_dictionary (`id` UInt64, `value` String) PRIMARY KEY id SOURCE(CLICKHOUSE(TABLE 'source_table')) LIFETIME(MIN 0 MAX 1000) LAYOUT(FLAT())"},{"name":"materialized_view","type":"MaterializedView","columns":[{"name":"name1","type":"UInt64","nullable":false},{"name":"name2","type":"Nullable(String)","nullable":false}],"def":"CREATE MATERIALIZED VIEW testdb.materialized_view (`name1` UInt64, `name2` Nullable(String)) ENGINE = Memory AS SELECT name1, name2 FROM testdb.table_name ORDER BY name1 DESC","referenced_tables":["table_name"]},{"name":"numbers_table","type":"SystemNumbers","columns":[{"name":"number","type":"UInt64","nullable":false}],"def":"CREATE TABLE testdb.numbers_table (`number` UInt64) AS numbers(100)"},{"name":"source_table","type":"MergeTree","columns":[{"name":"id","type":"UInt64","nullable":false},{"name":"value","type":"String","nullable":false}],"constraints":[{"name":"sorting key","type":"SORTING KEY","def":"ORDER BY (id)","table":"source_table","columns":["id"]},{"name":"primary key","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"source_table","columns":["id"]}],"def":"CREATE TABLE testdb.source_table (`id` UInt64, `value` String) ENGINE = MergeTree PRIMARY KEY id ORDER BY id SETTINGS index_granularity = 8192"},{"name":"t1","type":"Memory","columns":[{"name":"x","type":"String","nullable":false}],"def":"CREATE TABLE testdb.t1 (`x` String) ENGINE = Memory"},{"name":"table_name","type":"MergeTree","comment":"comment for table","columns":[{"name":"name1","type":"UInt64","nullable":false,"comment":"comment for column 1"},{"name":"name2","type":"Nullable(String)","nullable":false,"default":"DEFAULT 'column 2'","comment":"comment for column 2"},{"name":"name3","type":"LowCardinality(String)","nullable":false,"default":"MATERIALIZED upper(name2)","comment":"comment for column 3"},{"name":"name4","type":"SimpleAggregateFunction(sum, Float64)","nullable":false},{"name":"name5","type":"DateTime","nullable":false,"default":"DEFAULT now()","comment":""},{"name":"name6","type":"String","nullable":false,"default":"ALIAS formatReadableSize(name1)","comment":""},{"name":"name7","type":"String","nullable":false,"default":"MATERIALIZED hex(name1)","comment":""},{"name":"name8","type":"FixedString(4)","nullable":false,"default":"DEFAULT unhex(name7)","comment":""}],"indexes":[{"name":"idx1","def":"bloom_filter(0.01)","table":"table_name","columns":["name1"]},{"name":"idx2","def":"minmax","table":"table_name","columns":["name1 * 2"]},{"name":"idx3","def":"set(1000)","table":"table_name","columns":["name1 * length(name2)"]}],"constraints":[{"name":"partition key","type":"PARTITION KEY","def":"PARTITION BY ((name1, name3, name5))","table":"table_name","columns":["name1","name3","name5"]},{"name":"sorting key","type":"SORTING KEY","def":"ORDER BY (name1, name5)","table":"table_name","columns":["name1","name5"]},{"name":"primary key","type":"PRIMARY KEY","def":"PRIMARY KEY (name1, name5)","table":"table_name","columns":["name1","name5"]},{"name":"sampling key","type":"SAMPLING KEY","def":"SAMPLE BY (name1)","table":"table_name","columns":["name1"]}],"def":"CREATE TABLE testdb.table_name (`name1` UInt64 COMMENT 'comment for column 1', `name2` Nullable(String) DEFAULT 'column 2' COMMENT 'comment for column 2' CODEC(ZSTD(1)), `name3` LowCardinality(String) MATERIALIZED upper(name2) COMMENT 'comment for column 3', `name4` SimpleAggregateFunction(sum, Float64) TTL name5 + toIntervalDay(1), `name5` DateTime DEFAULT now(), `name6` String ALIAS formatReadableSize(name1), `name7` String MATERIALIZED hex(name1), `name8` FixedString(4) DEFAULT unhex(name7), INDEX idx1 name1 TYPE bloom_filter(0.01) GRANULARITY 1, INDEX idx2 name1 * 2 TYPE minmax GRANULARITY 3, INDEX idx3 name1 * length(name2) TYPE set(1000) GRANULARITY 4, PROJECTION projection_name_1 (SELECT name1, name2, name3 ORDER BY name1)) ENGINE = MergeTree PARTITION BY (name1, name3, name5) PRIMARY KEY (name1, name5) ORDER BY (name1, name5) SAMPLE BY name1 SETTINGS index_granularity = 8192 COMMENT 'comment for table'"},{"name":"view","type":"View","columns":[{"name":"name1","type":"UInt64","nullable":false},{"name":"name2","type":"Nullable(String)","nullable":false},{"name":"name4","type":"SimpleAggregateFunction(sum, Float64)","nullable":false},{"name":"name5","type":"DateTime","nullable":false},{"name":"name8","type":"FixedString(4)","nullable":false}],"def":"CREATE VIEW testdb.view (`name1` UInt64, `name2` Nullable(String), `name4` SimpleAggregateFunction(sum, Float64), `name5` DateTime, `name8` FixedString(4)) AS SELECT * FROM testdb.table_name"}],"functions":[{"name":"linear_equation","return_type":"","arguments":"","type":""}],"driver":{"name":"clickhouse","database_version":"24.4.4.113","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} +{"name":"testdb","tables":[{"name":"id_value_dictionary","type":"Dictionary","columns":[{"name":"id","type":"UInt64","nullable":false},{"name":"value","type":"String","nullable":false}],"def":"CREATE DICTIONARY testdb.id_value_dictionary (`id` UInt64, `value` String) PRIMARY KEY id SOURCE(CLICKHOUSE(TABLE 'source_table')) LIFETIME(MIN 0 MAX 1000) LAYOUT(FLAT())"},{"name":"materialized_view","type":"MaterializedView","columns":[{"name":"name1","type":"UInt64","nullable":false},{"name":"name2","type":"Nullable(String)","nullable":false}],"def":"CREATE MATERIALIZED VIEW testdb.materialized_view (`name1` UInt64, `name2` Nullable(String)) ENGINE = Memory AS SELECT name1, name2 FROM testdb.table_name ORDER BY name1 DESC","referenced_tables":["table_name"]},{"name":"numbers_table","type":"SystemNumbers","columns":[{"name":"number","type":"UInt64","nullable":false}],"def":"CREATE TABLE testdb.numbers_table (`number` UInt64) AS numbers(100)"},{"name":"source_table","type":"MergeTree","columns":[{"name":"id","type":"UInt64","nullable":false},{"name":"value","type":"String","nullable":false}],"constraints":[{"name":"sorting key","type":"SORTING KEY","def":"ORDER BY (id)","table":"source_table","columns":["id"]},{"name":"primary key","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"source_table","columns":["id"]}],"def":"CREATE TABLE testdb.source_table (`id` UInt64, `value` String) ENGINE = MergeTree PRIMARY KEY id ORDER BY id SETTINGS index_granularity = 8192"},{"name":"t1","type":"Memory","columns":[{"name":"x","type":"String","nullable":false}],"def":"CREATE TABLE testdb.t1 (`x` String) ENGINE = Memory"},{"name":"table_name","type":"MergeTree","comment":"comment for table","columns":[{"name":"name1","type":"UInt64","nullable":false,"comment":"comment for column 1"},{"name":"name2","type":"Nullable(String)","nullable":false,"default":"DEFAULT 'column 2'","comment":"comment for column 2"},{"name":"name3","type":"LowCardinality(String)","nullable":false,"default":"MATERIALIZED upper(name2)","comment":"comment for column 3"},{"name":"name4","type":"SimpleAggregateFunction(sum, Float64)","nullable":false},{"name":"name5","type":"DateTime","nullable":false,"default":"DEFAULT now()"},{"name":"name6","type":"String","nullable":false,"default":"ALIAS formatReadableSize(name1)"},{"name":"name7","type":"String","nullable":false,"default":"MATERIALIZED hex(name1)"},{"name":"name8","type":"FixedString(4)","nullable":false,"default":"DEFAULT unhex(name7)"}],"indexes":[{"name":"idx1","def":"bloom_filter(0.01)","table":"table_name","columns":["name1"]},{"name":"idx2","def":"minmax","table":"table_name","columns":["name1 * 2"]},{"name":"idx3","def":"set(1000)","table":"table_name","columns":["name1 * length(name2)"]}],"constraints":[{"name":"partition key","type":"PARTITION KEY","def":"PARTITION BY ((name1, name3, name5))","table":"table_name","columns":["name1","name3","name5"]},{"name":"sorting key","type":"SORTING KEY","def":"ORDER BY (name1, name5)","table":"table_name","columns":["name1","name5"]},{"name":"primary key","type":"PRIMARY KEY","def":"PRIMARY KEY (name1, name5)","table":"table_name","columns":["name1","name5"]},{"name":"sampling key","type":"SAMPLING KEY","def":"SAMPLE BY (name1)","table":"table_name","columns":["name1"]}],"def":"CREATE TABLE testdb.table_name (`name1` UInt64 COMMENT 'comment for column 1', `name2` Nullable(String) DEFAULT 'column 2' COMMENT 'comment for column 2' CODEC(ZSTD(1)), `name3` LowCardinality(String) MATERIALIZED upper(name2) COMMENT 'comment for column 3', `name4` SimpleAggregateFunction(sum, Float64) TTL name5 + toIntervalDay(1), `name5` DateTime DEFAULT now(), `name6` String ALIAS formatReadableSize(name1), `name7` String MATERIALIZED hex(name1), `name8` FixedString(4) DEFAULT unhex(name7), INDEX idx1 name1 TYPE bloom_filter(0.01) GRANULARITY 1, INDEX idx2 name1 * 2 TYPE minmax GRANULARITY 3, INDEX idx3 name1 * length(name2) TYPE set(1000) GRANULARITY 4, PROJECTION projection_name_1 (SELECT name1, name2, name3 ORDER BY name1)) ENGINE = MergeTree PARTITION BY (name1, name3, name5) PRIMARY KEY (name1, name5) ORDER BY (name1, name5) SAMPLE BY name1 SETTINGS index_granularity = 8192 COMMENT 'comment for table'"},{"name":"view","type":"View","columns":[{"name":"name1","type":"UInt64","nullable":false},{"name":"name2","type":"Nullable(String)","nullable":false},{"name":"name4","type":"SimpleAggregateFunction(sum, Float64)","nullable":false},{"name":"name5","type":"DateTime","nullable":false},{"name":"name8","type":"FixedString(4)","nullable":false}],"def":"CREATE VIEW testdb.view (`name1` UInt64, `name2` Nullable(String), `name4` SimpleAggregateFunction(sum, Float64), `name5` DateTime, `name8` FixedString(4)) AS SELECT * FROM testdb.table_name"}],"functions":[{"name":"linear_equation","return_type":"","arguments":"","type":""}],"driver":{"name":"clickhouse","database_version":"24.4.4.113","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} diff --git a/sample/detect_relations/schema.json b/sample/detect_relations/schema.json index 303f126d..b9c98c5f 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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"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,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`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,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL,\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},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]}],"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.4.4","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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"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,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`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,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL,\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},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]}],"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)"},{"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.4.4","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 65e562f6..d28f8929 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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment","type":"BASE TABLE","comment":"Comment\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"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"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comment","columns":["post_id","user_id"]}],"constraints":[{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comment","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment","columns":["id"]}],"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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_star","columns":["id"]},{"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"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_star","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_star","columns":["user_id","comment_post_id","comment_user_id"]}],"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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"log","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"log","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"log","columns":["id"]}],"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,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"post_user_id_idx","def":"KEY post_user_id_idx (id) USING BTREE","table":"post","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"post","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"post","columns":["user_id","title"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"post","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"post","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON post\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"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,"comment":"post.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"post.user.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comment.user.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comment.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comment.updated"}],"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,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"user","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"user","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"user","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"user","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"user","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"user","columns":["username"]}],"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},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_option","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_option","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_option","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_option","columns":["user_id"]},{"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"]}],"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.4.4","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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment","type":"BASE TABLE","comment":"Comment\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"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"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comment","columns":["post_id","user_id"]}],"constraints":[{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comment","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment","columns":["id"]}],"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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_star","columns":["id"]},{"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"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_star","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_star","columns":["user_id","comment_post_id","comment_user_id"]}],"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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"log","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"log","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"log","columns":["id"]}],"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,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"post_user_id_idx","def":"KEY post_user_id_idx (id) USING BTREE","table":"post","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"post","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"post","columns":["user_id","title"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"post","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"post","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON post\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"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,"comment":"post.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"post.user.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comment.user.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comment.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comment.updated"}],"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,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"user","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"user","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"user","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"user","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"user","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"user","columns":["username"]}],"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},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_option","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_option","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_option","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_option","columns":["user_id"]},{"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"]}],"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)"},{"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.4.4","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 cb1687d6..4f2d64ed 100644 --- a/sample/dict/schema.json +++ b/sample/dict/schema.json @@ -1 +1 @@ -{"name":"testdb","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"VIEW","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":""},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"post_user","type":"varchar(50)","nullable":true},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"created","type":"datetime","nullable":true},{"name":"updated","type":"datetime","nullable":true}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'"},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} +{"name":"testdb","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"VIEW","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"post_user","type":"varchar(50)","nullable":true},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"created","type":"datetime","nullable":true},{"name":"updated","type":"datetime","nullable":true}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'"},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} diff --git a/sample/exclude/schema.json b/sample/exclude/schema.json index 4a93971d..2ee9898a 100644 --- a/sample/exclude/schema.json +++ b/sample/exclude/schema.json @@ -1 +1 @@ -{"name":"testdb","tables":[{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'"},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} +{"name":"testdb","tables":[{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'"},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} diff --git a/sample/font/schema.json b/sample/font/schema.json index 536d65b6..9848a60d 100644 --- a/sample/font/schema.json +++ b/sample/font/schema.json @@ -1 +1 @@ -{"name":"testdb","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"エントリ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"本文"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'"},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"サンプル","virtual":true},{"name":"tbls","virtual":true}]} +{"name":"testdb","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"エントリ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"本文"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'"},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"サンプル","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/hide/schema.json b/sample/hide/schema.json index 3e1bbbdb..709ad61f 100644 --- a/sample/hide/schema.json +++ b/sample/hide/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} diff --git a/sample/hide_not_related_column/schema.json b/sample/hide_not_related_column/schema.json index d02b537c..ec587e5c 100644 --- a/sample/hide_not_related_column/schema.json +++ b/sample/hide_not_related_column/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com","labels":[{"name":"secure","virtual":true}]},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"Zero or more","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/mariadb/schema.json b/sample/mariadb/schema.json index 1a71cacf..bbe2a77c 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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint(20)","nullable":false},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment","type":"text","nullable":false,"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},{"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"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment_post_id","type":"bigint(20)","nullable":false},{"name":"comment_user_id","type":"int(11)","nullable":false},{"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"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"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}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true,"default":"NULL","comment":""}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint(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,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":"NULL","comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS ((select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on(`p`.`id` = `c`.`post_id`)) left join `testdb`.`users` `u` on(`u`.`id` = `p`.`user_id`)) left join `testdb`.`users` `u2` on(`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"same_name_constraints","type":"BASE TABLE","columns":[{"name":"id","type":"bigint(20)","nullable":true,"default":"NULL","comment":""},{"name":"user_id","type":"int(11)","nullable":false}],"indexes":[{"name":"same_name","def":"UNIQUE KEY same_name (user_id, id) USING BTREE","table":"same_name_constraints","columns":["user_id","id"]}],"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"]},{"name":"same_name","type":"UNIQUE","def":"UNIQUE KEY same_name (user_id, id)","table":"same_name_constraints","columns":["user_id","id"]}],"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,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"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"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]}],"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},{"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"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int(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}],"driver":{"name":"mariadb","database_version":"10.5.27-MariaDB-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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint(20)","nullable":false},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment","type":"text","nullable":false,"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"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true,"default":"NULL"}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment_post_id","type":"bigint(20)","nullable":false},{"name":"comment_user_id","type":"int(11)","nullable":false},{"name":"created","type":"timestamp","nullable":false,"default":"current_timestamp()","extra_def":"on update current_timestamp()"},{"name":"updated","type":"timestamp","nullable":false,"default":"'0000-00-00 00:00:00'"}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"post_id","type":"bigint(20)","nullable":true,"default":"NULL"},{"name":"comment_id","type":"bigint(20)","nullable":true,"default":"NULL"},{"name":"comment_star_id","type":"bigint(20)","nullable":true,"default":"NULL"},{"name":"payload","type":"text","nullable":true,"default":"NULL"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true,"default":"NULL"}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint(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,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":"NULL","comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS ((select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on(`p`.`id` = `c`.`post_id`)) left join `testdb`.`users` `u` on(`u`.`id` = `p`.`user_id`)) left join `testdb`.`users` `u2` on(`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"same_name_constraints","type":"BASE TABLE","columns":[{"name":"id","type":"bigint(20)","nullable":true,"default":"NULL"},{"name":"user_id","type":"int(11)","nullable":false}],"indexes":[{"name":"same_name","def":"UNIQUE KEY same_name (user_id, id) USING BTREE","table":"same_name_constraints","columns":["user_id","id"]}],"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"]},{"name":"same_name","type":"UNIQUE","def":"UNIQUE KEY same_name (user_id, id)","table":"same_name_constraints","columns":["user_id","id"]}],"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,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false,"default":"current_timestamp()","extra_def":"on update current_timestamp()"},{"name":"updated","type":"timestamp","nullable":false,"default":"'0000-00-00 00:00:00'"}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]}],"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},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false,"default":"current_timestamp()","extra_def":"on update current_timestamp()"},{"name":"updated","type":"timestamp","nullable":false,"default":"'0000-00-00 00:00:00'"}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int(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)"},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"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)"},{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"Exactly one","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Additional Relation","virtual":true}],"driver":{"name":"mariadb","database_version":"10.5.27-MariaDB-ubu2004","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/mermaid/schema.json b/sample/mermaid/schema.json index b0a5c42b..901682cb 100644 --- a/sample/mermaid/schema.json +++ b/sample/mermaid/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com","labels":[{"name":"secure","virtual":true}]},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"Exactly one","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/mssql/schema.json b/sample/mssql/schema.json index fc920a06..f3a8df74 100644 --- a/sample/mssql/schema.json +++ b/sample/mssql/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"users","type":"BASIC TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"comment":"long long long long long long long long long long long long long long long long long long long long long description"},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"PK__users_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"users","columns":["id"]},{"name":"UQ__users_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ email ]","table":"users","columns":["email"]},{"name":"UQ__users_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ username ]","table":"users","columns":["username"]}],"constraints":[{"name":"PK__users_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"users","columns":["id"]},{"name":"UQ__users_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ email ]","table":"users","columns":["email"]},{"name":"UQ__users_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ username ]","table":"users","columns":["username"]},{"name":"CK__users__username_*","type":"CHECK","def":"CHECK(len([username])\u003e(4))","table":"users","columns":null}],"triggers":[{"name":"update_users_updated","def":"CREATE TRIGGER update_users_updated\nON users\nAFTER UPDATE\nAS\nBEGIN\n UPDATE users SET updated = GETDATE()\n WHERE id = ( SELECT id FROM deleted)\nEND;"}]},{"name":"user_options","type":"BASIC TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"bit","nullable":false,"default":"((0))","comment":""},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"PK__user_opt_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ user_id ]","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PK__user_opt_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ user_id ]","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE CASCADE","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}]},{"name":"posts","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"posts","columns":["id"]},{"name":"UQ__posts_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, title ]","table":"posts","columns":["user_id","title"]},{"name":"posts_user_id_idx","def":"NONCLUSTERED, [ user_id ]","table":"posts","columns":["user_id"]}],"constraints":[{"name":"posts_id_pk","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"posts","columns":["id"]},{"name":"UQ__posts_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, title ]","table":"posts","columns":["user_id","title"]},{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE CASCADE","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated\nON posts\nAFTER UPDATE\nAS\nBEGIN\n UPDATE users SET updated = GETDATE()\n WHERE id = ( SELECT user_id FROM deleted)\nEND;"}],"labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"comments","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"post_id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"comments","columns":["id"]},{"name":"UQ__comments_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"]},{"name":"comments_post_id_user_id_idx","def":"NONCLUSTERED, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_id_pk","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"comments","columns":["id"]},{"name":"UQ__comments_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"]},{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(post_id) REFERENCES posts(id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}]},{"name":"comment_stars","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"int","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"UQ__comment__*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, comment_post_id, comment_user_id ]","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"UQ__comment__*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, comment_post_id, comment_user_id ]","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]},{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(comment_user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]}]},{"name":"logs","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"int","nullable":true},{"name":"comment_id","type":"int","nullable":true},{"name":"comment_star_id","type":"int","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"date","nullable":false}]},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"int","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"date","nullable":true,"comment":"comments.created"},{"name":"updated","type":"date","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (\n SELECT c.id, p.title, u2.username AS post_user, c.comment, u2.username AS comment_user, c.created, c.updated\n FROM posts AS p\n LEFT JOIN comments AS c on p.id = c.post_id\n LEFT JOIN users AS u on u.id = p.user_id\n LEFT JOIN users AS u2 on u2.id = c.user_id\n);","referenced_tables":["posts","comments","users"]},{"name":"CamelizeTable","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"created","type":"date","nullable":false}]},{"name":"hyphen-table","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"date","nullable":false}]},{"name":"administrator.blogs","type":"BASIC TABLE","comment":"admin blogs","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"PK__blogs_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"administrator.blogs","columns":["id"]}],"constraints":[{"name":"PK__blogs_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"administrator.blogs","columns":["id"]},{"name":"blogs_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE CASCADE","table":"administrator.blogs","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}]},{"name":"name with spaces","type":"VIEW","columns":[{"name":"title","type":"varchar(255)","nullable":false}],"def":"CREATE VIEW \"name with spaces\" AS (\n SELECT TOP 1 p.title\n FROM posts AS p\n);","referenced_tables":["posts"]},{"name":"Sales.Product","type":"BASIC TABLE","columns":[{"name":"ProductID","type":"int","nullable":false},{"name":"SalesPersonID","type":"int","nullable":true}],"indexes":[{"name":"PK__Product_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ ProductID ]","table":"Sales.Product","columns":["ProductID"]},{"name":"UQ__Product_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ SalesPersonID ]","table":"Sales.Product","columns":["SalesPersonID"]}],"constraints":[{"name":"PK__Product_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ ProductID ]","table":"Sales.Product","columns":["ProductID"]},{"name":"UQ__Product_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ SalesPersonID ]","table":"Sales.Product","columns":["SalesPersonID"]}]},{"name":"Rabbits.Running","type":"BASIC TABLE","columns":[{"name":"LocationID","type":"int","nullable":false},{"name":"ProductID","type":"int","nullable":true},{"name":"EmployeeID","type":"int","nullable":true}],"indexes":[{"name":"PK__Running_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ LocationID ]","table":"Rabbits.Running","columns":["LocationID"]},{"name":"UQ__Running_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ EmployeeID ]","table":"Rabbits.Running","columns":["EmployeeID"]},{"name":"UQ__Running_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ ProductID ]","table":"Rabbits.Running","columns":["ProductID"]}],"constraints":[{"name":"PK__Running_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ LocationID ]","table":"Rabbits.Running","columns":["LocationID"]},{"name":"UQ__Running_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ EmployeeID ]","table":"Rabbits.Running","columns":["EmployeeID"]},{"name":"UQ__Running_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ ProductID ]","table":"Rabbits.Running","columns":["ProductID"]},{"name":"FK_TempSales_SalesReason","type":"FOREIGN KEY","def":"FOREIGN KEY(ProductID) REFERENCES Sales.Product(SalesPersonID) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"Rabbits.Running","referenced_table":"Sales.Product","columns":["ProductID"],"referenced_columns":["SalesPersonID"]}]}],"relations":[{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"","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 2019 (RTM-CU30) (KB5049235) - 15.0.4415.2 (X64) \n\tNov 18 2024 17:45:37 \n\tCopyright (C) 2019 Microsoft Corporation\n\tDeveloper Edition (64-bit) on Linux (Ubuntu 20.04.6 LTS) \u003cX64\u003e","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"users","type":"BASIC TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"comment":"long long long long long long long long long long long long long long long long long long long long long description"},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"PK__users_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"users","columns":["id"]},{"name":"UQ__users_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ email ]","table":"users","columns":["email"]},{"name":"UQ__users_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ username ]","table":"users","columns":["username"]}],"constraints":[{"name":"PK__users_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"users","columns":["id"]},{"name":"UQ__users_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ email ]","table":"users","columns":["email"]},{"name":"UQ__users_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ username ]","table":"users","columns":["username"]},{"name":"CK__users__username_*","type":"CHECK","def":"CHECK(len([username])\u003e(4))","table":"users","columns":null}],"triggers":[{"name":"update_users_updated","def":"CREATE TRIGGER update_users_updated\nON users\nAFTER UPDATE\nAS\nBEGIN\n UPDATE users SET updated = GETDATE()\n WHERE id = ( SELECT id FROM deleted)\nEND;"}]},{"name":"user_options","type":"BASIC TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"bit","nullable":false,"default":"((0))"},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"PK__user_opt_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ user_id ]","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PK__user_opt_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ user_id ]","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE CASCADE","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}]},{"name":"posts","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"posts","columns":["id"]},{"name":"UQ__posts_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, title ]","table":"posts","columns":["user_id","title"]},{"name":"posts_user_id_idx","def":"NONCLUSTERED, [ user_id ]","table":"posts","columns":["user_id"]}],"constraints":[{"name":"posts_id_pk","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"posts","columns":["id"]},{"name":"UQ__posts_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, title ]","table":"posts","columns":["user_id","title"]},{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE CASCADE","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated\nON posts\nAFTER UPDATE\nAS\nBEGIN\n UPDATE users SET updated = GETDATE()\n WHERE id = ( SELECT user_id FROM deleted)\nEND;"}],"labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"comments","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"post_id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"comments","columns":["id"]},{"name":"UQ__comments_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"]},{"name":"comments_post_id_user_id_idx","def":"NONCLUSTERED, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_id_pk","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"comments","columns":["id"]},{"name":"UQ__comments_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"]},{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(post_id) REFERENCES posts(id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}]},{"name":"comment_stars","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"int","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"UQ__comment__*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, comment_post_id, comment_user_id ]","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"UQ__comment__*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, comment_post_id, comment_user_id ]","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]},{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(comment_user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]}]},{"name":"logs","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"int","nullable":true},{"name":"comment_id","type":"int","nullable":true},{"name":"comment_star_id","type":"int","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"date","nullable":false}]},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"int","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"date","nullable":true,"comment":"comments.created"},{"name":"updated","type":"date","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (\n SELECT c.id, p.title, u2.username AS post_user, c.comment, u2.username AS comment_user, c.created, c.updated\n FROM posts AS p\n LEFT JOIN comments AS c on p.id = c.post_id\n LEFT JOIN users AS u on u.id = p.user_id\n LEFT JOIN users AS u2 on u2.id = c.user_id\n);","referenced_tables":["posts","comments","users"]},{"name":"CamelizeTable","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"created","type":"date","nullable":false}]},{"name":"hyphen-table","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"date","nullable":false}]},{"name":"administrator.blogs","type":"BASIC TABLE","comment":"admin blogs","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"PK__blogs_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"administrator.blogs","columns":["id"]}],"constraints":[{"name":"PK__blogs_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"administrator.blogs","columns":["id"]},{"name":"blogs_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE CASCADE","table":"administrator.blogs","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}]},{"name":"name with spaces","type":"VIEW","columns":[{"name":"title","type":"varchar(255)","nullable":false}],"def":"CREATE VIEW \"name with spaces\" AS (\n SELECT TOP 1 p.title\n FROM posts AS p\n);","referenced_tables":["posts"]},{"name":"Sales.Product","type":"BASIC TABLE","columns":[{"name":"ProductID","type":"int","nullable":false},{"name":"SalesPersonID","type":"int","nullable":true}],"indexes":[{"name":"PK__Product_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ ProductID ]","table":"Sales.Product","columns":["ProductID"]},{"name":"UQ__Product_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ SalesPersonID ]","table":"Sales.Product","columns":["SalesPersonID"]}],"constraints":[{"name":"PK__Product_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ ProductID ]","table":"Sales.Product","columns":["ProductID"]},{"name":"UQ__Product_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ SalesPersonID ]","table":"Sales.Product","columns":["SalesPersonID"]}]},{"name":"Rabbits.Running","type":"BASIC TABLE","columns":[{"name":"LocationID","type":"int","nullable":false},{"name":"ProductID","type":"int","nullable":true},{"name":"EmployeeID","type":"int","nullable":true}],"indexes":[{"name":"PK__Running_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ LocationID ]","table":"Rabbits.Running","columns":["LocationID"]},{"name":"UQ__Running_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ EmployeeID ]","table":"Rabbits.Running","columns":["EmployeeID"]},{"name":"UQ__Running_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ ProductID ]","table":"Rabbits.Running","columns":["ProductID"]}],"constraints":[{"name":"PK__Running_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ LocationID ]","table":"Rabbits.Running","columns":["LocationID"]},{"name":"UQ__Running_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ EmployeeID ]","table":"Rabbits.Running","columns":["EmployeeID"]},{"name":"UQ__Running_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ ProductID ]","table":"Rabbits.Running","columns":["ProductID"]},{"name":"FK_TempSales_SalesReason","type":"FOREIGN KEY","def":"FOREIGN KEY(ProductID) REFERENCES Sales.Product(SalesPersonID) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"Rabbits.Running","referenced_table":"Sales.Product","columns":["ProductID"],"referenced_columns":["SalesPersonID"]}]}],"relations":[{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":""},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":""},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":""},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":""},{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":""},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"Exactly one","def":""},{"table":"administrator.blogs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":""},{"table":"Rabbits.Running","columns":["ProductID"],"cardinality":"Zero or one","parent_table":"Sales.Product","parent_columns":["SalesPersonID"],"parent_cardinality":"Zero or one","def":""},{"table":"logs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"Zero or more","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true}],"functions":[{"name":"dbo.get_user","return_type":"","arguments":"@userid int","type":"SQL inline table-valued function"},{"name":"dbo.What_DB_is_that","return_type":"","arguments":"@ID int","type":"SQL Stored Procedure"}],"driver":{"name":"sqlserver","database_version":"Microsoft SQL Server 2019 (RTM-CU30) (KB5049235) - 15.0.4415.2 (X64) \n\tNov 18 2024 17:45:37 \n\tCopyright (C) 2019 Microsoft Corporation\n\tDeveloper Edition (64-bit) on Linux (Ubuntu 20.04.6 LTS) \u003cX64\u003e","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/mysql/schema.json b/sample/mysql/schema.json index b0a5c42b..901682cb 100644 --- a/sample/mysql/schema.json +++ b/sample/mysql/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com","labels":[{"name":"secure","virtual":true}]},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"Exactly one","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/mysql56/schema.json b/sample/mysql56/schema.json index f46741c8..916a81dc 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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment_post_id","type":"bigint(20)","nullable":false},{"name":"comment_user_id","type":"int(11)","nullable":false},{"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"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint(20)","nullable":false},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"post_id","type":"bigint(20)","nullable":true},{"name":"comment_id","type":"bigint(20)","nullable":true},{"name":"comment_star_id","type":"bigint(20)","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint(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,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS ((select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`)))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint(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},{"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"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int(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,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"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"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]}],"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}],"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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment_post_id","type":"bigint(20)","nullable":false},{"name":"comment_user_id","type":"int(11)","nullable":false},{"name":"created","type":"timestamp","nullable":false,"default":"CURRENT_TIMESTAMP","extra_def":"on update CURRENT_TIMESTAMP"},{"name":"updated","type":"timestamp","nullable":false,"default":"0000-00-00 00:00:00"}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint(20)","nullable":false},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"post_id","type":"bigint(20)","nullable":true},{"name":"comment_id","type":"bigint(20)","nullable":true},{"name":"comment_star_id","type":"bigint(20)","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint(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,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS ((select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`)))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint(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},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false,"default":"CURRENT_TIMESTAMP","extra_def":"on update CURRENT_TIMESTAMP"},{"name":"updated","type":"timestamp","nullable":false,"default":"0000-00-00 00:00:00"}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int(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,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false,"default":"CURRENT_TIMESTAMP","extra_def":"on update CURRENT_TIMESTAMP"},{"name":"updated","type":"timestamp","nullable":false,"default":"0000-00-00 00:00:00"}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]}],"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)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"Exactly one","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Additional Relation","virtual":true}],"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 3dfc1329..e819c6f0 100644 --- a/sample/number/schema.json +++ b/sample/number/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/png/schema.json b/sample/png/schema.json index b0a5c42b..901682cb 100644 --- a/sample/png/schema.json +++ b/sample/png/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com","labels":[{"name":"secure","virtual":true}]},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"Exactly one","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/postgres/schema.json b/sample/postgres/schema.json index ac529da7..b649de22 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},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"users_pkey","def":"CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)","table":"public.users","columns":["id"]},{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)","table":"public.users","columns":["username"]},{"name":"users_email_key","def":"CREATE UNIQUE INDEX users_email_key ON public.users USING btree (email)","table":"public.users","columns":["email"]}],"constraints":[{"name":"users_username_check","type":"CHECK","def":"CHECK ((char_length((username)::text) \u003e 4))","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.users","referenced_table":"","columns":["id"]},{"name":"users_username_key","type":"UNIQUE","def":"UNIQUE (username)","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_email_key","type":"UNIQUE","def":"UNIQUE (email)","table":"public.users","referenced_table":"","columns":["email"]}],"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"}]},{"name":"public.user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"integer","nullable":false},{"name":"show_email","type":"boolean","nullable":false,"default":"false","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}]},{"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},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'::character varying","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"post_types","nullable":false,"comment":"public/private/draft"},{"name":"labels","type":"varchar(50)[]","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CREATE UNIQUE INDEX posts_id_pk ON public.posts USING btree (id)","table":"public.posts","columns":["id"]},{"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":["user_id","title"]},{"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"]},{"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"]},{"name":"posts_user_id_title_key","type":"UNIQUE","def":"UNIQUE (user_id, title)","table":"public.posts","referenced_table":"","columns":["user_id","title"]}],"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"}]},{"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},{"name":"user_id","type":"integer","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (post_id * '-1'::integer) STORED"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CREATE UNIQUE INDEX comments_id_pk ON public.comments USING btree (id)","table":"public.comments","columns":["id"]},{"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"]},{"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"]}],"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"]},{"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"]},{"name":"comments_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.comments","referenced_table":"","columns":["id"]},{"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"]}]},{"name":"public.comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"user_id","type":"integer","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"integer","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","table":"public.comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id)","table":"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"]},{"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"]}]},{"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},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"uuid","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false}]},{"name":"public.post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"timestamp without time zone","nullable":true,"comment":"comments.created"},{"name":"updated","type":"timestamp without time zone","nullable":true,"comment":"comments.updated"}],"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","columns":[{"name":"id","type":"uuid","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"comment_star_user","type":"varchar(50)","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false}],"indexes":[{"name":"CamelizeTable_id_key","def":"CREATE UNIQUE INDEX \"CamelizeTable_id_key\" ON public.\"CamelizeTable\" USING btree (id)","table":"public.CamelizeTable","columns":["id"]}],"constraints":[{"name":"CamelizeTable_id_key","type":"UNIQUE","def":"UNIQUE (id)","table":"public.CamelizeTable","referenced_table":"","columns":["id"]}]},{"name":"public.hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"hyphen-column","type":"text","nullable":false},{"name":"CamelizeTableId","type":"uuid","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false}],"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"]}],"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"]},{"name":"hyphen-table_hyphen-column_key","type":"UNIQUE","def":"UNIQUE (\"hyphen-column\")","table":"public.hyphen-table","referenced_table":"","columns":["hyphen-column"]}]},{"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},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON administrator.blogs USING btree (id)","table":"administrator.blogs","columns":["id"]}],"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"]},{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"administrator.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blogs","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blogs_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false},{"name":"dump","type":"text","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON backup.blogs USING btree (id)","table":"backup.blogs","columns":["id"]}],"constraints":[{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blog_options","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blog_options_id_seq'::regclass)","comment":""},{"name":"blog_id","type":"integer","nullable":false},{"name":"label","type":"text","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}],"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"]},{"name":"blog_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blog_options","referenced_table":"","columns":["id"]}]},{"name":"time.bar","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"indexes":[{"name":"bar_pkey","def":"CREATE UNIQUE INDEX bar_pkey ON \"time\".bar USING btree (id)","table":"time.bar","columns":["id"]}],"constraints":[{"name":"bar_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.bar","referenced_table":"","columns":["id"]}]},{"name":"time.hyphenated-table","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"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"]}],"constraints":[{"name":"hyphenated-table_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.hyphenated-table","referenced_table":"","columns":["id"]}]},{"name":"time.referencing","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false},{"name":"bar_id","type":"integer","nullable":false},{"name":"ht_id","type":"integer","nullable":false}],"indexes":[{"name":"referencing_pkey","def":"CREATE UNIQUE INDEX referencing_pkey ON \"time\".referencing USING btree (id)","table":"time.referencing","columns":["id"]}],"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"]},{"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"]},{"name":"referencing_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.referencing","referenced_table":"","columns":["id"]}]}],"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"}],"enums":[{"name":"public.post_types","values":["draft","private","public"]}],"driver":{"name":"postgres","database_version":"PostgreSQL 15.10 (Debian 15.10-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit","meta":{"current_schema":"public","search_paths":["postgres","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}},"viewpoints":[{"name":"post","desc":"for post","tables":["public.post*"]},{"name":"administrator","desc":"administrator schema only","tables":["administrator.*"]}]} +{"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)"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"users_pkey","def":"CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)","table":"public.users","columns":["id"]},{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)","table":"public.users","columns":["username"]},{"name":"users_email_key","def":"CREATE UNIQUE INDEX users_email_key ON public.users USING btree (email)","table":"public.users","columns":["email"]}],"constraints":[{"name":"users_username_check","type":"CHECK","def":"CHECK ((char_length((username)::text) \u003e 4))","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.users","referenced_table":"","columns":["id"]},{"name":"users_username_key","type":"UNIQUE","def":"UNIQUE (username)","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_email_key","type":"UNIQUE","def":"UNIQUE (email)","table":"public.users","referenced_table":"","columns":["email"]}],"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"}]},{"name":"public.user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"integer","nullable":false},{"name":"show_email","type":"boolean","nullable":false,"default":"false"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}]},{"name":"public.posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"default":"nextval('posts_id_seq'::regclass)"},{"name":"user_id","type":"integer","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'::character varying"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"post_types","nullable":false,"comment":"public/private/draft"},{"name":"labels","type":"varchar(50)[]","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CREATE UNIQUE INDEX posts_id_pk ON public.posts USING btree (id)","table":"public.posts","columns":["id"]},{"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":["user_id","title"]},{"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"]},{"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"]},{"name":"posts_user_id_title_key","type":"UNIQUE","def":"UNIQUE (user_id, title)","table":"public.posts","referenced_table":"","columns":["user_id","title"]}],"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"}]},{"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)"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"integer","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (post_id * '-1'::integer) STORED"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CREATE UNIQUE INDEX comments_id_pk ON public.comments USING btree (id)","table":"public.comments","columns":["id"]},{"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"]},{"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"]}],"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"]},{"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"]},{"name":"comments_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.comments","referenced_table":"","columns":["id"]},{"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"]}]},{"name":"public.comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"user_id","type":"integer","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"integer","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","table":"public.comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id)","table":"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"]},{"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"]}]},{"name":"public.logs","type":"BASE TABLE","comment":"audit log table","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"user_id","type":"integer","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"uuid","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false}]},{"name":"public.post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"timestamp without time zone","nullable":true,"comment":"comments.created"},{"name":"updated","type":"timestamp without time zone","nullable":true,"comment":"comments.updated"}],"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","columns":[{"name":"id","type":"uuid","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"comment_star_user","type":"varchar(50)","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"created","type":"timestamp without time zone","nullable":false}],"indexes":[{"name":"CamelizeTable_id_key","def":"CREATE UNIQUE INDEX \"CamelizeTable_id_key\" ON public.\"CamelizeTable\" USING btree (id)","table":"public.CamelizeTable","columns":["id"]}],"constraints":[{"name":"CamelizeTable_id_key","type":"UNIQUE","def":"UNIQUE (id)","table":"public.CamelizeTable","referenced_table":"","columns":["id"]}]},{"name":"public.hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"CamelizeTableId","type":"uuid","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false}],"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"]}],"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"]},{"name":"hyphen-table_hyphen-column_key","type":"UNIQUE","def":"UNIQUE (\"hyphen-column\")","table":"public.hyphen-table","referenced_table":"","columns":["hyphen-column"]}]},{"name":"administrator.blogs","type":"BASE TABLE","comment":"admin blogs","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('administrator.blogs_id_seq'::regclass)"},{"name":"user_id","type":"integer","nullable":false},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON administrator.blogs USING btree (id)","table":"administrator.blogs","columns":["id"]}],"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"]},{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"administrator.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blogs","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blogs_id_seq'::regclass)"},{"name":"user_id","type":"integer","nullable":false},{"name":"dump","type":"text","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON backup.blogs USING btree (id)","table":"backup.blogs","columns":["id"]}],"constraints":[{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blog_options","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blog_options_id_seq'::regclass)"},{"name":"blog_id","type":"integer","nullable":false},{"name":"label","type":"text","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}],"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"]},{"name":"blog_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blog_options","referenced_table":"","columns":["id"]}]},{"name":"time.bar","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"indexes":[{"name":"bar_pkey","def":"CREATE UNIQUE INDEX bar_pkey ON \"time\".bar USING btree (id)","table":"time.bar","columns":["id"]}],"constraints":[{"name":"bar_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.bar","referenced_table":"","columns":["id"]}]},{"name":"time.hyphenated-table","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"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"]}],"constraints":[{"name":"hyphenated-table_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.hyphenated-table","referenced_table":"","columns":["id"]}]},{"name":"time.referencing","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false},{"name":"bar_id","type":"integer","nullable":false},{"name":"ht_id","type":"integer","nullable":false}],"indexes":[{"name":"referencing_pkey","def":"CREATE UNIQUE INDEX referencing_pkey ON \"time\".referencing USING btree (id)","table":"time.referencing","columns":["id"]}],"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"]},{"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"]},{"name":"referencing_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.referencing","referenced_table":"","columns":["id"]}]}],"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"},{"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)"},{"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)"},{"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)"},{"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)"},{"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)"},{"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"},{"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"},{"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"},{"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)"},{"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)"},{"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"}],"enums":[{"name":"public.post_types","values":["draft","private","public"]}],"driver":{"name":"postgres","database_version":"PostgreSQL 15.10 (Debian 15.10-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit","meta":{"current_schema":"public","search_paths":["postgres","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}},"viewpoints":[{"name":"post","desc":"for post","tables":["public.post*"]},{"name":"administrator","desc":"administrator schema only","tables":["administrator.*"]}]} diff --git a/sample/postgres95/schema.json b/sample/postgres95/schema.json index 5b3953ed..53e4ee6e 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},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"users_pkey","def":"CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)","table":"public.users","columns":["id"]},{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)","table":"public.users","columns":["username"]},{"name":"users_email_key","def":"CREATE UNIQUE INDEX users_email_key ON public.users USING btree (email)","table":"public.users","columns":["email"]}],"constraints":[{"name":"users_username_check","type":"CHECK","def":"CHECK ((char_length((username)::text) \u003e 4))","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.users","referenced_table":"","columns":["id"]},{"name":"users_username_key","type":"UNIQUE","def":"UNIQUE (username)","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_email_key","type":"UNIQUE","def":"UNIQUE (email)","table":"public.users","referenced_table":"","columns":["email"]}],"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"}]},{"name":"public.user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"integer","nullable":false},{"name":"show_email","type":"boolean","nullable":false,"default":"false","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}]},{"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},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'::character varying","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"post_types","nullable":false,"comment":"public/private/draft"},{"name":"labels","type":"varchar(50)[]","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CREATE UNIQUE INDEX posts_id_pk ON public.posts USING btree (id)","table":"public.posts","columns":["id"]},{"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":["user_id","title"]},{"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"]},{"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"]},{"name":"posts_user_id_title_key","type":"UNIQUE","def":"UNIQUE (user_id, title)","table":"public.posts","referenced_table":"","columns":["user_id","title"]}],"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"}]},{"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},{"name":"user_id","type":"integer","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CREATE UNIQUE INDEX comments_id_pk ON public.comments USING btree (id)","table":"public.comments","columns":["id"]},{"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"]},{"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"]}],"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"]},{"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"]},{"name":"comments_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.comments","referenced_table":"","columns":["id"]},{"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"]}]},{"name":"public.comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"user_id","type":"integer","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"integer","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","table":"public.comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id)","table":"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"]},{"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"]}]},{"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},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"uuid","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false}]},{"name":"public.post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"timestamp without time zone","nullable":true,"comment":"comments.created"},{"name":"updated","type":"timestamp without time zone","nullable":true,"comment":"comments.updated"}],"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","columns":[{"name":"id","type":"uuid","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"comment_star_user","type":"varchar(50)","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"created","type":"timestamp without time zone","nullable":false}],"indexes":[{"name":"CamelizeTable_id_key","def":"CREATE UNIQUE INDEX \"CamelizeTable_id_key\" ON public.\"CamelizeTable\" USING btree (id)","table":"public.CamelizeTable","columns":["id"]}],"constraints":[{"name":"CamelizeTable_id_key","type":"UNIQUE","def":"UNIQUE (id)","table":"public.CamelizeTable","referenced_table":"","columns":["id"]}]},{"name":"public.hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()","comment":""},{"name":"hyphen-column","type":"text","nullable":false},{"name":"CamelizeTableId","type":"uuid","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false}],"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"]}],"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"]},{"name":"hyphen-table_hyphen-column_key","type":"UNIQUE","def":"UNIQUE (\"hyphen-column\")","table":"public.hyphen-table","referenced_table":"","columns":["hyphen-column"]}]},{"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},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON administrator.blogs USING btree (id)","table":"administrator.blogs","columns":["id"]}],"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"]},{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"administrator.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blogs","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blogs_id_seq'::regclass)","comment":""},{"name":"user_id","type":"integer","nullable":false},{"name":"dump","type":"text","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON backup.blogs USING btree (id)","table":"backup.blogs","columns":["id"]}],"constraints":[{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blog_options","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blog_options_id_seq'::regclass)","comment":""},{"name":"blog_id","type":"integer","nullable":false},{"name":"label","type":"text","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}],"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"]},{"name":"blog_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blog_options","referenced_table":"","columns":["id"]}]},{"name":"time.bar","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"indexes":[{"name":"bar_pkey","def":"CREATE UNIQUE INDEX bar_pkey ON \"time\".bar USING btree (id)","table":"time.bar","columns":["id"]}],"constraints":[{"name":"bar_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.bar","referenced_table":"","columns":["id"]}]},{"name":"time.hyphenated-table","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"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"]}],"constraints":[{"name":"hyphenated-table_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.hyphenated-table","referenced_table":"","columns":["id"]}]},{"name":"time.referencing","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false},{"name":"bar_id","type":"integer","nullable":false},{"name":"ht_id","type":"integer","nullable":false}],"indexes":[{"name":"referencing_pkey","def":"CREATE UNIQUE INDEX referencing_pkey ON \"time\".referencing USING btree (id)","table":"time.referencing","columns":["id"]}],"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"]},{"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"]},{"name":"referencing_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.referencing","referenced_table":"","columns":["id"]}]}],"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"}],"enums":[{"name":"public.post_types","values":["draft","private","public"]}],"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":["postgres","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}},"viewpoints":[{"name":"post","desc":"for post","tables":["public.post*"]},{"name":"administrator","desc":"administrator schema only","tables":["administrator.*"]}]} +{"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)"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"users_pkey","def":"CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)","table":"public.users","columns":["id"]},{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)","table":"public.users","columns":["username"]},{"name":"users_email_key","def":"CREATE UNIQUE INDEX users_email_key ON public.users USING btree (email)","table":"public.users","columns":["email"]}],"constraints":[{"name":"users_username_check","type":"CHECK","def":"CHECK ((char_length((username)::text) \u003e 4))","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.users","referenced_table":"","columns":["id"]},{"name":"users_username_key","type":"UNIQUE","def":"UNIQUE (username)","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_email_key","type":"UNIQUE","def":"UNIQUE (email)","table":"public.users","referenced_table":"","columns":["email"]}],"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"}]},{"name":"public.user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"integer","nullable":false},{"name":"show_email","type":"boolean","nullable":false,"default":"false"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}]},{"name":"public.posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"default":"nextval('posts_id_seq'::regclass)"},{"name":"user_id","type":"integer","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'::character varying"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"post_types","nullable":false,"comment":"public/private/draft"},{"name":"labels","type":"varchar(50)[]","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CREATE UNIQUE INDEX posts_id_pk ON public.posts USING btree (id)","table":"public.posts","columns":["id"]},{"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":["user_id","title"]},{"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"]},{"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"]},{"name":"posts_user_id_title_key","type":"UNIQUE","def":"UNIQUE (user_id, title)","table":"public.posts","referenced_table":"","columns":["user_id","title"]}],"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"}]},{"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)"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"integer","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CREATE UNIQUE INDEX comments_id_pk ON public.comments USING btree (id)","table":"public.comments","columns":["id"]},{"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"]},{"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"]}],"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"]},{"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"]},{"name":"comments_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.comments","referenced_table":"","columns":["id"]},{"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"]}]},{"name":"public.comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"user_id","type":"integer","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"integer","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","table":"public.comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id)","table":"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"]},{"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"]}]},{"name":"public.logs","type":"BASE TABLE","comment":"audit log table","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"user_id","type":"integer","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"uuid","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false}]},{"name":"public.post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"timestamp without time zone","nullable":true,"comment":"comments.created"},{"name":"updated","type":"timestamp without time zone","nullable":true,"comment":"comments.updated"}],"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","columns":[{"name":"id","type":"uuid","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"comment_star_user","type":"varchar(50)","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"created","type":"timestamp without time zone","nullable":false}],"indexes":[{"name":"CamelizeTable_id_key","def":"CREATE UNIQUE INDEX \"CamelizeTable_id_key\" ON public.\"CamelizeTable\" USING btree (id)","table":"public.CamelizeTable","columns":["id"]}],"constraints":[{"name":"CamelizeTable_id_key","type":"UNIQUE","def":"UNIQUE (id)","table":"public.CamelizeTable","referenced_table":"","columns":["id"]}]},{"name":"public.hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"CamelizeTableId","type":"uuid","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false}],"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"]}],"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"]},{"name":"hyphen-table_hyphen-column_key","type":"UNIQUE","def":"UNIQUE (\"hyphen-column\")","table":"public.hyphen-table","referenced_table":"","columns":["hyphen-column"]}]},{"name":"administrator.blogs","type":"BASE TABLE","comment":"admin blogs","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('administrator.blogs_id_seq'::regclass)"},{"name":"user_id","type":"integer","nullable":false},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON administrator.blogs USING btree (id)","table":"administrator.blogs","columns":["id"]}],"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"]},{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"administrator.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blogs","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blogs_id_seq'::regclass)"},{"name":"user_id","type":"integer","nullable":false},{"name":"dump","type":"text","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON backup.blogs USING btree (id)","table":"backup.blogs","columns":["id"]}],"constraints":[{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blog_options","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blog_options_id_seq'::regclass)"},{"name":"blog_id","type":"integer","nullable":false},{"name":"label","type":"text","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}],"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"]},{"name":"blog_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blog_options","referenced_table":"","columns":["id"]}]},{"name":"time.bar","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"indexes":[{"name":"bar_pkey","def":"CREATE UNIQUE INDEX bar_pkey ON \"time\".bar USING btree (id)","table":"time.bar","columns":["id"]}],"constraints":[{"name":"bar_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.bar","referenced_table":"","columns":["id"]}]},{"name":"time.hyphenated-table","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"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"]}],"constraints":[{"name":"hyphenated-table_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.hyphenated-table","referenced_table":"","columns":["id"]}]},{"name":"time.referencing","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false},{"name":"bar_id","type":"integer","nullable":false},{"name":"ht_id","type":"integer","nullable":false}],"indexes":[{"name":"referencing_pkey","def":"CREATE UNIQUE INDEX referencing_pkey ON \"time\".referencing USING btree (id)","table":"time.referencing","columns":["id"]}],"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"]},{"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"]},{"name":"referencing_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.referencing","referenced_table":"","columns":["id"]}]}],"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"},{"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"},{"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)"},{"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)"},{"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)"},{"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)"},{"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"},{"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"},{"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"},{"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)"},{"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)"},{"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"}],"enums":[{"name":"public.post_types","values":["draft","private","public"]}],"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":["postgres","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}},"viewpoints":[{"name":"post","desc":"for post","tables":["public.post*"]},{"name":"administrator","desc":"administrator schema only","tables":["administrator.*"]}]} diff --git a/sample/sqlite/schema.json b/sample/sqlite/schema.json index 06d41d63..c28290db 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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"username","type":"TEXT","nullable":false},{"name":"password","type":"TEXT","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"TEXT","nullable":false,"labels":[{"name":"secure","virtual":true}]},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"indexes":[{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON users(username)","table":"users","columns":["username"]},{"name":"sqlite_autoindex_users_2","def":"UNIQUE (email)","table":"users","columns":["email"]},{"name":"sqlite_autoindex_users_1","def":"UNIQUE (username)","table":"users","columns":["username"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"sqlite_autoindex_users_2","type":"UNIQUE","def":"UNIQUE (email)","table":"users","columns":["email"]},{"name":"sqlite_autoindex_users_1","type":"UNIQUE","def":"UNIQUE (username)","table":"users","columns":["username"]},{"name":"-","type":"CHECK","def":"CHECK(length(username) \u003e 4)","table":"users","columns":["username"]}],"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","columns":[{"name":"user_id","type":"INTEGER","nullable":true},{"name":"show_email","type":"INTEGER","nullable":false,"default":"0","comment":""},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"constraints":[{"name":"user_id","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"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"]}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"title","type":"TEXT","nullable":false},{"name":"body","type":"TEXT","nullable":false,"comment":"post body"},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"CREATE INDEX posts_user_id_idx ON posts(user_id)","table":"posts","columns":["user_id"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"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"]}],"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"}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"post_id","type":"INTEGER","nullable":false},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"comment","type":"TEXT","nullable":false},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"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"]},{"name":"sqlite_autoindex_comments_1","def":"UNIQUE (post_id, user_id)","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]},{"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"]},{"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"]},{"name":"sqlite_autoindex_comments_1","type":"UNIQUE","def":"UNIQUE (post_id, user_id)","table":"comments","columns":["post_id","user_id"]}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"comment_post_id","type":"INTEGER","nullable":false},{"name":"comment_user_id","type":"INTEGER","nullable":false},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"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"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"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"]},{"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"]},{"name":"sqlite_autoindex_comment_stars_1","type":"UNIQUE","def":"UNIQUE (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE comment_stars (\n id 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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"post_id","type":"INTEGER","nullable":true},{"name":"comment_id","type":"INTEGER","nullable":true},{"name":"comment_star_id","type":"INTEGER","nullable":true},{"name":"payload","type":"TEXT","nullable":true},{"name":"created","type":"NUMERIC","nullable":false}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"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,"comment":"comments.id"},{"name":"title","type":"TEXT","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"TEXT","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"TEXT","nullable":true},{"name":"comment_user","type":"TEXT","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"NUMERIC","nullable":true,"comment":"comments.created"},{"name":"updated","type":"NUMERIC","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS\n SELECT c.id, p.title, u2.username AS post_user, c.comment, u2.username AS comment_user, c.created, c.updated\n FROM posts AS p\n LEFT JOIN comments AS c on p.id = c.post_id\n LEFT JOIN users AS u on u.id = p.user_id\n LEFT JOIN users AS u2 on u2.id = c.user_id","referenced_tables":["posts","comments","users"]},{"name":"CamelizeTable","type":"table","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"created","type":"NUMERIC","nullable":false}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE CamelizeTable (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n created NUMERIC NOT NULL\n)"},{"name":"hyphen-table","type":"table","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"hyphen-column","type":"TEXT","nullable":false},{"name":"created","type":"NUMERIC","nullable":false}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"col","type":"TEXT","nullable":true},{"name":"brackets","type":"TEXT","nullable":false},{"name":"checkcheck","type":"TEXT","nullable":false},{"name":"downcase","type":"TEXT","nullable":false},{"name":"nl","type":"TEXT","nullable":false}],"indexes":[{"name":"sqlite_autoindex_check_constraints_4","def":"UNIQUE (nl)","table":"check_constraints","columns":["nl"]},{"name":"sqlite_autoindex_check_constraints_3","def":"UNIQUE (downcase)","table":"check_constraints","columns":["downcase"]},{"name":"sqlite_autoindex_check_constraints_2","def":"UNIQUE (checkcheck)","table":"check_constraints","columns":["checkcheck"]},{"name":"sqlite_autoindex_check_constraints_1","def":"UNIQUE (brackets)","table":"check_constraints","columns":["brackets"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"check_constraints","columns":["id"]},{"name":"sqlite_autoindex_check_constraints_4","type":"UNIQUE","def":"UNIQUE (nl)","table":"check_constraints","columns":["nl"]},{"name":"sqlite_autoindex_check_constraints_3","type":"UNIQUE","def":"UNIQUE (downcase)","table":"check_constraints","columns":["downcase"]},{"name":"sqlite_autoindex_check_constraints_2","type":"UNIQUE","def":"UNIQUE (checkcheck)","table":"check_constraints","columns":["checkcheck"]},{"name":"sqlite_autoindex_check_constraints_1","type":"UNIQUE","def":"UNIQUE (brackets)","table":"check_constraints","columns":["brackets"]},{"name":"-","type":"CHECK","def":"CHECK(length(col) \u003e 4)","table":"check_constraints","columns":["col"]},{"name":"-","type":"CHECK","def":"CHECK(((length(brackets) \u003e 4)))","table":"check_constraints","columns":["brackets"]},{"name":"-","type":"CHECK","def":"CHECK(length(checkcheck) \u003e 4)","table":"check_constraints","columns":["checkcheck"]},{"name":"-","type":"CHECK","def":"check(length(downcase) \u003e 4)","table":"check_constraints","columns":["downcase"]},{"name":"-","type":"CHECK","def":"check(length(nl) \u003e 4 OR nl != 'ln')","table":"check_constraints","columns":["nl"]}],"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","columns":[{"name":"logs","type":"","nullable":true}],"def":"CREATE VIRTUAL TABLE syslog USING fts3(logs)"},{"name":"access_log","type":"virtual table","columns":[{"name":"logs","type":"","nullable":true}],"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}],"driver":{"name":"sqlite","database_version":"3.46.1"},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} +{"name":"testdb.sqlite3","desc":"Sample database document.","tables":[{"name":"users","type":"table","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"username","type":"TEXT","nullable":false},{"name":"password","type":"TEXT","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"TEXT","nullable":false,"labels":[{"name":"secure","virtual":true}]},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"indexes":[{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON users(username)","table":"users","columns":["username"]},{"name":"sqlite_autoindex_users_2","def":"UNIQUE (email)","table":"users","columns":["email"]},{"name":"sqlite_autoindex_users_1","def":"UNIQUE (username)","table":"users","columns":["username"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"sqlite_autoindex_users_2","type":"UNIQUE","def":"UNIQUE (email)","table":"users","columns":["email"]},{"name":"sqlite_autoindex_users_1","type":"UNIQUE","def":"UNIQUE (username)","table":"users","columns":["username"]},{"name":"-","type":"CHECK","def":"CHECK(length(username) \u003e 4)","table":"users","columns":["username"]}],"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","columns":[{"name":"user_id","type":"INTEGER","nullable":true},{"name":"show_email","type":"INTEGER","nullable":false,"default":"0"},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"constraints":[{"name":"user_id","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"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"]}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"title","type":"TEXT","nullable":false},{"name":"body","type":"TEXT","nullable":false,"comment":"post body"},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"CREATE INDEX posts_user_id_idx ON posts(user_id)","table":"posts","columns":["user_id"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"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"]}],"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"}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"post_id","type":"INTEGER","nullable":false},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"comment","type":"TEXT","nullable":false},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"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"]},{"name":"sqlite_autoindex_comments_1","def":"UNIQUE (post_id, user_id)","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]},{"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"]},{"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"]},{"name":"sqlite_autoindex_comments_1","type":"UNIQUE","def":"UNIQUE (post_id, user_id)","table":"comments","columns":["post_id","user_id"]}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"comment_post_id","type":"INTEGER","nullable":false},{"name":"comment_user_id","type":"INTEGER","nullable":false},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"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"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"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"]},{"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"]},{"name":"sqlite_autoindex_comment_stars_1","type":"UNIQUE","def":"UNIQUE (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE comment_stars (\n id 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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"post_id","type":"INTEGER","nullable":true},{"name":"comment_id","type":"INTEGER","nullable":true},{"name":"comment_star_id","type":"INTEGER","nullable":true},{"name":"payload","type":"TEXT","nullable":true},{"name":"created","type":"NUMERIC","nullable":false}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"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,"comment":"comments.id"},{"name":"title","type":"TEXT","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"TEXT","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"TEXT","nullable":true},{"name":"comment_user","type":"TEXT","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"NUMERIC","nullable":true,"comment":"comments.created"},{"name":"updated","type":"NUMERIC","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS\n SELECT c.id, p.title, u2.username AS post_user, c.comment, u2.username AS comment_user, c.created, c.updated\n FROM posts AS p\n LEFT JOIN comments AS c on p.id = c.post_id\n LEFT JOIN users AS u on u.id = p.user_id\n LEFT JOIN users AS u2 on u2.id = c.user_id","referenced_tables":["posts","comments","users"]},{"name":"CamelizeTable","type":"table","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"created","type":"NUMERIC","nullable":false}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE CamelizeTable (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n created NUMERIC NOT NULL\n)"},{"name":"hyphen-table","type":"table","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"hyphen-column","type":"TEXT","nullable":false},{"name":"created","type":"NUMERIC","nullable":false}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"col","type":"TEXT","nullable":true},{"name":"brackets","type":"TEXT","nullable":false},{"name":"checkcheck","type":"TEXT","nullable":false},{"name":"downcase","type":"TEXT","nullable":false},{"name":"nl","type":"TEXT","nullable":false}],"indexes":[{"name":"sqlite_autoindex_check_constraints_4","def":"UNIQUE (nl)","table":"check_constraints","columns":["nl"]},{"name":"sqlite_autoindex_check_constraints_3","def":"UNIQUE (downcase)","table":"check_constraints","columns":["downcase"]},{"name":"sqlite_autoindex_check_constraints_2","def":"UNIQUE (checkcheck)","table":"check_constraints","columns":["checkcheck"]},{"name":"sqlite_autoindex_check_constraints_1","def":"UNIQUE (brackets)","table":"check_constraints","columns":["brackets"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"check_constraints","columns":["id"]},{"name":"sqlite_autoindex_check_constraints_4","type":"UNIQUE","def":"UNIQUE (nl)","table":"check_constraints","columns":["nl"]},{"name":"sqlite_autoindex_check_constraints_3","type":"UNIQUE","def":"UNIQUE (downcase)","table":"check_constraints","columns":["downcase"]},{"name":"sqlite_autoindex_check_constraints_2","type":"UNIQUE","def":"UNIQUE (checkcheck)","table":"check_constraints","columns":["checkcheck"]},{"name":"sqlite_autoindex_check_constraints_1","type":"UNIQUE","def":"UNIQUE (brackets)","table":"check_constraints","columns":["brackets"]},{"name":"-","type":"CHECK","def":"CHECK(length(col) \u003e 4)","table":"check_constraints","columns":["col"]},{"name":"-","type":"CHECK","def":"CHECK(((length(brackets) \u003e 4)))","table":"check_constraints","columns":["brackets"]},{"name":"-","type":"CHECK","def":"CHECK(length(checkcheck) \u003e 4)","table":"check_constraints","columns":["checkcheck"]},{"name":"-","type":"CHECK","def":"check(length(downcase) \u003e 4)","table":"check_constraints","columns":["downcase"]},{"name":"-","type":"CHECK","def":"check(length(nl) \u003e 4 OR nl != 'ln')","table":"check_constraints","columns":["nl"]}],"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","columns":[{"name":"logs","type":"","nullable":true}],"def":"CREATE VIRTUAL TABLE syslog USING fts3(logs)"},{"name":"access_log","type":"virtual table","columns":[{"name":"logs","type":"","nullable":true}],"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"},{"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"},{"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"},{"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"},{"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"},{"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"},{"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}],"driver":{"name":"sqlite","database_version":"3.46.1"},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/viewpoints/schema.json b/sample/viewpoints/schema.json index 1721081b..77f7cfa5 100644 --- a/sample/viewpoints/schema.json +++ b/sample/viewpoints/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"labels":[{"name":"user","virtual":true}]},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci","labels":[{"name":"content","virtual":true}]},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false,"labels":[{"name":"user","virtual":true}]},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'","labels":[{"name":"content","virtual":true}]},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","labels":[{"name":"content","virtual":true}],"referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"labels":[{"name":"user","virtual":true}]},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":""},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"content","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0","comment":""},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'","labels":[{"name":"user","virtual":true}]},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com","labels":[{"name":"secure","virtual":true}]},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'","labels":[{"name":"user","virtual":true}]}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","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.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}],"viewpoints":[{"name":"Content","desc":"Content as an asset for blogging services","labels":["content"]},{"name":"Ops","desc":"Tables to be referenced during operation","tables":["logs","users","posts"]},{"name":"Around the users table","desc":"Tables related to the users table","tables":["users"],"distance":1,"groups":[{"name":"Content","desc":"Content as an asset for blogging services","labels":["content"]}]},{"name":"Secure data","desc":"Tables with secure data","labels":["secure"]}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"labels":[{"name":"user","virtual":true}]},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci","labels":[{"name":"content","virtual":true}]},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false,"labels":[{"name":"user","virtual":true}]},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'","labels":[{"name":"content","virtual":true}]},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","labels":[{"name":"content","virtual":true}],"referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"labels":[{"name":"user","virtual":true}]},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"content","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'","labels":[{"name":"user","virtual":true}]},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'","labels":[{"name":"user","virtual":true}]}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"Zero or more","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}],"viewpoints":[{"name":"Content","desc":"Content as an asset for blogging services","labels":["content"]},{"name":"Ops","desc":"Tables to be referenced during operation","tables":["logs","users","posts"]},{"name":"Around the users table","desc":"Tables related to the users table","tables":["users"],"distance":1,"groups":[{"name":"Content","desc":"Content as an asset for blogging services","labels":["content"]}]},{"name":"Secure data","desc":"Tables with secure data","labels":["secure"]}]} diff --git a/schema/json.go b/schema/json.go index 5ef0d5b3..9140cc7e 100644 --- a/schema/json.go +++ b/schema/json.go @@ -4,41 +4,8 @@ import ( "encoding/json" ) -// MarshalJSON return custom JSON byte -func (s Schema) MarshalJSON() ([]byte, error) { - if len(s.Tables) == 0 { - s.Tables = []*Table{} - } - - return json.Marshal(&struct { - Name string `json:"name,omitempty"` - Desc string `json:"desc,omitempty"` - Tables []*Table `json:"tables"` - Relations []*Relation `json:"relations,omitempty"` - Functions []*Function `json:"functions,omitempty"` - Enums []*Enum `json:"enums,omitempty"` - Driver *Driver `json:"driver,omitempty"` - Labels Labels `json:"labels,omitempty"` - Viewpoints []*Viewpoint `json:"viewpoints,omitempty"` - }{ - Name: s.Name, - Desc: s.Desc, - Tables: s.Tables, - Relations: s.Relations, - Driver: s.Driver, - Functions: s.Functions, - Enums: s.Enums, - Labels: s.Labels, - Viewpoints: s.Viewpoints, - }) -} - // MarshalJSON return custom JSON byte func (t Table) MarshalJSON() ([]byte, error) { - if len(t.Columns) == 0 { - t.Columns = []*Column{} - } - referencedTables := []string{} for _, rt := range t.ReferencedTables { referencedTables = append(referencedTables, rt.Name) @@ -136,7 +103,7 @@ func (r Relation) MarshalJSON() ([]byte, error) { ParentColumns []string `json:"parent_columns"` ParentCardinality string `json:"parent_cardinality,omitempty"` Def string `json:"def"` - Virtual bool `json:"virtual"` + Virtual bool `json:"virtual,omitempty"` }{ Table: r.Table.Name, Columns: columns, diff --git a/schema/yaml.go b/schema/yaml.go index 81ebe01c..4bb14b90 100644 --- a/schema/yaml.go +++ b/schema/yaml.go @@ -6,19 +6,6 @@ import ( // MarshalYAML return custom JSON byte func (t Table) MarshalYAML() ([]byte, error) { - if len(t.Columns) == 0 { - t.Columns = []*Column{} - } - if len(t.Indexes) == 0 { - t.Indexes = []*Index{} - } - if len(t.Constraints) == 0 { - t.Constraints = []*Constraint{} - } - if len(t.Triggers) == 0 { - t.Triggers = []*Trigger{} - } - referencedTables := []string{} for _, rt := range t.ReferencedTables { referencedTables = append(referencedTables, rt.Name) diff --git a/testdata/json_output_schema.golden b/testdata/json_output_schema.golden index 60084ee8..98a54973 100644 --- a/testdata/json_output_schema.golden +++ b/testdata/json_output_schema.golden @@ -113,8 +113,7 @@ "a" ], "parent_cardinality": "Exactly one", - "def": "FOREIGN KEY (b) REFERENCES a(a)", - "virtual": false + "def": "FOREIGN KEY (b) REFERENCES a(a)" } ], "enums": [ diff --git a/testdata/modify_schema_.golden b/testdata/modify_schema_.golden index 3414466f..0398b70b 100644 --- a/testdata/modify_schema_.golden +++ b/testdata/modify_schema_.golden @@ -303,8 +303,7 @@ "id" ], "parent_cardinality": "Exactly one", - "def": "FOREIGN KEY (category_id) REFERENCES categories (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE", - "virtual": false + "def": "FOREIGN KEY (category_id) REFERENCES categories (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" }, { "table": "posts", @@ -317,8 +316,7 @@ "id" ], "parent_cardinality": "Exactly one", - "def": "FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE", - "virtual": false + "def": "FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" }, { "table": "user_options", @@ -331,8 +329,7 @@ "id" ], "parent_cardinality": "Exactly one", - "def": "FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE", - "virtual": false + "def": "FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" } ], "driver": { diff --git a/testdata/modify_schema_mod_name_and_desc.golden b/testdata/modify_schema_mod_name_and_desc.golden index 575f01b9..174285c0 100644 --- a/testdata/modify_schema_mod_name_and_desc.golden +++ b/testdata/modify_schema_mod_name_and_desc.golden @@ -304,8 +304,7 @@ "id" ], "parent_cardinality": "Exactly one", - "def": "FOREIGN KEY (category_id) REFERENCES categories (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE", - "virtual": false + "def": "FOREIGN KEY (category_id) REFERENCES categories (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" }, { "table": "posts", @@ -318,8 +317,7 @@ "id" ], "parent_cardinality": "Exactly one", - "def": "FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE", - "virtual": false + "def": "FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" }, { "table": "user_options", @@ -332,8 +330,7 @@ "id" ], "parent_cardinality": "Exactly one", - "def": "FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE", - "virtual": false + "def": "FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" } ], "driver": { diff --git a/testdata/modify_schema_not_override.golden b/testdata/modify_schema_not_override.golden index 5207f1f0..6d647249 100644 --- a/testdata/modify_schema_not_override.golden +++ b/testdata/modify_schema_not_override.golden @@ -303,8 +303,7 @@ "id" ], "parent_cardinality": "Exactly one", - "def": "FOREIGN KEY (category_id) REFERENCES categories (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE", - "virtual": false + "def": "FOREIGN KEY (category_id) REFERENCES categories (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" }, { "table": "posts", @@ -317,8 +316,7 @@ "id" ], "parent_cardinality": "Exactly one", - "def": "FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE", - "virtual": false + "def": "FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" }, { "table": "user_options", @@ -331,8 +329,7 @@ "id" ], "parent_cardinality": "Exactly one", - "def": "FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE", - "virtual": false + "def": "FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" }, { "table": "users", diff --git a/testdata/modify_schema_override.golden b/testdata/modify_schema_override.golden index a4712301..a885aba3 100644 --- a/testdata/modify_schema_override.golden +++ b/testdata/modify_schema_override.golden @@ -303,8 +303,7 @@ "id" ], "parent_cardinality": "Exactly one", - "def": "FOREIGN KEY (category_id) REFERENCES categories (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE", - "virtual": false + "def": "FOREIGN KEY (category_id) REFERENCES categories (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" }, { "table": "posts", @@ -331,8 +330,7 @@ "id" ], "parent_cardinality": "Exactly one", - "def": "FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE", - "virtual": false + "def": "FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" } ], "driver": { diff --git a/testdata/modify_schema_relations.golden b/testdata/modify_schema_relations.golden index ccaa058a..3d086fe7 100644 --- a/testdata/modify_schema_relations.golden +++ b/testdata/modify_schema_relations.golden @@ -303,8 +303,7 @@ "id" ], "parent_cardinality": "Exactly one", - "def": "FOREIGN KEY (category_id) REFERENCES categories (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE", - "virtual": false + "def": "FOREIGN KEY (category_id) REFERENCES categories (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" }, { "table": "posts", @@ -317,8 +316,7 @@ "id" ], "parent_cardinality": "Exactly one", - "def": "FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE", - "virtual": false + "def": "FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" }, { "table": "user_options", @@ -331,8 +329,7 @@ "id" ], "parent_cardinality": "Exactly one", - "def": "FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE", - "virtual": false + "def": "FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" }, { "table": "users", From 13d37f3bcb36277de489a5db4b79e04b5cebd363 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Fri, 24 Jan 2025 17:38:31 +0900 Subject: [PATCH 08/13] fix: Add schema.SchemaJSON for JSON (schema.json) representation --- schema/json.go | 220 ++++++++++++++++++++++++++++------------------- schema/schema.go | 70 +++++++-------- 2 files changed, 168 insertions(+), 122 deletions(-) diff --git a/schema/json.go b/schema/json.go index 9140cc7e..48bce268 100644 --- a/schema/json.go +++ b/schema/json.go @@ -4,107 +4,131 @@ import ( "encoding/json" ) -// MarshalJSON return custom JSON byte -func (t Table) MarshalJSON() ([]byte, error) { - referencedTables := []string{} +// SchemaJSON is a JSON representation of schema.Schema +type SchemaJSON struct { + Name string `json:"name,omitempty"` + Desc string `json:"desc,omitempty"` + Tables []*TableJSON `json:"tables"` + Relations []*RelationJSON `json:"relations,omitempty"` + Functions []*Function `json:"functions,omitempty"` + Enums []*Enum `json:"enums,omitempty"` + Driver *Driver `json:"driver,omitempty"` + Labels Labels `json:"labels,omitempty"` + Viewpoints Viewpoints `json:"viewpoints,omitempty"` +} + +// TableJSON is a JSON representation of schema.Table +type TableJSON struct { + Name string `json:"name"` + Type string `json:"type"` + Comment string `json:"comment,omitempty"` + Columns []*ColumnJSON `json:"columns"` + Indexes []*Index `json:"indexes,omitempty"` + Constraints []*Constraint `json:"constraints,omitempty"` + Triggers []*Trigger `json:"triggers,omitempty"` + Def string `json:"def,omitempty"` + Labels Labels `json:"labels,omitempty"` + ReferencedTables []string `json:"referenced_tables,omitempty"` +} + +// ColumnJSON is a JSON representation of schema.Column +type ColumnJSON struct { + Name string `json:"name"` + Type string `json:"type"` + Nullable bool `json:"nullable"` + Default *string `json:"default,omitempty"` + ExtraDef string `json:"extra_def,omitempty"` + Labels Labels `json:"labels,omitempty"` + Comment string `json:"comment,omitempty"` +} + +// RelationJSON is a JSON representation of schema.Relation +type RelationJSON struct { + Table string `json:"table"` + Columns []string `json:"columns"` + Cardinality string `json:"cardinality,omitempty"` + ParentTable string `json:"parent_table"` + ParentColumns []string `json:"parent_columns"` + ParentCardinality string `json:"parent_cardinality,omitempty"` + Def string `json:"def"` + Virtual bool `json:"virtual,omitempty"` +} + +// ToJSONObjct convert schema.Schema to JSON object +func (s Schema) ToJSONObject() SchemaJSON { + var tables []*TableJSON + for _, t := range s.Tables { + tt := t.ToJSONObject() + tables = append(tables, &tt) + } + var relations []*RelationJSON + for _, r := range s.Relations { + rr := r.ToJSONObject() + relations = append(relations, &rr) + } + return SchemaJSON{ + Name: s.Name, + Desc: s.Desc, + Tables: tables, + Relations: relations, + Functions: s.Functions, + Enums: s.Enums, + Driver: s.Driver, + Labels: s.Labels, + Viewpoints: s.Viewpoints, + } +} + +func (t Table) ToJSONObject() TableJSON { + var referencedTables []string for _, rt := range t.ReferencedTables { referencedTables = append(referencedTables, rt.Name) } - - return json.Marshal(&struct { - Name string `json:"name"` - Type string `json:"type"` - Comment string `json:"comment,omitempty"` - Columns []*Column `json:"columns"` - Indexes []*Index `json:"indexes,omitempty"` - Constraints []*Constraint `json:"constraints,omitempty"` - Triggers []*Trigger `json:"triggers,omitempty"` - Def string `json:"def,omitempty"` - Labels Labels `json:"labels,omitempty"` - ReferencedTables []string `json:"referenced_tables,omitempty"` - }{ + var columns []*ColumnJSON + for _, c := range t.Columns { + cc := c.ToJSONObject() + columns = append(columns, &cc) + } + return TableJSON{ Name: t.Name, Type: t.Type, Comment: t.Comment, - Columns: t.Columns, + Columns: columns, Indexes: t.Indexes, Constraints: t.Constraints, Triggers: t.Triggers, Def: t.Def, Labels: t.Labels, ReferencedTables: referencedTables, - }) + } } -// MarshalJSON return custom JSON byte -func (c Column) MarshalJSON() ([]byte, error) { +func (c Column) ToJSONObject() ColumnJSON { + var defaultVal *string if c.Default.Valid { - return json.Marshal(&struct { - Name string `json:"name"` - Type string `json:"type"` - Nullable bool `json:"nullable"` - Default *string `json:"default,omitempty"` - ExtraDef string `json:"extra_def,omitempty"` - Labels Labels `json:"labels,omitempty"` - Comment string `json:"comment"` - ParentRelations []*Relation `json:"-"` - ChildRelations []*Relation `json:"-"` - }{ - Name: c.Name, - Type: c.Type, - Nullable: c.Nullable, - Default: &c.Default.String, - Comment: c.Comment, - ExtraDef: c.ExtraDef, - Labels: c.Labels, - ParentRelations: c.ParentRelations, - ChildRelations: c.ChildRelations, - }) + defaultVal = &c.Default.String + } + return ColumnJSON{ + Name: c.Name, + Type: c.Type, + Nullable: c.Nullable, + Default: defaultVal, + Comment: c.Comment, + ExtraDef: c.ExtraDef, + Labels: c.Labels, } - return json.Marshal(&struct { - Name string `json:"name"` - Type string `json:"type"` - Nullable bool `json:"nullable"` - Default *string `json:"default,omitempty"` - Comment string `json:"comment,omitempty"` - ExtraDef string `json:"extra_def,omitempty"` - Labels Labels `json:"labels,omitempty"` - ParentRelations []*Relation `json:"-"` - ChildRelations []*Relation `json:"-"` - }{ - Name: c.Name, - Type: c.Type, - Nullable: c.Nullable, - Default: nil, - Comment: c.Comment, - ExtraDef: c.ExtraDef, - Labels: c.Labels, - ParentRelations: c.ParentRelations, - ChildRelations: c.ChildRelations, - }) } -// MarshalJSON return custom JSON byte -func (r Relation) MarshalJSON() ([]byte, error) { - columns := []string{} - parentColumns := []string{} +func (r Relation) ToJSONObject() RelationJSON { + var columns []string + var parentColumns []string for _, c := range r.Columns { columns = append(columns, c.Name) } for _, c := range r.ParentColumns { parentColumns = append(parentColumns, c.Name) } - - return json.Marshal(&struct { - Table string `json:"table"` - Columns []string `json:"columns"` - Cardinality string `json:"cardinality,omitempty"` - ParentTable string `json:"parent_table"` - ParentColumns []string `json:"parent_columns"` - ParentCardinality string `json:"parent_cardinality,omitempty"` - Def string `json:"def"` - Virtual bool `json:"virtual,omitempty"` - }{ + return RelationJSON{ Table: r.Table.Name, Columns: columns, Cardinality: r.Cardinality.String(), @@ -113,7 +137,31 @@ func (r Relation) MarshalJSON() ([]byte, error) { ParentCardinality: r.ParentCardinality.String(), Def: r.Def, Virtual: r.Virtual, - }) + } +} + +// MarshalJSON return custom JSON byte +func (s Schema) MarshalJSON() ([]byte, error) { + ss := s.ToJSONObject() + return json.Marshal(&ss) +} + +// MarshalJSON return custom JSON byte +func (t Table) MarshalJSON() ([]byte, error) { + tt := t.ToJSONObject() + return json.Marshal(&tt) +} + +// MarshalJSON return custom JSON byte +func (c Column) MarshalJSON() ([]byte, error) { + cc := c.ToJSONObject() + return json.Marshal(&cc) +} + +// MarshalJSON return custom JSON byte +func (r Relation) MarshalJSON() ([]byte, error) { + rr := r.ToJSONObject() + return json.Marshal(&rr) } // UnmarshalJSON unmarshal JSON to schema.Table @@ -154,15 +202,13 @@ func (t *Table) UnmarshalJSON(data []byte) error { // UnmarshalJSON unmarshal JSON to schema.Column func (c *Column) UnmarshalJSON(data []byte) error { s := struct { - Name string `json:"name"` - Type string `json:"type"` - Nullable bool `json:"nullable"` - Default *string `json:"default,omitempty"` - Comment string `json:"comment,omitempty"` - ExtraDef string `json:"extra_def,omitempty"` - Labels Labels `json:"labels,omitempty"` - ParentRelations []*Relation `json:"-"` - ChildRelations []*Relation `json:"-"` + Name string `json:"name"` + Type string `json:"type"` + Nullable bool `json:"nullable"` + Default *string `json:"default,omitempty"` + Comment string `json:"comment,omitempty"` + ExtraDef string `json:"extra_def,omitempty"` + Labels Labels `json:"labels,omitempty"` }{} err := json.Unmarshal(data, &s) if err != nil { diff --git a/schema/schema.go b/schema/schema.go index ea797669..f2aa1693 100644 --- a/schema/schema.go +++ b/schema/schema.go @@ -116,20 +116,20 @@ type Trigger struct { // Column is the struct for table column type Column struct { - Name string `json:"name"` - Type string `json:"type"` - Nullable bool `json:"nullable"` - Default sql.NullString `json:"default,omitempty"` - Comment string `json:"comment,omitempty"` - ExtraDef string `json:"extra_def,omitempty" yaml:"extraDef,omitempty"` - Occurrences sql.NullInt32 `json:"occurrences,omitempty" yaml:"occurrences,omitempty"` - Percents sql.NullFloat64 `json:"percents,omitempty" yaml:"percents,omitempty"` - Labels Labels `json:"labels,omitempty"` - ParentRelations []*Relation `json:"-"` - ChildRelations []*Relation `json:"-"` - PK bool `json:"-"` - FK bool `json:"-"` - HideForER bool `json:"-"` + Name string + Type string + Nullable bool + Default sql.NullString + Comment string + ExtraDef string + Occurrences sql.NullInt32 + Percents sql.NullFloat64 + Labels Labels + ParentRelations []*Relation + ChildRelations []*Relation + PK bool + FK bool + HideForER bool } type TableViewpoint struct { @@ -140,31 +140,31 @@ type TableViewpoint struct { // Table is the struct for database table type Table struct { - Name string `json:"name"` - Type string `json:"type"` - Comment string `json:"comment,omitempty"` - Columns []*Column `json:"columns"` - Viewpoints []*TableViewpoint `json:"viewpoints,omitempty"` - Indexes []*Index `json:"indexes,omitempty"` - Constraints []*Constraint `json:"constraints,omitempty"` - Triggers []*Trigger `json:"triggers,omitempty"` - Def string `json:"def,omitempty"` - Labels Labels `json:"labels,omitempty"` - ReferencedTables []*Table `json:"referenced_tables,omitempty" yaml:"referencedTables,omitempty"` - External bool `json:"-"` // Table external to the schema + Name string + Type string + Comment string + Columns []*Column + Viewpoints []*TableViewpoint + Indexes []*Index + Constraints []*Constraint + Triggers []*Trigger + Def string + Labels Labels + ReferencedTables []*Table + External bool } // Relation is the struct for table relation type Relation struct { - Table *Table `json:"table"` - Columns []*Column `json:"columns"` - ParentTable *Table `json:"parent_table" yaml:"parentTable"` - ParentColumns []*Column `json:"parent_columns" yaml:"parentColumns"` - Cardinality Cardinality `json:"cardinality,omitempty"` - ParentCardinality Cardinality `json:"parent_cardinality,omitempty" yaml:"parentCardinality"` - Def string `json:"def"` - Virtual bool `json:"virtual,omitempty"` - HideForER bool `json:"-"` + Table *Table + Columns []*Column + ParentTable *Table + ParentColumns []*Column + Cardinality Cardinality + ParentCardinality Cardinality + Def string + Virtual bool + HideForER bool } type DriverMeta struct { From 804eaa620975eec974c6c2231b172c1c98aec0e8 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Fri, 24 Jan 2025 17:43:44 +0900 Subject: [PATCH 09/13] fix: Add script for generate JSON Schema of schema.json --- scripts/jsonschema/go.mod | 24 +++++++++++++++++++++++ scripts/jsonschema/go.sum | 40 ++++++++++++++++++++++++++++++++++++++ scripts/jsonschema/main.go | 30 ++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 scripts/jsonschema/go.mod create mode 100644 scripts/jsonschema/go.sum create mode 100644 scripts/jsonschema/main.go diff --git a/scripts/jsonschema/go.mod b/scripts/jsonschema/go.mod new file mode 100644 index 00000000..3e9ead83 --- /dev/null +++ b/scripts/jsonschema/go.mod @@ -0,0 +1,24 @@ +module github.com/k1LoW/tbls/scripts/jsonschema + +go 1.23.4 + +require ( + github.com/iancoleman/strcase v0.3.0 + github.com/invopop/jsonschema v0.13.0 + github.com/k1LoW/tbls v0.0.0 +) + +require ( + github.com/bahlo/generic-list-go v0.2.0 // indirect + github.com/buger/jsonparser v1.1.1 // indirect + github.com/goccy/go-yaml v1.15.13 // indirect + github.com/k1LoW/errors v1.0.0 // indirect + github.com/mailru/easyjson v0.7.7 // indirect + github.com/minio/pkg v1.7.5 // indirect + github.com/samber/lo v1.47.0 // indirect + github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect + golang.org/x/text v0.21.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) + +replace github.com/k1LoW/tbls => ../../ diff --git a/scripts/jsonschema/go.sum b/scripts/jsonschema/go.sum new file mode 100644 index 00000000..ac5846c9 --- /dev/null +++ b/scripts/jsonschema/go.sum @@ -0,0 +1,40 @@ +github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk= +github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg= +github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= +github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/goccy/go-yaml v1.15.13 h1:Xd87Yddmr2rC1SLLTm2MNDcTjeO/GYo0JGiww6gSTDg= +github.com/goccy/go-yaml v1.15.13/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI= +github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= +github.com/invopop/jsonschema v0.13.0 h1:KvpoAJWEjR3uD9Kbm2HWJmqsEaHt8lBUpd0qHcIi21E= +github.com/invopop/jsonschema v0.13.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/k1LoW/errors v1.0.0 h1:b18K/Nj3LdWpTfcmvhpPdXNePWnqDqD/xxFnLsk9Qjo= +github.com/k1LoW/errors v1.0.0/go.mod h1:FnyqU5omnd/+J2ViEsDaIZXTZGuRMZ5uDpLEqrEsMp4= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= +github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/minio/pkg v1.7.5 h1:UOUJjewE5zoaDPlCMJtNx/swc1jT1ZR+IajT7hrLd44= +github.com/minio/pkg v1.7.5/go.mod h1:mEfGMTm5Z0b5EGxKNuPwyb5A2d+CC/VlUyRj6RJtIwo= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc= +github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc= +github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/scripts/jsonschema/main.go b/scripts/jsonschema/main.go new file mode 100644 index 00000000..a84c11b9 --- /dev/null +++ b/scripts/jsonschema/main.go @@ -0,0 +1,30 @@ +package main + +import ( + "encoding/json" + "fmt" + "os" + + "github.com/iancoleman/strcase" + "github.com/invopop/jsonschema" + "github.com/k1LoW/tbls/schema" +) + +func main() { + if err := _main(); err != nil { + fmt.Println(err) + os.Exit(1) + } +} + +func _main() error { + r := new(jsonschema.Reflector) + r.KeyNamer = strcase.ToSnake + s := r.Reflect(&schema.SchemaJSON{}) + b, err := json.MarshalIndent(s, "", " ") + if err != nil { + return err + } + fmt.Println(string(b)) + return nil +} From 8ff399c06d73228164d4f47dac4308f2c59e3b59 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Fri, 24 Jan 2025 21:25:52 +0900 Subject: [PATCH 10/13] fix: Change cardinality string --- schema/cardinality.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/schema/cardinality.go b/schema/cardinality.go index f5027d77..c37ce23a 100644 --- a/schema/cardinality.go +++ b/schema/cardinality.go @@ -8,10 +8,10 @@ import ( type Cardinality string const ( - ZeroOrOne Cardinality = "Zero or one" - ExactlyOne Cardinality = "Exactly one" - ZeroOrMore Cardinality = "Zero or more" - OneOrMore Cardinality = "One or more" + ZeroOrOne Cardinality = "zero_or_one" + ExactlyOne Cardinality = "exactly_one" + ZeroOrMore Cardinality = "zero_or_more" + OneOrMore Cardinality = "one_or_more" UnknownCardinality Cardinality = "" ) @@ -23,6 +23,13 @@ var cardinalityAliases = map[string]Cardinality{ "one or zero": ZeroOrOne, "zero or many": ZeroOrMore, "one or many": OneOrMore, + "zero_or_one": ZeroOrOne, + "exactly_one": ExactlyOne, + "zero_or_more": ZeroOrMore, + "one_or_more": OneOrMore, + "one_or_zero": ZeroOrOne, + "zero_or_many": ZeroOrMore, + "one_or_many": OneOrMore, "many(0)": ZeroOrMore, "many(1)": OneOrMore, "0+": ZeroOrMore, From 29882d34c1c5d1dc467a2e03f1a0847eee3942d1 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Fri, 24 Jan 2025 21:26:51 +0900 Subject: [PATCH 11/13] fix: Set jsonschema tag --- sample/adjust/schema.json | 2 +- sample/detect_relations/schema.json | 2 +- sample/detect_relations_singular/schema.json | 2 +- sample/dict/schema.json | 2 +- sample/dynamodb/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/schema.json | 2 +- sample/mssql/schema.json | 2 +- 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 +- schema/json.go | 6 +++--- scripts/jsonschema/main.go | 5 +++++ testdata/json_output_schema.golden | 4 ++-- testdata/modify_schema_.golden | 12 ++++++------ testdata/modify_schema_mod_name_and_desc.golden | 12 ++++++------ testdata/modify_schema_not_override.golden | 16 ++++++++-------- testdata/modify_schema_override.golden | 12 ++++++------ testdata/modify_schema_relations.golden | 16 ++++++++-------- testdata/yaml_output_schema.golden | 4 ++-- 29 files changed, 66 insertions(+), 61 deletions(-) diff --git a/sample/adjust/schema.json b/sample/adjust/schema.json index b649de22..9f7c5b70 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)"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"users_pkey","def":"CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)","table":"public.users","columns":["id"]},{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)","table":"public.users","columns":["username"]},{"name":"users_email_key","def":"CREATE UNIQUE INDEX users_email_key ON public.users USING btree (email)","table":"public.users","columns":["email"]}],"constraints":[{"name":"users_username_check","type":"CHECK","def":"CHECK ((char_length((username)::text) \u003e 4))","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.users","referenced_table":"","columns":["id"]},{"name":"users_username_key","type":"UNIQUE","def":"UNIQUE (username)","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_email_key","type":"UNIQUE","def":"UNIQUE (email)","table":"public.users","referenced_table":"","columns":["email"]}],"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"}]},{"name":"public.user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"integer","nullable":false},{"name":"show_email","type":"boolean","nullable":false,"default":"false"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}]},{"name":"public.posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"default":"nextval('posts_id_seq'::regclass)"},{"name":"user_id","type":"integer","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'::character varying"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"post_types","nullable":false,"comment":"public/private/draft"},{"name":"labels","type":"varchar(50)[]","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CREATE UNIQUE INDEX posts_id_pk ON public.posts USING btree (id)","table":"public.posts","columns":["id"]},{"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":["user_id","title"]},{"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"]},{"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"]},{"name":"posts_user_id_title_key","type":"UNIQUE","def":"UNIQUE (user_id, title)","table":"public.posts","referenced_table":"","columns":["user_id","title"]}],"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"}]},{"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)"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"integer","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (post_id * '-1'::integer) STORED"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CREATE UNIQUE INDEX comments_id_pk ON public.comments USING btree (id)","table":"public.comments","columns":["id"]},{"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"]},{"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"]}],"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"]},{"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"]},{"name":"comments_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.comments","referenced_table":"","columns":["id"]},{"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"]}]},{"name":"public.comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"user_id","type":"integer","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"integer","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","table":"public.comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id)","table":"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"]},{"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"]}]},{"name":"public.logs","type":"BASE TABLE","comment":"audit log table","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"user_id","type":"integer","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"uuid","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false}]},{"name":"public.post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"timestamp without time zone","nullable":true,"comment":"comments.created"},{"name":"updated","type":"timestamp without time zone","nullable":true,"comment":"comments.updated"}],"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","columns":[{"name":"id","type":"uuid","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"comment_star_user","type":"varchar(50)","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"created","type":"timestamp without time zone","nullable":false}],"indexes":[{"name":"CamelizeTable_id_key","def":"CREATE UNIQUE INDEX \"CamelizeTable_id_key\" ON public.\"CamelizeTable\" USING btree (id)","table":"public.CamelizeTable","columns":["id"]}],"constraints":[{"name":"CamelizeTable_id_key","type":"UNIQUE","def":"UNIQUE (id)","table":"public.CamelizeTable","referenced_table":"","columns":["id"]}]},{"name":"public.hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"CamelizeTableId","type":"uuid","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false}],"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"]}],"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"]},{"name":"hyphen-table_hyphen-column_key","type":"UNIQUE","def":"UNIQUE (\"hyphen-column\")","table":"public.hyphen-table","referenced_table":"","columns":["hyphen-column"]}]},{"name":"administrator.blogs","type":"BASE TABLE","comment":"admin blogs","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('administrator.blogs_id_seq'::regclass)"},{"name":"user_id","type":"integer","nullable":false},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON administrator.blogs USING btree (id)","table":"administrator.blogs","columns":["id"]}],"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"]},{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"administrator.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blogs","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blogs_id_seq'::regclass)"},{"name":"user_id","type":"integer","nullable":false},{"name":"dump","type":"text","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON backup.blogs USING btree (id)","table":"backup.blogs","columns":["id"]}],"constraints":[{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blog_options","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blog_options_id_seq'::regclass)"},{"name":"blog_id","type":"integer","nullable":false},{"name":"label","type":"text","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}],"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"]},{"name":"blog_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blog_options","referenced_table":"","columns":["id"]}]},{"name":"time.bar","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"indexes":[{"name":"bar_pkey","def":"CREATE UNIQUE INDEX bar_pkey ON \"time\".bar USING btree (id)","table":"time.bar","columns":["id"]}],"constraints":[{"name":"bar_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.bar","referenced_table":"","columns":["id"]}]},{"name":"time.hyphenated-table","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"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"]}],"constraints":[{"name":"hyphenated-table_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.hyphenated-table","referenced_table":"","columns":["id"]}]},{"name":"time.referencing","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false},{"name":"bar_id","type":"integer","nullable":false},{"name":"ht_id","type":"integer","nullable":false}],"indexes":[{"name":"referencing_pkey","def":"CREATE UNIQUE INDEX referencing_pkey ON \"time\".referencing USING btree (id)","table":"time.referencing","columns":["id"]}],"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"]},{"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"]},{"name":"referencing_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.referencing","referenced_table":"","columns":["id"]}]}],"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"},{"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)"},{"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)"},{"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)"},{"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)"},{"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)"},{"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"},{"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"},{"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"},{"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)"},{"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)"},{"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"}],"enums":[{"name":"public.post_types","values":["draft","private","public"]}],"driver":{"name":"postgres","database_version":"PostgreSQL 15.10 (Debian 15.10-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit","meta":{"current_schema":"public","search_paths":["postgres","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}},"viewpoints":[{"name":"post","desc":"for post","tables":["public.post*"]},{"name":"administrator","desc":"administrator schema only","tables":["administrator.*"]}]} +{"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)"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"users_pkey","def":"CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)","table":"public.users","columns":["id"]},{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)","table":"public.users","columns":["username"]},{"name":"users_email_key","def":"CREATE UNIQUE INDEX users_email_key ON public.users USING btree (email)","table":"public.users","columns":["email"]}],"constraints":[{"name":"users_username_check","type":"CHECK","def":"CHECK ((char_length((username)::text) \u003e 4))","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.users","referenced_table":"","columns":["id"]},{"name":"users_username_key","type":"UNIQUE","def":"UNIQUE (username)","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_email_key","type":"UNIQUE","def":"UNIQUE (email)","table":"public.users","referenced_table":"","columns":["email"]}],"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"}]},{"name":"public.user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"integer","nullable":false},{"name":"show_email","type":"boolean","nullable":false,"default":"false"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}]},{"name":"public.posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"default":"nextval('posts_id_seq'::regclass)"},{"name":"user_id","type":"integer","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'::character varying"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"post_types","nullable":false,"comment":"public/private/draft"},{"name":"labels","type":"varchar(50)[]","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CREATE UNIQUE INDEX posts_id_pk ON public.posts USING btree (id)","table":"public.posts","columns":["id"]},{"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":["user_id","title"]},{"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"]},{"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"]},{"name":"posts_user_id_title_key","type":"UNIQUE","def":"UNIQUE (user_id, title)","table":"public.posts","referenced_table":"","columns":["user_id","title"]}],"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"}]},{"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)"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"integer","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (post_id * '-1'::integer) STORED"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CREATE UNIQUE INDEX comments_id_pk ON public.comments USING btree (id)","table":"public.comments","columns":["id"]},{"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"]},{"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"]}],"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"]},{"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"]},{"name":"comments_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.comments","referenced_table":"","columns":["id"]},{"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"]}]},{"name":"public.comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"user_id","type":"integer","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"integer","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","table":"public.comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id)","table":"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"]},{"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"]}]},{"name":"public.logs","type":"BASE TABLE","comment":"audit log table","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"user_id","type":"integer","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"uuid","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false}]},{"name":"public.post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"timestamp without time zone","nullable":true,"comment":"comments.created"},{"name":"updated","type":"timestamp without time zone","nullable":true,"comment":"comments.updated"}],"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","columns":[{"name":"id","type":"uuid","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"comment_star_user","type":"varchar(50)","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"created","type":"timestamp without time zone","nullable":false}],"indexes":[{"name":"CamelizeTable_id_key","def":"CREATE UNIQUE INDEX \"CamelizeTable_id_key\" ON public.\"CamelizeTable\" USING btree (id)","table":"public.CamelizeTable","columns":["id"]}],"constraints":[{"name":"CamelizeTable_id_key","type":"UNIQUE","def":"UNIQUE (id)","table":"public.CamelizeTable","referenced_table":"","columns":["id"]}]},{"name":"public.hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"CamelizeTableId","type":"uuid","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false}],"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"]}],"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"]},{"name":"hyphen-table_hyphen-column_key","type":"UNIQUE","def":"UNIQUE (\"hyphen-column\")","table":"public.hyphen-table","referenced_table":"","columns":["hyphen-column"]}]},{"name":"administrator.blogs","type":"BASE TABLE","comment":"admin blogs","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('administrator.blogs_id_seq'::regclass)"},{"name":"user_id","type":"integer","nullable":false},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON administrator.blogs USING btree (id)","table":"administrator.blogs","columns":["id"]}],"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"]},{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"administrator.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blogs","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blogs_id_seq'::regclass)"},{"name":"user_id","type":"integer","nullable":false},{"name":"dump","type":"text","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON backup.blogs USING btree (id)","table":"backup.blogs","columns":["id"]}],"constraints":[{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blog_options","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blog_options_id_seq'::regclass)"},{"name":"blog_id","type":"integer","nullable":false},{"name":"label","type":"text","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}],"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"]},{"name":"blog_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blog_options","referenced_table":"","columns":["id"]}]},{"name":"time.bar","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"indexes":[{"name":"bar_pkey","def":"CREATE UNIQUE INDEX bar_pkey ON \"time\".bar USING btree (id)","table":"time.bar","columns":["id"]}],"constraints":[{"name":"bar_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.bar","referenced_table":"","columns":["id"]}]},{"name":"time.hyphenated-table","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"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"]}],"constraints":[{"name":"hyphenated-table_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.hyphenated-table","referenced_table":"","columns":["id"]}]},{"name":"time.referencing","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false},{"name":"bar_id","type":"integer","nullable":false},{"name":"ht_id","type":"integer","nullable":false}],"indexes":[{"name":"referencing_pkey","def":"CREATE UNIQUE INDEX referencing_pkey ON \"time\".referencing USING btree (id)","table":"time.referencing","columns":["id"]}],"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"]},{"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"]},{"name":"referencing_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.referencing","referenced_table":"","columns":["id"]}]}],"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"},{"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)"},{"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)"},{"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)"},{"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)"},{"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)"},{"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"},{"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"},{"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"},{"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)"},{"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)"},{"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"}],"enums":[{"name":"public.post_types","values":["draft","private","public"]}],"driver":{"name":"postgres","database_version":"PostgreSQL 15.10 (Debian 15.10-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit","meta":{"current_schema":"public","search_paths":["postgres","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}},"viewpoints":[{"name":"post","desc":"for post","tables":["public.post*"]},{"name":"administrator","desc":"administrator schema only","tables":["administrator.*"]}]} diff --git a/sample/detect_relations/schema.json b/sample/detect_relations/schema.json index b9c98c5f..5b0cc571 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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"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,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`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,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL,\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},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]}],"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)"},{"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.4.4","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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"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,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`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,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL,\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},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]}],"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)"},{"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.4.4","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 d28f8929..992beed9 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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment","type":"BASE TABLE","comment":"Comment\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"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"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comment","columns":["post_id","user_id"]}],"constraints":[{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comment","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment","columns":["id"]}],"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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_star","columns":["id"]},{"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"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_star","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_star","columns":["user_id","comment_post_id","comment_user_id"]}],"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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"log","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"log","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"log","columns":["id"]}],"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,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"post_user_id_idx","def":"KEY post_user_id_idx (id) USING BTREE","table":"post","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"post","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"post","columns":["user_id","title"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"post","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"post","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON post\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"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,"comment":"post.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"post.user.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comment.user.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comment.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comment.updated"}],"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,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"user","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"user","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"user","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"user","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"user","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"user","columns":["username"]}],"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},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_option","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_option","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_option","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_option","columns":["user_id"]},{"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"]}],"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)"},{"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.4.4","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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment","type":"BASE TABLE","comment":"Comment\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"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"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comment","columns":["post_id","user_id"]}],"constraints":[{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comment","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment","columns":["id"]}],"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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_star","columns":["id"]},{"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"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_star","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_star","columns":["user_id","comment_post_id","comment_user_id"]}],"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","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"log","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"log","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"log","columns":["id"]}],"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,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"post_user_id_idx","def":"KEY post_user_id_idx (id) USING BTREE","table":"post","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"post","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"post","columns":["user_id","title"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"post","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"post","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON post\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"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,"comment":"post.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"post.user.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comment.user.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comment.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comment.updated"}],"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,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"user","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"user","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"user","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"user","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"user","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"user","columns":["username"]}],"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},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_option","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_option","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_option","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_option","columns":["user_id"]},{"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"]}],"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)"},{"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.4.4","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 4f2d64ed..b30dd01d 100644 --- a/sample/dict/schema.json +++ b/sample/dict/schema.json @@ -1 +1 @@ -{"name":"testdb","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"VIEW","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"post_user","type":"varchar(50)","nullable":true},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"created","type":"datetime","nullable":true},{"name":"updated","type":"datetime","nullable":true}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'"},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} +{"name":"testdb","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"VIEW","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"post_user","type":"varchar(50)","nullable":true},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"created","type":"datetime","nullable":true},{"name":"updated","type":"datetime","nullable":true}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'"},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} diff --git a/sample/dynamodb/schema.json b/sample/dynamodb/schema.json index 09206c41..1d7da8f3 100644 --- a/sample/dynamodb/schema.json +++ b/sample/dynamodb/schema.json @@ -1 +1 @@ -{"name":"Amazon DynamoDB (ap-northeast-1)","tables":[{"name":"Forum","type":"BASIC TABLE","columns":[{"name":"Name","type":"S","nullable":false}],"constraints":[{"name":"Primary Key","type":"Partition key","def":"[{ AttributeName: \"Name\", KeyType: \"HASH\" }]","table":null,"columns":["Name"]}]},{"name":"ProductCatalog","type":"BASIC TABLE","columns":[{"name":"Id","type":"N","nullable":false}],"constraints":[{"name":"Primary Key","type":"Partition key","def":"[{ AttributeName: \"Id\", KeyType: \"HASH\" }]","table":null,"columns":["Id"]}]},{"name":"Reply","type":"BASIC TABLE","columns":[{"name":"Id","type":"S","nullable":false},{"name":"ReplyDateTime","type":"S","nullable":false},{"name":"PostedBy","type":"S","nullable":false}],"indexes":[{"name":"PostedBy-index","def":"LocalSecondaryIndex { [{ AttributeName: \"Id\", KeyType: \"HASH\" } { AttributeName: \"PostedBy\", KeyType: \"RANGE\" }], { ProjectionType: \"KEYS_ONLY\" } }","table":null,"columns":null}],"constraints":[{"name":"Primary Key","type":"Partition key and sort key","def":"[{ AttributeName: \"Id\", KeyType: \"HASH\" } { AttributeName: \"ReplyDateTime\", KeyType: \"RANGE\" }]","table":null,"columns":["Id","ReplyDateTime"]}]},{"name":"Thread","type":"BASIC TABLE","columns":[{"name":"ForumName","type":"S","nullable":false},{"name":"Subject","type":"S","nullable":false}],"constraints":[{"name":"Primary Key","type":"Partition key and sort key","def":"[{ AttributeName: \"ForumName\", KeyType: \"HASH\" } { AttributeName: \"Subject\", KeyType: \"RANGE\" }]","table":null,"columns":["ForumName","Subject"]}]}],"relations":[{"table":"Thread","columns":["ForumName"],"cardinality":"Zero or more","parent_table":"Forum","parent_columns":["Name"],"parent_cardinality":"Exactly one","def":"Thread-\u003eForum","virtual":true}],"driver":{"name":"dynamodb","meta":{"dict":{"Column":"Attribute","Columns":"Attributes","Constraints":"Primary Key","Indexes":"Secondary Indexes"}}}} +{"name":"Amazon DynamoDB (ap-northeast-1)","tables":[{"name":"Forum","type":"BASIC TABLE","columns":[{"name":"Name","type":"S","nullable":false}],"constraints":[{"name":"Primary Key","type":"Partition key","def":"[{ AttributeName: \"Name\", KeyType: \"HASH\" }]","table":null,"columns":["Name"]}]},{"name":"ProductCatalog","type":"BASIC TABLE","columns":[{"name":"Id","type":"N","nullable":false}],"constraints":[{"name":"Primary Key","type":"Partition key","def":"[{ AttributeName: \"Id\", KeyType: \"HASH\" }]","table":null,"columns":["Id"]}]},{"name":"Reply","type":"BASIC TABLE","columns":[{"name":"Id","type":"S","nullable":false},{"name":"ReplyDateTime","type":"S","nullable":false},{"name":"PostedBy","type":"S","nullable":false}],"indexes":[{"name":"PostedBy-index","def":"LocalSecondaryIndex { [{ AttributeName: \"Id\", KeyType: \"HASH\" } { AttributeName: \"PostedBy\", KeyType: \"RANGE\" }], { ProjectionType: \"KEYS_ONLY\" } }","table":null,"columns":null}],"constraints":[{"name":"Primary Key","type":"Partition key and sort key","def":"[{ AttributeName: \"Id\", KeyType: \"HASH\" } { AttributeName: \"ReplyDateTime\", KeyType: \"RANGE\" }]","table":null,"columns":["Id","ReplyDateTime"]}]},{"name":"Thread","type":"BASIC TABLE","columns":[{"name":"ForumName","type":"S","nullable":false},{"name":"Subject","type":"S","nullable":false}],"constraints":[{"name":"Primary Key","type":"Partition key and sort key","def":"[{ AttributeName: \"ForumName\", KeyType: \"HASH\" } { AttributeName: \"Subject\", KeyType: \"RANGE\" }]","table":null,"columns":["ForumName","Subject"]}]}],"relations":[{"table":"Thread","columns":["ForumName"],"cardinality":"zero_or_more","parent_table":"Forum","parent_columns":["Name"],"parent_cardinality":"exactly_one","def":"Thread-\u003eForum","virtual":true}],"driver":{"name":"dynamodb","meta":{"dict":{"Column":"Attribute","Columns":"Attributes","Constraints":"Primary Key","Indexes":"Secondary Indexes"}}}} diff --git a/sample/exclude/schema.json b/sample/exclude/schema.json index 2ee9898a..da578d6c 100644 --- a/sample/exclude/schema.json +++ b/sample/exclude/schema.json @@ -1 +1 @@ -{"name":"testdb","tables":[{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'"},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} +{"name":"testdb","tables":[{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'"},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} diff --git a/sample/font/schema.json b/sample/font/schema.json index 9848a60d..9117a437 100644 --- a/sample/font/schema.json +++ b/sample/font/schema.json @@ -1 +1 @@ -{"name":"testdb","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"エントリ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"本文"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'"},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"サンプル","virtual":true},{"name":"tbls","virtual":true}]} +{"name":"testdb","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"エントリ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"本文"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'"},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"サンプル","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/hide/schema.json b/sample/hide/schema.json index 709ad61f..f1d7ca61 100644 --- a/sample/hide/schema.json +++ b/sample/hide/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}}} diff --git a/sample/hide_not_related_column/schema.json b/sample/hide_not_related_column/schema.json index ec587e5c..bb6d1a87 100644 --- a/sample/hide_not_related_column/schema.json +++ b/sample/hide_not_related_column/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"Zero or more","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"zero_or_more","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/mariadb/schema.json b/sample/mariadb/schema.json index bbe2a77c..5769a55e 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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint(20)","nullable":false},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment","type":"text","nullable":false,"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"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true,"default":"NULL"}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment_post_id","type":"bigint(20)","nullable":false},{"name":"comment_user_id","type":"int(11)","nullable":false},{"name":"created","type":"timestamp","nullable":false,"default":"current_timestamp()","extra_def":"on update current_timestamp()"},{"name":"updated","type":"timestamp","nullable":false,"default":"'0000-00-00 00:00:00'"}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"post_id","type":"bigint(20)","nullable":true,"default":"NULL"},{"name":"comment_id","type":"bigint(20)","nullable":true,"default":"NULL"},{"name":"comment_star_id","type":"bigint(20)","nullable":true,"default":"NULL"},{"name":"payload","type":"text","nullable":true,"default":"NULL"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true,"default":"NULL"}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint(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,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":"NULL","comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS ((select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on(`p`.`id` = `c`.`post_id`)) left join `testdb`.`users` `u` on(`u`.`id` = `p`.`user_id`)) left join `testdb`.`users` `u2` on(`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"same_name_constraints","type":"BASE TABLE","columns":[{"name":"id","type":"bigint(20)","nullable":true,"default":"NULL"},{"name":"user_id","type":"int(11)","nullable":false}],"indexes":[{"name":"same_name","def":"UNIQUE KEY same_name (user_id, id) USING BTREE","table":"same_name_constraints","columns":["user_id","id"]}],"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"]},{"name":"same_name","type":"UNIQUE","def":"UNIQUE KEY same_name (user_id, id)","table":"same_name_constraints","columns":["user_id","id"]}],"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,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false,"default":"current_timestamp()","extra_def":"on update current_timestamp()"},{"name":"updated","type":"timestamp","nullable":false,"default":"'0000-00-00 00:00:00'"}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]}],"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},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false,"default":"current_timestamp()","extra_def":"on update current_timestamp()"},{"name":"updated","type":"timestamp","nullable":false,"default":"'0000-00-00 00:00:00'"}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int(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)"},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"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)"},{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"Exactly one","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Additional Relation","virtual":true}],"driver":{"name":"mariadb","database_version":"10.5.27-MariaDB-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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint(20)","nullable":false},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment","type":"text","nullable":false,"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"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true,"default":"NULL"}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment_post_id","type":"bigint(20)","nullable":false},{"name":"comment_user_id","type":"int(11)","nullable":false},{"name":"created","type":"timestamp","nullable":false,"default":"current_timestamp()","extra_def":"on update current_timestamp()"},{"name":"updated","type":"timestamp","nullable":false,"default":"'0000-00-00 00:00:00'"}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"post_id","type":"bigint(20)","nullable":true,"default":"NULL"},{"name":"comment_id","type":"bigint(20)","nullable":true,"default":"NULL"},{"name":"comment_star_id","type":"bigint(20)","nullable":true,"default":"NULL"},{"name":"payload","type":"text","nullable":true,"default":"NULL"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true,"default":"NULL"}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint(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,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"default":"NULL","comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS ((select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on(`p`.`id` = `c`.`post_id`)) left join `testdb`.`users` `u` on(`u`.`id` = `p`.`user_id`)) left join `testdb`.`users` `u2` on(`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"same_name_constraints","type":"BASE TABLE","columns":[{"name":"id","type":"bigint(20)","nullable":true,"default":"NULL"},{"name":"user_id","type":"int(11)","nullable":false}],"indexes":[{"name":"same_name","def":"UNIQUE KEY same_name (user_id, id) USING BTREE","table":"same_name_constraints","columns":["user_id","id"]}],"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"]},{"name":"same_name","type":"UNIQUE","def":"UNIQUE KEY same_name (user_id, id)","table":"same_name_constraints","columns":["user_id","id"]}],"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,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false,"default":"current_timestamp()","extra_def":"on update current_timestamp()"},{"name":"updated","type":"timestamp","nullable":false,"default":"'0000-00-00 00:00:00'"}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]}],"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},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false,"default":"current_timestamp()","extra_def":"on update current_timestamp()"},{"name":"updated","type":"timestamp","nullable":false,"default":"'0000-00-00 00:00:00'"}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int(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)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"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)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"exactly_one","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"Additional Relation","virtual":true}],"driver":{"name":"mariadb","database_version":"10.5.27-MariaDB-ubu2004","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/mermaid/schema.json b/sample/mermaid/schema.json index 901682cb..5c731a00 100644 --- a/sample/mermaid/schema.json +++ b/sample/mermaid/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"Exactly one","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"exactly_one","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/mssql/schema.json b/sample/mssql/schema.json index f3a8df74..fd81a10c 100644 --- a/sample/mssql/schema.json +++ b/sample/mssql/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"users","type":"BASIC TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"comment":"long long long long long long long long long long long long long long long long long long long long long description"},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"PK__users_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"users","columns":["id"]},{"name":"UQ__users_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ email ]","table":"users","columns":["email"]},{"name":"UQ__users_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ username ]","table":"users","columns":["username"]}],"constraints":[{"name":"PK__users_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"users","columns":["id"]},{"name":"UQ__users_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ email ]","table":"users","columns":["email"]},{"name":"UQ__users_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ username ]","table":"users","columns":["username"]},{"name":"CK__users__username_*","type":"CHECK","def":"CHECK(len([username])\u003e(4))","table":"users","columns":null}],"triggers":[{"name":"update_users_updated","def":"CREATE TRIGGER update_users_updated\nON users\nAFTER UPDATE\nAS\nBEGIN\n UPDATE users SET updated = GETDATE()\n WHERE id = ( SELECT id FROM deleted)\nEND;"}]},{"name":"user_options","type":"BASIC TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"bit","nullable":false,"default":"((0))"},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"PK__user_opt_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ user_id ]","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PK__user_opt_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ user_id ]","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE CASCADE","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}]},{"name":"posts","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"posts","columns":["id"]},{"name":"UQ__posts_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, title ]","table":"posts","columns":["user_id","title"]},{"name":"posts_user_id_idx","def":"NONCLUSTERED, [ user_id ]","table":"posts","columns":["user_id"]}],"constraints":[{"name":"posts_id_pk","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"posts","columns":["id"]},{"name":"UQ__posts_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, title ]","table":"posts","columns":["user_id","title"]},{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE CASCADE","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated\nON posts\nAFTER UPDATE\nAS\nBEGIN\n UPDATE users SET updated = GETDATE()\n WHERE id = ( SELECT user_id FROM deleted)\nEND;"}],"labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"comments","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"post_id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"comments","columns":["id"]},{"name":"UQ__comments_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"]},{"name":"comments_post_id_user_id_idx","def":"NONCLUSTERED, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_id_pk","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"comments","columns":["id"]},{"name":"UQ__comments_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"]},{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(post_id) REFERENCES posts(id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}]},{"name":"comment_stars","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"int","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"UQ__comment__*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, comment_post_id, comment_user_id ]","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"UQ__comment__*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, comment_post_id, comment_user_id ]","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]},{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(comment_user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]}]},{"name":"logs","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"int","nullable":true},{"name":"comment_id","type":"int","nullable":true},{"name":"comment_star_id","type":"int","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"date","nullable":false}]},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"int","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"date","nullable":true,"comment":"comments.created"},{"name":"updated","type":"date","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (\n SELECT c.id, p.title, u2.username AS post_user, c.comment, u2.username AS comment_user, c.created, c.updated\n FROM posts AS p\n LEFT JOIN comments AS c on p.id = c.post_id\n LEFT JOIN users AS u on u.id = p.user_id\n LEFT JOIN users AS u2 on u2.id = c.user_id\n);","referenced_tables":["posts","comments","users"]},{"name":"CamelizeTable","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"created","type":"date","nullable":false}]},{"name":"hyphen-table","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"date","nullable":false}]},{"name":"administrator.blogs","type":"BASIC TABLE","comment":"admin blogs","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"PK__blogs_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"administrator.blogs","columns":["id"]}],"constraints":[{"name":"PK__blogs_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"administrator.blogs","columns":["id"]},{"name":"blogs_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE CASCADE","table":"administrator.blogs","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}]},{"name":"name with spaces","type":"VIEW","columns":[{"name":"title","type":"varchar(255)","nullable":false}],"def":"CREATE VIEW \"name with spaces\" AS (\n SELECT TOP 1 p.title\n FROM posts AS p\n);","referenced_tables":["posts"]},{"name":"Sales.Product","type":"BASIC TABLE","columns":[{"name":"ProductID","type":"int","nullable":false},{"name":"SalesPersonID","type":"int","nullable":true}],"indexes":[{"name":"PK__Product_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ ProductID ]","table":"Sales.Product","columns":["ProductID"]},{"name":"UQ__Product_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ SalesPersonID ]","table":"Sales.Product","columns":["SalesPersonID"]}],"constraints":[{"name":"PK__Product_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ ProductID ]","table":"Sales.Product","columns":["ProductID"]},{"name":"UQ__Product_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ SalesPersonID ]","table":"Sales.Product","columns":["SalesPersonID"]}]},{"name":"Rabbits.Running","type":"BASIC TABLE","columns":[{"name":"LocationID","type":"int","nullable":false},{"name":"ProductID","type":"int","nullable":true},{"name":"EmployeeID","type":"int","nullable":true}],"indexes":[{"name":"PK__Running_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ LocationID ]","table":"Rabbits.Running","columns":["LocationID"]},{"name":"UQ__Running_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ EmployeeID ]","table":"Rabbits.Running","columns":["EmployeeID"]},{"name":"UQ__Running_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ ProductID ]","table":"Rabbits.Running","columns":["ProductID"]}],"constraints":[{"name":"PK__Running_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ LocationID ]","table":"Rabbits.Running","columns":["LocationID"]},{"name":"UQ__Running_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ EmployeeID ]","table":"Rabbits.Running","columns":["EmployeeID"]},{"name":"UQ__Running_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ ProductID ]","table":"Rabbits.Running","columns":["ProductID"]},{"name":"FK_TempSales_SalesReason","type":"FOREIGN KEY","def":"FOREIGN KEY(ProductID) REFERENCES Sales.Product(SalesPersonID) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"Rabbits.Running","referenced_table":"Sales.Product","columns":["ProductID"],"referenced_columns":["SalesPersonID"]}]}],"relations":[{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":""},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":""},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":""},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":""},{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":""},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"Exactly one","def":""},{"table":"administrator.blogs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":""},{"table":"Rabbits.Running","columns":["ProductID"],"cardinality":"Zero or one","parent_table":"Sales.Product","parent_columns":["SalesPersonID"],"parent_cardinality":"Zero or one","def":""},{"table":"logs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"Zero or more","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true}],"functions":[{"name":"dbo.get_user","return_type":"","arguments":"@userid int","type":"SQL inline table-valued function"},{"name":"dbo.What_DB_is_that","return_type":"","arguments":"@ID int","type":"SQL Stored Procedure"}],"driver":{"name":"sqlserver","database_version":"Microsoft SQL Server 2019 (RTM-CU30) (KB5049235) - 15.0.4415.2 (X64) \n\tNov 18 2024 17:45:37 \n\tCopyright (C) 2019 Microsoft Corporation\n\tDeveloper Edition (64-bit) on Linux (Ubuntu 20.04.6 LTS) \u003cX64\u003e","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"users","type":"BASIC TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"comment":"long long long long long long long long long long long long long long long long long long long long long description"},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"PK__users_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"users","columns":["id"]},{"name":"UQ__users_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ email ]","table":"users","columns":["email"]},{"name":"UQ__users_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ username ]","table":"users","columns":["username"]}],"constraints":[{"name":"PK__users_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"users","columns":["id"]},{"name":"UQ__users_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ email ]","table":"users","columns":["email"]},{"name":"UQ__users_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ username ]","table":"users","columns":["username"]},{"name":"CK__users__username_*","type":"CHECK","def":"CHECK(len([username])\u003e(4))","table":"users","columns":null}],"triggers":[{"name":"update_users_updated","def":"CREATE TRIGGER update_users_updated\nON users\nAFTER UPDATE\nAS\nBEGIN\n UPDATE users SET updated = GETDATE()\n WHERE id = ( SELECT id FROM deleted)\nEND;"}]},{"name":"user_options","type":"BASIC TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"bit","nullable":false,"default":"((0))"},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"PK__user_opt_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ user_id ]","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PK__user_opt_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ user_id ]","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE CASCADE","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}]},{"name":"posts","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"posts","columns":["id"]},{"name":"UQ__posts_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, title ]","table":"posts","columns":["user_id","title"]},{"name":"posts_user_id_idx","def":"NONCLUSTERED, [ user_id ]","table":"posts","columns":["user_id"]}],"constraints":[{"name":"posts_id_pk","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"posts","columns":["id"]},{"name":"UQ__posts_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, title ]","table":"posts","columns":["user_id","title"]},{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE CASCADE","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated\nON posts\nAFTER UPDATE\nAS\nBEGIN\n UPDATE users SET updated = GETDATE()\n WHERE id = ( SELECT user_id FROM deleted)\nEND;"}],"labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"comments","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"post_id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"comments","columns":["id"]},{"name":"UQ__comments_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"]},{"name":"comments_post_id_user_id_idx","def":"NONCLUSTERED, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_id_pk","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"comments","columns":["id"]},{"name":"UQ__comments_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ post_id, user_id ]","table":"comments","columns":["post_id","user_id"]},{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(post_id) REFERENCES posts(id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}]},{"name":"comment_stars","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"int","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"UQ__comment__*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, comment_post_id, comment_user_id ]","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"UQ__comment__*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ user_id, comment_post_id, comment_user_id ]","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]},{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(comment_user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]}]},{"name":"logs","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"int","nullable":true},{"name":"comment_id","type":"int","nullable":true},{"name":"comment_star_id","type":"int","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"date","nullable":false}]},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"int","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"date","nullable":true,"comment":"comments.created"},{"name":"updated","type":"date","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (\n SELECT c.id, p.title, u2.username AS post_user, c.comment, u2.username AS comment_user, c.created, c.updated\n FROM posts AS p\n LEFT JOIN comments AS c on p.id = c.post_id\n LEFT JOIN users AS u on u.id = p.user_id\n LEFT JOIN users AS u2 on u2.id = c.user_id\n);","referenced_tables":["posts","comments","users"]},{"name":"CamelizeTable","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"created","type":"date","nullable":false}]},{"name":"hyphen-table","type":"BASIC TABLE","columns":[{"name":"id","type":"int","nullable":false},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"date","nullable":false}]},{"name":"administrator.blogs","type":"BASIC TABLE","comment":"admin blogs","columns":[{"name":"id","type":"int","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"date","nullable":false},{"name":"updated","type":"date","nullable":true}],"indexes":[{"name":"PK__blogs_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"administrator.blogs","columns":["id"]}],"constraints":[{"name":"PK__blogs_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ id ]","table":"administrator.blogs","columns":["id"]},{"name":"blogs_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO_ACTION ON DELETE CASCADE","table":"administrator.blogs","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}]},{"name":"name with spaces","type":"VIEW","columns":[{"name":"title","type":"varchar(255)","nullable":false}],"def":"CREATE VIEW \"name with spaces\" AS (\n SELECT TOP 1 p.title\n FROM posts AS p\n);","referenced_tables":["posts"]},{"name":"Sales.Product","type":"BASIC TABLE","columns":[{"name":"ProductID","type":"int","nullable":false},{"name":"SalesPersonID","type":"int","nullable":true}],"indexes":[{"name":"PK__Product_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ ProductID ]","table":"Sales.Product","columns":["ProductID"]},{"name":"UQ__Product_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ SalesPersonID ]","table":"Sales.Product","columns":["SalesPersonID"]}],"constraints":[{"name":"PK__Product_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ ProductID ]","table":"Sales.Product","columns":["ProductID"]},{"name":"UQ__Product_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ SalesPersonID ]","table":"Sales.Product","columns":["SalesPersonID"]}]},{"name":"Rabbits.Running","type":"BASIC TABLE","columns":[{"name":"LocationID","type":"int","nullable":false},{"name":"ProductID","type":"int","nullable":true},{"name":"EmployeeID","type":"int","nullable":true}],"indexes":[{"name":"PK__Running_*","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ LocationID ]","table":"Rabbits.Running","columns":["LocationID"]},{"name":"UQ__Running_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ EmployeeID ]","table":"Rabbits.Running","columns":["EmployeeID"]},{"name":"UQ__Running_*","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ ProductID ]","table":"Rabbits.Running","columns":["ProductID"]}],"constraints":[{"name":"PK__Running_*","type":"PRIMARY KEY","def":"CLUSTERED, unique, part of a PRIMARY KEY constraint, [ LocationID ]","table":"Rabbits.Running","columns":["LocationID"]},{"name":"UQ__Running_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ EmployeeID ]","table":"Rabbits.Running","columns":["EmployeeID"]},{"name":"UQ__Running_*","type":"UNIQUE","def":"NONCLUSTERED, unique, part of a UNIQUE constraint, [ ProductID ]","table":"Rabbits.Running","columns":["ProductID"]},{"name":"FK_TempSales_SalesReason","type":"FOREIGN KEY","def":"FOREIGN KEY(ProductID) REFERENCES Sales.Product(SalesPersonID) ON UPDATE NO_ACTION ON DELETE NO_ACTION","table":"Rabbits.Running","referenced_table":"Sales.Product","columns":["ProductID"],"referenced_columns":["SalesPersonID"]}]}],"relations":[{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":""},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":""},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":""},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":""},{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":""},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":""},{"table":"administrator.blogs","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":""},{"table":"Rabbits.Running","columns":["ProductID"],"cardinality":"zero_or_one","parent_table":"Sales.Product","parent_columns":["SalesPersonID"],"parent_cardinality":"zero_or_one","def":""},{"table":"logs","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"zero_or_more","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true}],"functions":[{"name":"dbo.get_user","return_type":"","arguments":"@userid int","type":"SQL inline table-valued function"},{"name":"dbo.What_DB_is_that","return_type":"","arguments":"@ID int","type":"SQL Stored Procedure"}],"driver":{"name":"sqlserver","database_version":"Microsoft SQL Server 2019 (RTM-CU30) (KB5049235) - 15.0.4415.2 (X64) \n\tNov 18 2024 17:45:37 \n\tCopyright (C) 2019 Microsoft Corporation\n\tDeveloper Edition (64-bit) on Linux (Ubuntu 20.04.6 LTS) \u003cX64\u003e","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/mysql/schema.json b/sample/mysql/schema.json index 901682cb..5c731a00 100644 --- a/sample/mysql/schema.json +++ b/sample/mysql/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"Exactly one","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"exactly_one","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/mysql56/schema.json b/sample/mysql56/schema.json index 916a81dc..685f903a 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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment_post_id","type":"bigint(20)","nullable":false},{"name":"comment_user_id","type":"int(11)","nullable":false},{"name":"created","type":"timestamp","nullable":false,"default":"CURRENT_TIMESTAMP","extra_def":"on update CURRENT_TIMESTAMP"},{"name":"updated","type":"timestamp","nullable":false,"default":"0000-00-00 00:00:00"}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint(20)","nullable":false},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"post_id","type":"bigint(20)","nullable":true},{"name":"comment_id","type":"bigint(20)","nullable":true},{"name":"comment_star_id","type":"bigint(20)","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint(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,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS ((select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`)))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint(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},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false,"default":"CURRENT_TIMESTAMP","extra_def":"on update CURRENT_TIMESTAMP"},{"name":"updated","type":"timestamp","nullable":false,"default":"0000-00-00 00:00:00"}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int(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,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false,"default":"CURRENT_TIMESTAMP","extra_def":"on update CURRENT_TIMESTAMP"},{"name":"updated","type":"timestamp","nullable":false,"default":"0000-00-00 00:00:00"}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]}],"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)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"Exactly one","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Additional Relation","virtual":true}],"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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment_post_id","type":"bigint(20)","nullable":false},{"name":"comment_user_id","type":"int(11)","nullable":false},{"name":"created","type":"timestamp","nullable":false,"default":"CURRENT_TIMESTAMP","extra_def":"on update CURRENT_TIMESTAMP"},{"name":"updated","type":"timestamp","nullable":false,"default":"0000-00-00 00:00:00"}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint(20)","nullable":false},{"name":"user_id","type":"int(11)","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint(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","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint(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,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"post_id","type":"bigint(20)","nullable":true},{"name":"comment_id","type":"bigint(20)","nullable":true},{"name":"comment_star_id","type":"bigint(20)","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint(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,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS ((select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`)))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint(20)","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int(11)","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint(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},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false,"default":"CURRENT_TIMESTAMP","extra_def":"on update CURRENT_TIMESTAMP"},{"name":"updated","type":"timestamp","nullable":false,"default":"0000-00-00 00:00:00"}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int(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,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false,"default":"CURRENT_TIMESTAMP","extra_def":"on update CURRENT_TIMESTAMP"},{"name":"updated","type":"timestamp","nullable":false,"default":"0000-00-00 00:00:00"}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]}],"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)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"exactly_one","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"Additional Relation","virtual":true}],"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 e819c6f0..7209b78e 100644 --- a/sample/number/schema.json +++ b/sample/number/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/png/schema.json b/sample/png/schema.json index 901682cb..5c731a00 100644 --- a/sample/png/schema.json +++ b/sample/png/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"Exactly one","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'"},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"green","virtual":true},{"name":"red","virtual":true},{"name":"blue","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'"},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'"}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"exactly_one","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/postgres/schema.json b/sample/postgres/schema.json index b649de22..9f7c5b70 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)"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"users_pkey","def":"CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)","table":"public.users","columns":["id"]},{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)","table":"public.users","columns":["username"]},{"name":"users_email_key","def":"CREATE UNIQUE INDEX users_email_key ON public.users USING btree (email)","table":"public.users","columns":["email"]}],"constraints":[{"name":"users_username_check","type":"CHECK","def":"CHECK ((char_length((username)::text) \u003e 4))","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.users","referenced_table":"","columns":["id"]},{"name":"users_username_key","type":"UNIQUE","def":"UNIQUE (username)","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_email_key","type":"UNIQUE","def":"UNIQUE (email)","table":"public.users","referenced_table":"","columns":["email"]}],"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"}]},{"name":"public.user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"integer","nullable":false},{"name":"show_email","type":"boolean","nullable":false,"default":"false"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}]},{"name":"public.posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"default":"nextval('posts_id_seq'::regclass)"},{"name":"user_id","type":"integer","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'::character varying"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"post_types","nullable":false,"comment":"public/private/draft"},{"name":"labels","type":"varchar(50)[]","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CREATE UNIQUE INDEX posts_id_pk ON public.posts USING btree (id)","table":"public.posts","columns":["id"]},{"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":["user_id","title"]},{"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"]},{"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"]},{"name":"posts_user_id_title_key","type":"UNIQUE","def":"UNIQUE (user_id, title)","table":"public.posts","referenced_table":"","columns":["user_id","title"]}],"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"}]},{"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)"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"integer","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (post_id * '-1'::integer) STORED"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CREATE UNIQUE INDEX comments_id_pk ON public.comments USING btree (id)","table":"public.comments","columns":["id"]},{"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"]},{"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"]}],"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"]},{"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"]},{"name":"comments_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.comments","referenced_table":"","columns":["id"]},{"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"]}]},{"name":"public.comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"user_id","type":"integer","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"integer","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","table":"public.comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id)","table":"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"]},{"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"]}]},{"name":"public.logs","type":"BASE TABLE","comment":"audit log table","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"user_id","type":"integer","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"uuid","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false}]},{"name":"public.post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"timestamp without time zone","nullable":true,"comment":"comments.created"},{"name":"updated","type":"timestamp without time zone","nullable":true,"comment":"comments.updated"}],"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","columns":[{"name":"id","type":"uuid","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"comment_star_user","type":"varchar(50)","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"created","type":"timestamp without time zone","nullable":false}],"indexes":[{"name":"CamelizeTable_id_key","def":"CREATE UNIQUE INDEX \"CamelizeTable_id_key\" ON public.\"CamelizeTable\" USING btree (id)","table":"public.CamelizeTable","columns":["id"]}],"constraints":[{"name":"CamelizeTable_id_key","type":"UNIQUE","def":"UNIQUE (id)","table":"public.CamelizeTable","referenced_table":"","columns":["id"]}]},{"name":"public.hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"CamelizeTableId","type":"uuid","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false}],"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"]}],"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"]},{"name":"hyphen-table_hyphen-column_key","type":"UNIQUE","def":"UNIQUE (\"hyphen-column\")","table":"public.hyphen-table","referenced_table":"","columns":["hyphen-column"]}]},{"name":"administrator.blogs","type":"BASE TABLE","comment":"admin blogs","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('administrator.blogs_id_seq'::regclass)"},{"name":"user_id","type":"integer","nullable":false},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON administrator.blogs USING btree (id)","table":"administrator.blogs","columns":["id"]}],"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"]},{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"administrator.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blogs","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blogs_id_seq'::regclass)"},{"name":"user_id","type":"integer","nullable":false},{"name":"dump","type":"text","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON backup.blogs USING btree (id)","table":"backup.blogs","columns":["id"]}],"constraints":[{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blog_options","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blog_options_id_seq'::regclass)"},{"name":"blog_id","type":"integer","nullable":false},{"name":"label","type":"text","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}],"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"]},{"name":"blog_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blog_options","referenced_table":"","columns":["id"]}]},{"name":"time.bar","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"indexes":[{"name":"bar_pkey","def":"CREATE UNIQUE INDEX bar_pkey ON \"time\".bar USING btree (id)","table":"time.bar","columns":["id"]}],"constraints":[{"name":"bar_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.bar","referenced_table":"","columns":["id"]}]},{"name":"time.hyphenated-table","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"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"]}],"constraints":[{"name":"hyphenated-table_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.hyphenated-table","referenced_table":"","columns":["id"]}]},{"name":"time.referencing","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false},{"name":"bar_id","type":"integer","nullable":false},{"name":"ht_id","type":"integer","nullable":false}],"indexes":[{"name":"referencing_pkey","def":"CREATE UNIQUE INDEX referencing_pkey ON \"time\".referencing USING btree (id)","table":"time.referencing","columns":["id"]}],"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"]},{"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"]},{"name":"referencing_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.referencing","referenced_table":"","columns":["id"]}]}],"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"},{"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)"},{"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)"},{"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)"},{"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)"},{"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)"},{"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"},{"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"},{"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"},{"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)"},{"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)"},{"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"}],"enums":[{"name":"public.post_types","values":["draft","private","public"]}],"driver":{"name":"postgres","database_version":"PostgreSQL 15.10 (Debian 15.10-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit","meta":{"current_schema":"public","search_paths":["postgres","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}},"viewpoints":[{"name":"post","desc":"for post","tables":["public.post*"]},{"name":"administrator","desc":"administrator schema only","tables":["administrator.*"]}]} +{"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)"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"users_pkey","def":"CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)","table":"public.users","columns":["id"]},{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)","table":"public.users","columns":["username"]},{"name":"users_email_key","def":"CREATE UNIQUE INDEX users_email_key ON public.users USING btree (email)","table":"public.users","columns":["email"]}],"constraints":[{"name":"users_username_check","type":"CHECK","def":"CHECK ((char_length((username)::text) \u003e 4))","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.users","referenced_table":"","columns":["id"]},{"name":"users_username_key","type":"UNIQUE","def":"UNIQUE (username)","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_email_key","type":"UNIQUE","def":"UNIQUE (email)","table":"public.users","referenced_table":"","columns":["email"]}],"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"}]},{"name":"public.user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"integer","nullable":false},{"name":"show_email","type":"boolean","nullable":false,"default":"false"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}]},{"name":"public.posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"default":"nextval('posts_id_seq'::regclass)"},{"name":"user_id","type":"integer","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'::character varying"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"post_types","nullable":false,"comment":"public/private/draft"},{"name":"labels","type":"varchar(50)[]","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CREATE UNIQUE INDEX posts_id_pk ON public.posts USING btree (id)","table":"public.posts","columns":["id"]},{"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":["user_id","title"]},{"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"]},{"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"]},{"name":"posts_user_id_title_key","type":"UNIQUE","def":"UNIQUE (user_id, title)","table":"public.posts","referenced_table":"","columns":["user_id","title"]}],"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"}]},{"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)"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"integer","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (post_id * '-1'::integer) STORED"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CREATE UNIQUE INDEX comments_id_pk ON public.comments USING btree (id)","table":"public.comments","columns":["id"]},{"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"]},{"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"]}],"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"]},{"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"]},{"name":"comments_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.comments","referenced_table":"","columns":["id"]},{"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"]}]},{"name":"public.comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"user_id","type":"integer","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"integer","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","table":"public.comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id)","table":"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"]},{"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"]}]},{"name":"public.logs","type":"BASE TABLE","comment":"audit log table","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"user_id","type":"integer","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"uuid","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false}]},{"name":"public.post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"timestamp without time zone","nullable":true,"comment":"comments.created"},{"name":"updated","type":"timestamp without time zone","nullable":true,"comment":"comments.updated"}],"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","columns":[{"name":"id","type":"uuid","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"comment_star_user","type":"varchar(50)","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"created","type":"timestamp without time zone","nullable":false}],"indexes":[{"name":"CamelizeTable_id_key","def":"CREATE UNIQUE INDEX \"CamelizeTable_id_key\" ON public.\"CamelizeTable\" USING btree (id)","table":"public.CamelizeTable","columns":["id"]}],"constraints":[{"name":"CamelizeTable_id_key","type":"UNIQUE","def":"UNIQUE (id)","table":"public.CamelizeTable","referenced_table":"","columns":["id"]}]},{"name":"public.hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"CamelizeTableId","type":"uuid","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false}],"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"]}],"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"]},{"name":"hyphen-table_hyphen-column_key","type":"UNIQUE","def":"UNIQUE (\"hyphen-column\")","table":"public.hyphen-table","referenced_table":"","columns":["hyphen-column"]}]},{"name":"administrator.blogs","type":"BASE TABLE","comment":"admin blogs","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('administrator.blogs_id_seq'::regclass)"},{"name":"user_id","type":"integer","nullable":false},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON administrator.blogs USING btree (id)","table":"administrator.blogs","columns":["id"]}],"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"]},{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"administrator.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blogs","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blogs_id_seq'::regclass)"},{"name":"user_id","type":"integer","nullable":false},{"name":"dump","type":"text","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON backup.blogs USING btree (id)","table":"backup.blogs","columns":["id"]}],"constraints":[{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blog_options","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blog_options_id_seq'::regclass)"},{"name":"blog_id","type":"integer","nullable":false},{"name":"label","type":"text","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}],"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"]},{"name":"blog_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blog_options","referenced_table":"","columns":["id"]}]},{"name":"time.bar","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"indexes":[{"name":"bar_pkey","def":"CREATE UNIQUE INDEX bar_pkey ON \"time\".bar USING btree (id)","table":"time.bar","columns":["id"]}],"constraints":[{"name":"bar_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.bar","referenced_table":"","columns":["id"]}]},{"name":"time.hyphenated-table","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"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"]}],"constraints":[{"name":"hyphenated-table_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.hyphenated-table","referenced_table":"","columns":["id"]}]},{"name":"time.referencing","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false},{"name":"bar_id","type":"integer","nullable":false},{"name":"ht_id","type":"integer","nullable":false}],"indexes":[{"name":"referencing_pkey","def":"CREATE UNIQUE INDEX referencing_pkey ON \"time\".referencing USING btree (id)","table":"time.referencing","columns":["id"]}],"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"]},{"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"]},{"name":"referencing_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.referencing","referenced_table":"","columns":["id"]}]}],"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"},{"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)"},{"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)"},{"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)"},{"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)"},{"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)"},{"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"},{"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"},{"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"},{"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)"},{"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)"},{"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"}],"enums":[{"name":"public.post_types","values":["draft","private","public"]}],"driver":{"name":"postgres","database_version":"PostgreSQL 15.10 (Debian 15.10-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit","meta":{"current_schema":"public","search_paths":["postgres","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}},"viewpoints":[{"name":"post","desc":"for post","tables":["public.post*"]},{"name":"administrator","desc":"administrator schema only","tables":["administrator.*"]}]} diff --git a/sample/postgres95/schema.json b/sample/postgres95/schema.json index 53e4ee6e..d1550f5b 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)"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"users_pkey","def":"CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)","table":"public.users","columns":["id"]},{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)","table":"public.users","columns":["username"]},{"name":"users_email_key","def":"CREATE UNIQUE INDEX users_email_key ON public.users USING btree (email)","table":"public.users","columns":["email"]}],"constraints":[{"name":"users_username_check","type":"CHECK","def":"CHECK ((char_length((username)::text) \u003e 4))","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.users","referenced_table":"","columns":["id"]},{"name":"users_username_key","type":"UNIQUE","def":"UNIQUE (username)","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_email_key","type":"UNIQUE","def":"UNIQUE (email)","table":"public.users","referenced_table":"","columns":["email"]}],"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"}]},{"name":"public.user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"integer","nullable":false},{"name":"show_email","type":"boolean","nullable":false,"default":"false"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}]},{"name":"public.posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"default":"nextval('posts_id_seq'::regclass)"},{"name":"user_id","type":"integer","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'::character varying"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"post_types","nullable":false,"comment":"public/private/draft"},{"name":"labels","type":"varchar(50)[]","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CREATE UNIQUE INDEX posts_id_pk ON public.posts USING btree (id)","table":"public.posts","columns":["id"]},{"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":["user_id","title"]},{"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"]},{"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"]},{"name":"posts_user_id_title_key","type":"UNIQUE","def":"UNIQUE (user_id, title)","table":"public.posts","referenced_table":"","columns":["user_id","title"]}],"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"}]},{"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)"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"integer","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CREATE UNIQUE INDEX comments_id_pk ON public.comments USING btree (id)","table":"public.comments","columns":["id"]},{"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"]},{"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"]}],"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"]},{"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"]},{"name":"comments_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.comments","referenced_table":"","columns":["id"]},{"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"]}]},{"name":"public.comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"user_id","type":"integer","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"integer","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","table":"public.comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id)","table":"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"]},{"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"]}]},{"name":"public.logs","type":"BASE TABLE","comment":"audit log table","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"user_id","type":"integer","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"uuid","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false}]},{"name":"public.post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"timestamp without time zone","nullable":true,"comment":"comments.created"},{"name":"updated","type":"timestamp without time zone","nullable":true,"comment":"comments.updated"}],"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","columns":[{"name":"id","type":"uuid","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"comment_star_user","type":"varchar(50)","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"created","type":"timestamp without time zone","nullable":false}],"indexes":[{"name":"CamelizeTable_id_key","def":"CREATE UNIQUE INDEX \"CamelizeTable_id_key\" ON public.\"CamelizeTable\" USING btree (id)","table":"public.CamelizeTable","columns":["id"]}],"constraints":[{"name":"CamelizeTable_id_key","type":"UNIQUE","def":"UNIQUE (id)","table":"public.CamelizeTable","referenced_table":"","columns":["id"]}]},{"name":"public.hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"CamelizeTableId","type":"uuid","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false}],"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"]}],"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"]},{"name":"hyphen-table_hyphen-column_key","type":"UNIQUE","def":"UNIQUE (\"hyphen-column\")","table":"public.hyphen-table","referenced_table":"","columns":["hyphen-column"]}]},{"name":"administrator.blogs","type":"BASE TABLE","comment":"admin blogs","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('administrator.blogs_id_seq'::regclass)"},{"name":"user_id","type":"integer","nullable":false},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON administrator.blogs USING btree (id)","table":"administrator.blogs","columns":["id"]}],"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"]},{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"administrator.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blogs","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blogs_id_seq'::regclass)"},{"name":"user_id","type":"integer","nullable":false},{"name":"dump","type":"text","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON backup.blogs USING btree (id)","table":"backup.blogs","columns":["id"]}],"constraints":[{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blog_options","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blog_options_id_seq'::regclass)"},{"name":"blog_id","type":"integer","nullable":false},{"name":"label","type":"text","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}],"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"]},{"name":"blog_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blog_options","referenced_table":"","columns":["id"]}]},{"name":"time.bar","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"indexes":[{"name":"bar_pkey","def":"CREATE UNIQUE INDEX bar_pkey ON \"time\".bar USING btree (id)","table":"time.bar","columns":["id"]}],"constraints":[{"name":"bar_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.bar","referenced_table":"","columns":["id"]}]},{"name":"time.hyphenated-table","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"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"]}],"constraints":[{"name":"hyphenated-table_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.hyphenated-table","referenced_table":"","columns":["id"]}]},{"name":"time.referencing","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false},{"name":"bar_id","type":"integer","nullable":false},{"name":"ht_id","type":"integer","nullable":false}],"indexes":[{"name":"referencing_pkey","def":"CREATE UNIQUE INDEX referencing_pkey ON \"time\".referencing USING btree (id)","table":"time.referencing","columns":["id"]}],"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"]},{"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"]},{"name":"referencing_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.referencing","referenced_table":"","columns":["id"]}]}],"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"},{"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"},{"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)"},{"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)"},{"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)"},{"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)"},{"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"},{"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"},{"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"},{"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)"},{"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)"},{"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"}],"enums":[{"name":"public.post_types","values":["draft","private","public"]}],"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":["postgres","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}},"viewpoints":[{"name":"post","desc":"for post","tables":["public.post*"]},{"name":"administrator","desc":"administrator schema only","tables":["administrator.*"]}]} +{"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)"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false},{"name":"email","type":"varchar(355)","nullable":false,"comment":"ex. user@example.com"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"users_pkey","def":"CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)","table":"public.users","columns":["id"]},{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)","table":"public.users","columns":["username"]},{"name":"users_email_key","def":"CREATE UNIQUE INDEX users_email_key ON public.users USING btree (email)","table":"public.users","columns":["email"]}],"constraints":[{"name":"users_username_check","type":"CHECK","def":"CHECK ((char_length((username)::text) \u003e 4))","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.users","referenced_table":"","columns":["id"]},{"name":"users_username_key","type":"UNIQUE","def":"UNIQUE (username)","table":"public.users","referenced_table":"","columns":["username"]},{"name":"users_email_key","type":"UNIQUE","def":"UNIQUE (email)","table":"public.users","referenced_table":"","columns":["email"]}],"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"}]},{"name":"public.user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"integer","nullable":false},{"name":"show_email","type":"boolean","nullable":false,"default":"false"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}]},{"name":"public.posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"default":"nextval('posts_id_seq'::regclass)"},{"name":"user_id","type":"integer","nullable":false},{"name":"title","type":"varchar(255)","nullable":false,"default":"'Untitled'::character varying"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"post_types","nullable":false,"comment":"public/private/draft"},{"name":"labels","type":"varchar(50)[]","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"posts_id_pk","def":"CREATE UNIQUE INDEX posts_id_pk ON public.posts USING btree (id)","table":"public.posts","columns":["id"]},{"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":["user_id","title"]},{"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"]},{"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"]},{"name":"posts_user_id_title_key","type":"UNIQUE","def":"UNIQUE (user_id, title)","table":"public.posts","referenced_table":"","columns":["user_id","title"]}],"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"}]},{"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)"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"integer","nullable":false},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"comments_id_pk","def":"CREATE UNIQUE INDEX comments_id_pk ON public.comments USING btree (id)","table":"public.comments","columns":["id"]},{"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"]},{"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"]}],"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"]},{"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"]},{"name":"comments_id_pk","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"public.comments","referenced_table":"","columns":["id"]},{"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"]}]},{"name":"public.comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"user_id","type":"integer","nullable":false},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"integer","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users(id)","table":"public.comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id)","table":"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"]},{"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"]}]},{"name":"public.logs","type":"BASE TABLE","comment":"audit log table","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"user_id","type":"integer","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"uuid","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false}]},{"name":"public.post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"timestamp without time zone","nullable":true,"comment":"comments.created"},{"name":"updated","type":"timestamp without time zone","nullable":true,"comment":"comments.updated"}],"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","columns":[{"name":"id","type":"uuid","nullable":true},{"name":"comment_user","type":"varchar(50)","nullable":true},{"name":"comment_star_user","type":"varchar(50)","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"created","type":"timestamp without time zone","nullable":false}],"indexes":[{"name":"CamelizeTable_id_key","def":"CREATE UNIQUE INDEX \"CamelizeTable_id_key\" ON public.\"CamelizeTable\" USING btree (id)","table":"public.CamelizeTable","columns":["id"]}],"constraints":[{"name":"CamelizeTable_id_key","type":"UNIQUE","def":"UNIQUE (id)","table":"public.CamelizeTable","referenced_table":"","columns":["id"]}]},{"name":"public.hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"uuid","nullable":false,"default":"uuid_generate_v4()"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"CamelizeTableId","type":"uuid","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false}],"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"]}],"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"]},{"name":"hyphen-table_hyphen-column_key","type":"UNIQUE","def":"UNIQUE (\"hyphen-column\")","table":"public.hyphen-table","referenced_table":"","columns":["hyphen-column"]}]},{"name":"administrator.blogs","type":"BASE TABLE","comment":"admin blogs","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('administrator.blogs_id_seq'::regclass)"},{"name":"user_id","type":"integer","nullable":false},{"name":"name","type":"text","nullable":false},{"name":"description","type":"text","nullable":true},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON administrator.blogs USING btree (id)","table":"administrator.blogs","columns":["id"]}],"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"]},{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"administrator.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blogs","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blogs_id_seq'::regclass)"},{"name":"user_id","type":"integer","nullable":false},{"name":"dump","type":"text","nullable":false},{"name":"created","type":"timestamp without time zone","nullable":false},{"name":"updated","type":"timestamp without time zone","nullable":true}],"indexes":[{"name":"blogs_pkey","def":"CREATE UNIQUE INDEX blogs_pkey ON backup.blogs USING btree (id)","table":"backup.blogs","columns":["id"]}],"constraints":[{"name":"blogs_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blogs","referenced_table":"","columns":["id"]}]},{"name":"backup.blog_options","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false,"default":"nextval('blog_options_id_seq'::regclass)"},{"name":"blog_id","type":"integer","nullable":false},{"name":"label","type":"text","nullable":true},{"name":"updated","type":"timestamp without time zone","nullable":true}],"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"]}],"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"]},{"name":"blog_options_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"backup.blog_options","referenced_table":"","columns":["id"]}]},{"name":"time.bar","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"indexes":[{"name":"bar_pkey","def":"CREATE UNIQUE INDEX bar_pkey ON \"time\".bar USING btree (id)","table":"time.bar","columns":["id"]}],"constraints":[{"name":"bar_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.bar","referenced_table":"","columns":["id"]}]},{"name":"time.hyphenated-table","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false}],"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"]}],"constraints":[{"name":"hyphenated-table_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.hyphenated-table","referenced_table":"","columns":["id"]}]},{"name":"time.referencing","type":"BASE TABLE","columns":[{"name":"id","type":"integer","nullable":false},{"name":"bar_id","type":"integer","nullable":false},{"name":"ht_id","type":"integer","nullable":false}],"indexes":[{"name":"referencing_pkey","def":"CREATE UNIQUE INDEX referencing_pkey ON \"time\".referencing USING btree (id)","table":"time.referencing","columns":["id"]}],"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"]},{"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"]},{"name":"referencing_pkey","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"time.referencing","referenced_table":"","columns":["id"]}]}],"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"},{"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"},{"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)"},{"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)"},{"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)"},{"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)"},{"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"},{"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"},{"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"},{"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)"},{"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)"},{"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"}],"enums":[{"name":"public.post_types","values":["draft","private","public"]}],"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":["postgres","public","backup"],"dict":{"Functions":"Stored procedures and functions"}}},"viewpoints":[{"name":"post","desc":"for post","tables":["public.post*"]},{"name":"administrator","desc":"administrator schema only","tables":["administrator.*"]}]} diff --git a/sample/sqlite/schema.json b/sample/sqlite/schema.json index c28290db..5ddf6445 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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"username","type":"TEXT","nullable":false},{"name":"password","type":"TEXT","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"TEXT","nullable":false,"labels":[{"name":"secure","virtual":true}]},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"indexes":[{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON users(username)","table":"users","columns":["username"]},{"name":"sqlite_autoindex_users_2","def":"UNIQUE (email)","table":"users","columns":["email"]},{"name":"sqlite_autoindex_users_1","def":"UNIQUE (username)","table":"users","columns":["username"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"sqlite_autoindex_users_2","type":"UNIQUE","def":"UNIQUE (email)","table":"users","columns":["email"]},{"name":"sqlite_autoindex_users_1","type":"UNIQUE","def":"UNIQUE (username)","table":"users","columns":["username"]},{"name":"-","type":"CHECK","def":"CHECK(length(username) \u003e 4)","table":"users","columns":["username"]}],"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","columns":[{"name":"user_id","type":"INTEGER","nullable":true},{"name":"show_email","type":"INTEGER","nullable":false,"default":"0"},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"constraints":[{"name":"user_id","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"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"]}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"title","type":"TEXT","nullable":false},{"name":"body","type":"TEXT","nullable":false,"comment":"post body"},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"CREATE INDEX posts_user_id_idx ON posts(user_id)","table":"posts","columns":["user_id"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"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"]}],"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"}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"post_id","type":"INTEGER","nullable":false},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"comment","type":"TEXT","nullable":false},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"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"]},{"name":"sqlite_autoindex_comments_1","def":"UNIQUE (post_id, user_id)","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]},{"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"]},{"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"]},{"name":"sqlite_autoindex_comments_1","type":"UNIQUE","def":"UNIQUE (post_id, user_id)","table":"comments","columns":["post_id","user_id"]}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"comment_post_id","type":"INTEGER","nullable":false},{"name":"comment_user_id","type":"INTEGER","nullable":false},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"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"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"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"]},{"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"]},{"name":"sqlite_autoindex_comment_stars_1","type":"UNIQUE","def":"UNIQUE (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE comment_stars (\n id 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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"post_id","type":"INTEGER","nullable":true},{"name":"comment_id","type":"INTEGER","nullable":true},{"name":"comment_star_id","type":"INTEGER","nullable":true},{"name":"payload","type":"TEXT","nullable":true},{"name":"created","type":"NUMERIC","nullable":false}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"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,"comment":"comments.id"},{"name":"title","type":"TEXT","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"TEXT","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"TEXT","nullable":true},{"name":"comment_user","type":"TEXT","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"NUMERIC","nullable":true,"comment":"comments.created"},{"name":"updated","type":"NUMERIC","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS\n SELECT c.id, p.title, u2.username AS post_user, c.comment, u2.username AS comment_user, c.created, c.updated\n FROM posts AS p\n LEFT JOIN comments AS c on p.id = c.post_id\n LEFT JOIN users AS u on u.id = p.user_id\n LEFT JOIN users AS u2 on u2.id = c.user_id","referenced_tables":["posts","comments","users"]},{"name":"CamelizeTable","type":"table","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"created","type":"NUMERIC","nullable":false}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE CamelizeTable (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n created NUMERIC NOT NULL\n)"},{"name":"hyphen-table","type":"table","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"hyphen-column","type":"TEXT","nullable":false},{"name":"created","type":"NUMERIC","nullable":false}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"col","type":"TEXT","nullable":true},{"name":"brackets","type":"TEXT","nullable":false},{"name":"checkcheck","type":"TEXT","nullable":false},{"name":"downcase","type":"TEXT","nullable":false},{"name":"nl","type":"TEXT","nullable":false}],"indexes":[{"name":"sqlite_autoindex_check_constraints_4","def":"UNIQUE (nl)","table":"check_constraints","columns":["nl"]},{"name":"sqlite_autoindex_check_constraints_3","def":"UNIQUE (downcase)","table":"check_constraints","columns":["downcase"]},{"name":"sqlite_autoindex_check_constraints_2","def":"UNIQUE (checkcheck)","table":"check_constraints","columns":["checkcheck"]},{"name":"sqlite_autoindex_check_constraints_1","def":"UNIQUE (brackets)","table":"check_constraints","columns":["brackets"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"check_constraints","columns":["id"]},{"name":"sqlite_autoindex_check_constraints_4","type":"UNIQUE","def":"UNIQUE (nl)","table":"check_constraints","columns":["nl"]},{"name":"sqlite_autoindex_check_constraints_3","type":"UNIQUE","def":"UNIQUE (downcase)","table":"check_constraints","columns":["downcase"]},{"name":"sqlite_autoindex_check_constraints_2","type":"UNIQUE","def":"UNIQUE (checkcheck)","table":"check_constraints","columns":["checkcheck"]},{"name":"sqlite_autoindex_check_constraints_1","type":"UNIQUE","def":"UNIQUE (brackets)","table":"check_constraints","columns":["brackets"]},{"name":"-","type":"CHECK","def":"CHECK(length(col) \u003e 4)","table":"check_constraints","columns":["col"]},{"name":"-","type":"CHECK","def":"CHECK(((length(brackets) \u003e 4)))","table":"check_constraints","columns":["brackets"]},{"name":"-","type":"CHECK","def":"CHECK(length(checkcheck) \u003e 4)","table":"check_constraints","columns":["checkcheck"]},{"name":"-","type":"CHECK","def":"check(length(downcase) \u003e 4)","table":"check_constraints","columns":["downcase"]},{"name":"-","type":"CHECK","def":"check(length(nl) \u003e 4 OR nl != 'ln')","table":"check_constraints","columns":["nl"]}],"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","columns":[{"name":"logs","type":"","nullable":true}],"def":"CREATE VIRTUAL TABLE syslog USING fts3(logs)"},{"name":"access_log","type":"virtual table","columns":[{"name":"logs","type":"","nullable":true}],"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"},{"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"},{"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"},{"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"},{"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"},{"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"},{"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}],"driver":{"name":"sqlite","database_version":"3.46.1"},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} +{"name":"testdb.sqlite3","desc":"Sample database document.","tables":[{"name":"users","type":"table","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"username","type":"TEXT","nullable":false},{"name":"password","type":"TEXT","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"TEXT","nullable":false,"labels":[{"name":"secure","virtual":true}]},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"indexes":[{"name":"users_username_key","def":"CREATE UNIQUE INDEX users_username_key ON users(username)","table":"users","columns":["username"]},{"name":"sqlite_autoindex_users_2","def":"UNIQUE (email)","table":"users","columns":["email"]},{"name":"sqlite_autoindex_users_1","def":"UNIQUE (username)","table":"users","columns":["username"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"sqlite_autoindex_users_2","type":"UNIQUE","def":"UNIQUE (email)","table":"users","columns":["email"]},{"name":"sqlite_autoindex_users_1","type":"UNIQUE","def":"UNIQUE (username)","table":"users","columns":["username"]},{"name":"-","type":"CHECK","def":"CHECK(length(username) \u003e 4)","table":"users","columns":["username"]}],"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","columns":[{"name":"user_id","type":"INTEGER","nullable":true},{"name":"show_email","type":"INTEGER","nullable":false,"default":"0"},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"constraints":[{"name":"user_id","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"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"]}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"title","type":"TEXT","nullable":false},{"name":"body","type":"TEXT","nullable":false,"comment":"post body"},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"CREATE INDEX posts_user_id_idx ON posts(user_id)","table":"posts","columns":["user_id"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"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"]}],"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"}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"post_id","type":"INTEGER","nullable":false},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"comment","type":"TEXT","nullable":false},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"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"]},{"name":"sqlite_autoindex_comments_1","def":"UNIQUE (post_id, user_id)","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]},{"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"]},{"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"]},{"name":"sqlite_autoindex_comments_1","type":"UNIQUE","def":"UNIQUE (post_id, user_id)","table":"comments","columns":["post_id","user_id"]}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"comment_post_id","type":"INTEGER","nullable":false},{"name":"comment_user_id","type":"INTEGER","nullable":false},{"name":"created","type":"NUMERIC","nullable":false},{"name":"updated","type":"NUMERIC","nullable":true}],"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"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"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"]},{"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"]},{"name":"sqlite_autoindex_comment_stars_1","type":"UNIQUE","def":"UNIQUE (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE comment_stars (\n id 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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"user_id","type":"INTEGER","nullable":false},{"name":"post_id","type":"INTEGER","nullable":true},{"name":"comment_id","type":"INTEGER","nullable":true},{"name":"comment_star_id","type":"INTEGER","nullable":true},{"name":"payload","type":"TEXT","nullable":true},{"name":"created","type":"NUMERIC","nullable":false}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"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,"comment":"comments.id"},{"name":"title","type":"TEXT","nullable":true,"comment":"posts.title"},{"name":"post_user","type":"TEXT","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"TEXT","nullable":true},{"name":"comment_user","type":"TEXT","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"NUMERIC","nullable":true,"comment":"comments.created"},{"name":"updated","type":"NUMERIC","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS\n SELECT c.id, p.title, u2.username AS post_user, c.comment, u2.username AS comment_user, c.created, c.updated\n FROM posts AS p\n LEFT JOIN comments AS c on p.id = c.post_id\n LEFT JOIN users AS u on u.id = p.user_id\n LEFT JOIN users AS u2 on u2.id = c.user_id","referenced_tables":["posts","comments","users"]},{"name":"CamelizeTable","type":"table","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"created","type":"NUMERIC","nullable":false}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE CamelizeTable (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n created NUMERIC NOT NULL\n)"},{"name":"hyphen-table","type":"table","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"hyphen-column","type":"TEXT","nullable":false},{"name":"created","type":"NUMERIC","nullable":false}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"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","columns":[{"name":"id","type":"INTEGER","nullable":true},{"name":"col","type":"TEXT","nullable":true},{"name":"brackets","type":"TEXT","nullable":false},{"name":"checkcheck","type":"TEXT","nullable":false},{"name":"downcase","type":"TEXT","nullable":false},{"name":"nl","type":"TEXT","nullable":false}],"indexes":[{"name":"sqlite_autoindex_check_constraints_4","def":"UNIQUE (nl)","table":"check_constraints","columns":["nl"]},{"name":"sqlite_autoindex_check_constraints_3","def":"UNIQUE (downcase)","table":"check_constraints","columns":["downcase"]},{"name":"sqlite_autoindex_check_constraints_2","def":"UNIQUE (checkcheck)","table":"check_constraints","columns":["checkcheck"]},{"name":"sqlite_autoindex_check_constraints_1","def":"UNIQUE (brackets)","table":"check_constraints","columns":["brackets"]}],"constraints":[{"name":"id","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"check_constraints","columns":["id"]},{"name":"sqlite_autoindex_check_constraints_4","type":"UNIQUE","def":"UNIQUE (nl)","table":"check_constraints","columns":["nl"]},{"name":"sqlite_autoindex_check_constraints_3","type":"UNIQUE","def":"UNIQUE (downcase)","table":"check_constraints","columns":["downcase"]},{"name":"sqlite_autoindex_check_constraints_2","type":"UNIQUE","def":"UNIQUE (checkcheck)","table":"check_constraints","columns":["checkcheck"]},{"name":"sqlite_autoindex_check_constraints_1","type":"UNIQUE","def":"UNIQUE (brackets)","table":"check_constraints","columns":["brackets"]},{"name":"-","type":"CHECK","def":"CHECK(length(col) \u003e 4)","table":"check_constraints","columns":["col"]},{"name":"-","type":"CHECK","def":"CHECK(((length(brackets) \u003e 4)))","table":"check_constraints","columns":["brackets"]},{"name":"-","type":"CHECK","def":"CHECK(length(checkcheck) \u003e 4)","table":"check_constraints","columns":["checkcheck"]},{"name":"-","type":"CHECK","def":"check(length(downcase) \u003e 4)","table":"check_constraints","columns":["downcase"]},{"name":"-","type":"CHECK","def":"check(length(nl) \u003e 4 OR nl != 'ln')","table":"check_constraints","columns":["nl"]}],"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","columns":[{"name":"logs","type":"","nullable":true}],"def":"CREATE VIRTUAL TABLE syslog USING fts3(logs)"},{"name":"access_log","type":"virtual table","columns":[{"name":"logs","type":"","nullable":true}],"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"},{"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"},{"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"},{"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"},{"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"},{"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"},{"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}],"driver":{"name":"sqlite","database_version":"3.46.1"},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}]} diff --git a/sample/viewpoints/schema.json b/sample/viewpoints/schema.json index 77f7cfa5..fd66c9ef 100644 --- a/sample/viewpoints/schema.json +++ b/sample/viewpoints/schema.json @@ -1 +1 @@ -{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"labels":[{"name":"user","virtual":true}]},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci","labels":[{"name":"content","virtual":true}]},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false,"labels":[{"name":"user","virtual":true}]},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'","labels":[{"name":"content","virtual":true}]},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","labels":[{"name":"content","virtual":true}],"referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"labels":[{"name":"user","virtual":true}]},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"content","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'","labels":[{"name":"user","virtual":true}]},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'","labels":[{"name":"user","virtual":true}]}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"Zero or one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"Zero or more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"Exactly one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"Zero or more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"Zero or more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"Zero or more","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"Zero or one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}],"viewpoints":[{"name":"Content","desc":"Content as an asset for blogging services","labels":["content"]},{"name":"Ops","desc":"Tables to be referenced during operation","tables":["logs","users","posts"]},{"name":"Around the users table","desc":"Tables related to the users table","tables":["users"],"distance":1,"groups":[{"name":"Content","desc":"Content as an asset for blogging services","labels":["content"]}]},{"name":"Secure data","desc":"Tables with secure data","labels":["secure"]}]} +{"name":"testdb","desc":"Sample database document.","tables":[{"name":"CamelizeTable","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"CamelizeTable","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"CamelizeTable","columns":["id"]}],"def":"CREATE TABLE `CamelizeTable` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"comment_stars","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"labels":[{"name":"user","virtual":true}]},{"name":"comment_post_id","type":"bigint","nullable":false},{"name":"comment_user_id","type":"int","nullable":false},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"comment_stars_user_id_fk","def":"KEY comment_stars_user_id_fk (comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_user_id"]},{"name":"comment_stars_user_id_post_id_fk","def":"KEY comment_stars_user_id_post_id_fk (comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["comment_post_id","comment_user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comment_stars","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id) USING BTREE","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"constraints":[{"name":"comment_stars_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)","table":"comment_stars","referenced_table":"users","columns":["comment_user_id"],"referenced_columns":["id"]},{"name":"comment_stars_user_id_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)","table":"comment_stars","referenced_table":"comments","columns":["comment_post_id","comment_user_id"],"referenced_columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comment_stars","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, comment_post_id, comment_user_id)","table":"comment_stars","columns":["user_id","comment_post_id","comment_user_id"]}],"def":"CREATE TABLE `comment_stars` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `comment_post_id` bigint NOT NULL,\n `comment_user_id` int NOT NULL,\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_post_id_fk` (`comment_post_id`,`comment_user_id`),\n KEY `comment_stars_user_id_fk` (`comment_user_id`),\n CONSTRAINT `comment_stars_user_id_fk` FOREIGN KEY (`comment_user_id`) REFERENCES `users` (`id`),\n CONSTRAINT `comment_stars_user_id_post_id_fk` FOREIGN KEY (`comment_post_id`, `comment_user_id`) REFERENCES `comments` (`post_id`, `user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci","labels":[{"name":"content","virtual":true}]},{"name":"comments","type":"BASE TABLE","comment":"Comments\nMulti-line\r\ntable\rcomment","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"post_id","type":"bigint","nullable":false},{"name":"user_id","type":"int","nullable":false,"labels":[{"name":"user","virtual":true}]},{"name":"comment","type":"text","nullable":false,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"post_id_desc","type":"bigint","nullable":true,"extra_def":"GENERATED ALWAYS AS (`post_id` * -(1)) VIRTUAL"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"comments_post_id_user_id_idx","def":"KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]},{"name":"comments_user_id_fk","def":"KEY comments_user_id_fk (user_id) USING BTREE","table":"comments","columns":["user_id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"comments","columns":["id"]},{"name":"post_id","def":"UNIQUE KEY post_id (post_id, user_id) USING BTREE","table":"comments","columns":["post_id","user_id"]}],"constraints":[{"name":"comments_post_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (post_id) REFERENCES posts (id)","table":"comments","referenced_table":"posts","columns":["post_id"],"referenced_columns":["id"]},{"name":"comments_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"comments","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"post_id","type":"UNIQUE","def":"UNIQUE KEY post_id (post_id, user_id)","table":"comments","columns":["post_id","user_id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"comments","columns":["id"]}],"def":"CREATE TABLE `comments` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `post_id` bigint NOT NULL,\n `user_id` int NOT NULL,\n `comment` text NOT NULL COMMENT 'Comment\\nMulti-line\\r\\ncolumn\\rcomment',\n `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `post_id` (`post_id`,`user_id`),\n KEY `comments_user_id_fk` (`user_id`),\n KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),\n CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),\n CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\\nMulti-line\\r\\ntable\\rcomment'","labels":[{"name":"content","virtual":true}]},{"name":"hyphen-table","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"hyphen-column","type":"text","nullable":false},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"hyphen-table","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"hyphen-table","columns":["id"]}],"def":"CREATE TABLE `hyphen-table` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `hyphen-column` text NOT NULL,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"logs","type":"BASE TABLE","comment":"Auditログ","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false},{"name":"post_id","type":"bigint","nullable":true},{"name":"comment_id","type":"bigint","nullable":true},{"name":"comment_star_id","type":"bigint","nullable":true},{"name":"payload","type":"text","nullable":true},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"logs","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"logs","columns":["id"]}],"def":"CREATE TABLE `logs` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `post_id` bigint DEFAULT NULL,\n `comment_id` bigint DEFAULT NULL,\n `comment_star_id` bigint DEFAULT NULL,\n `payload` text,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Auditログ'"},{"name":"long_long_long_long_long_long_long_long_table_name","type":"BASE TABLE","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"created","type":"datetime","nullable":false}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"long_long_long_long_long_long_long_long_table_name","columns":["id"]}],"def":"CREATE TABLE `long_long_long_long_long_long_long_long_table_name` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `created` datetime NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"},{"name":"post_comments","type":"VIEW","comment":"post and comments View table","columns":[{"name":"id","type":"bigint","nullable":true,"default":"0","comment":"comments.id"},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled","comment":"posts.title"},{"name":"post_user","type":"varchar(50)","nullable":true,"comment":"posts.users.username"},{"name":"comment","type":"text","nullable":true,"comment":"Comment\nMulti-line\r\ncolumn\rcomment"},{"name":"comment_user","type":"varchar(50)","nullable":true,"comment":"comments.users.username"},{"name":"created","type":"datetime","nullable":true,"comment":"comments.created"},{"name":"updated","type":"datetime","nullable":true,"comment":"comments.updated"}],"def":"CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`.`username` AS `post_user`,`c`.`comment` AS `comment`,`u2`.`username` AS `comment_user`,`c`.`created` AS `created`,`c`.`updated` AS `updated` from (((`testdb`.`posts` `p` left join `testdb`.`comments` `c` on((`p`.`id` = `c`.`post_id`))) left join `testdb`.`users` `u` on((`u`.`id` = `p`.`user_id`))) left join `testdb`.`users` `u2` on((`u2`.`id` = `c`.`user_id`))))","labels":[{"name":"content","virtual":true}],"referenced_tables":["posts","comments","users"]},{"name":"posts","type":"BASE TABLE","comment":"Posts table","columns":[{"name":"id","type":"bigint","nullable":false,"extra_def":"auto_increment"},{"name":"user_id","type":"int","nullable":false,"labels":[{"name":"user","virtual":true}]},{"name":"title","type":"varchar(255)","nullable":false,"default":"Untitled"},{"name":"body","type":"text","nullable":false,"comment":"post body"},{"name":"post_type","type":"enum('public','private','draft')","nullable":false,"comment":"public/private/draft"},{"name":"created","type":"datetime","nullable":false},{"name":"updated","type":"datetime","nullable":true}],"indexes":[{"name":"posts_user_id_idx","def":"KEY posts_user_id_idx (id) USING BTREE","table":"posts","columns":["id"]},{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"posts","columns":["id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id, title) USING BTREE","table":"posts","columns":["user_id","title"]}],"constraints":[{"name":"posts_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"posts","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"posts","columns":["id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id, title)","table":"posts","columns":["user_id","title"]}],"triggers":[{"name":"update_posts_updated","def":"CREATE TRIGGER update_posts_updated BEFORE UPDATE ON posts\nFOR EACH ROW\nSET NEW.updated = CURRENT_TIMESTAMP()"}],"def":"CREATE TABLE `posts` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `user_id` int NOT NULL,\n `title` varchar(255) NOT NULL DEFAULT 'Untitled',\n `body` text NOT NULL,\n `post_type` enum('public','private','draft') NOT NULL COMMENT 'public/private/draft',\n `created` datetime NOT NULL,\n `updated` datetime DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `user_id` (`user_id`,`title`),\n KEY `posts_user_id_idx` (`id`) USING BTREE,\n CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Posts table'","labels":[{"name":"content","virtual":true}]},{"name":"user_options","type":"BASE TABLE","comment":"User options table","columns":[{"name":"user_id","type":"int","nullable":false},{"name":"show_email","type":"tinyint(1)","nullable":false,"default":"0"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (user_id) USING BTREE","table":"user_options","columns":["user_id"]},{"name":"user_id","def":"UNIQUE KEY user_id (user_id) USING BTREE","table":"user_options","columns":["user_id"]}],"constraints":[{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_id","type":"UNIQUE","def":"UNIQUE KEY user_id (user_id)","table":"user_options","columns":["user_id"]},{"name":"user_options_user_id_fk","type":"FOREIGN KEY","def":"FOREIGN KEY (user_id) REFERENCES users (id)","table":"user_options","referenced_table":"users","columns":["user_id"],"referenced_columns":["id"]}],"def":"CREATE TABLE `user_options` (\n `user_id` int NOT NULL,\n `show_email` tinyint(1) NOT NULL DEFAULT '0',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`user_id`),\n UNIQUE KEY `user_id` (`user_id`),\n CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='User options table'","labels":[{"name":"user","virtual":true}]},{"name":"users","type":"BASE TABLE","comment":"Users table","columns":[{"name":"id","type":"int","nullable":false,"extra_def":"auto_increment"},{"name":"username","type":"varchar(50)","nullable":false},{"name":"password","type":"varchar(50)","nullable":false,"labels":[{"name":"secure","virtual":true},{"name":"encrypted","virtual":true}]},{"name":"email","type":"varchar(355)","nullable":false,"labels":[{"name":"secure","virtual":true}],"comment":"ex. user@example.com"},{"name":"created","type":"timestamp","nullable":false},{"name":"updated","type":"timestamp","nullable":true}],"indexes":[{"name":"PRIMARY","def":"PRIMARY KEY (id) USING BTREE","table":"users","columns":["id"]},{"name":"email","def":"UNIQUE KEY email (email) USING BTREE","table":"users","columns":["email"]},{"name":"username","def":"UNIQUE KEY username (username) USING BTREE","table":"users","columns":["username"]}],"constraints":[{"name":"email","type":"UNIQUE","def":"UNIQUE KEY email (email)","table":"users","columns":["email"]},{"name":"PRIMARY","type":"PRIMARY KEY","def":"PRIMARY KEY (id)","table":"users","columns":["id"]},{"name":"username","type":"UNIQUE","def":"UNIQUE KEY username (username)","table":"users","columns":["username"]},{"name":"users_chk_1","type":"CHECK","def":"CHECK ((char_length(`username`) \u003e 4))","table":"users","columns":null}],"def":"CREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL,\n `updated` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`),\n CONSTRAINT `users_chk_1` CHECK ((char_length(`username`) \u003e 4))\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Users table'","labels":[{"name":"user","virtual":true}]}],"relations":[{"table":"comment_stars","columns":["comment_user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_user_id) REFERENCES users (id)"},{"table":"comment_stars","columns":["comment_post_id","comment_user_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["post_id","user_id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"},{"table":"comments","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (post_id) REFERENCES posts (id)"},{"table":"comments","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"posts","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"user_options","columns":["user_id"],"cardinality":"zero_or_one","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"FOREIGN KEY (user_id) REFERENCES users (id)"},{"table":"logs","columns":["user_id"],"cardinality":"zero_or_more","parent_table":"users","parent_columns":["id"],"parent_cardinality":"exactly_one","def":"logs-\u003eusers","virtual":true},{"table":"logs","columns":["post_id"],"cardinality":"zero_or_more","parent_table":"posts","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_id"],"cardinality":"zero_or_more","parent_table":"comments","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true},{"table":"logs","columns":["comment_star_id"],"cardinality":"zero_or_more","parent_table":"comment_stars","parent_columns":["id"],"parent_cardinality":"zero_or_one","def":"Additional Relation","virtual":true}],"functions":[{"name":"CustomerLevel","return_type":"varchar","arguments":"credit decimal","type":"FUNCTION"},{"name":"GetAllComments","return_type":"","arguments":"","type":"PROCEDURE"}],"driver":{"name":"mysql","database_version":"8.4.4","meta":{"dict":{"Functions":"Stored procedures and functions"}}},"labels":[{"name":"sample","virtual":true},{"name":"tbls","virtual":true}],"viewpoints":[{"name":"Content","desc":"Content as an asset for blogging services","labels":["content"]},{"name":"Ops","desc":"Tables to be referenced during operation","tables":["logs","users","posts"]},{"name":"Around the users table","desc":"Tables related to the users table","tables":["users"],"distance":1,"groups":[{"name":"Content","desc":"Content as an asset for blogging services","labels":["content"]}]},{"name":"Secure data","desc":"Tables with secure data","labels":["secure"]}]} diff --git a/schema/json.go b/schema/json.go index 48bce268..dccca499 100644 --- a/schema/json.go +++ b/schema/json.go @@ -36,7 +36,7 @@ type ColumnJSON struct { Name string `json:"name"` Type string `json:"type"` Nullable bool `json:"nullable"` - Default *string `json:"default,omitempty"` + Default *string `json:"default,omitempty" jsonschema:"anyof_type=string;null"` ExtraDef string `json:"extra_def,omitempty"` Labels Labels `json:"labels,omitempty"` Comment string `json:"comment,omitempty"` @@ -46,10 +46,10 @@ type ColumnJSON struct { type RelationJSON struct { Table string `json:"table"` Columns []string `json:"columns"` - Cardinality string `json:"cardinality,omitempty"` + Cardinality string `json:"cardinality,omitempty" jsonschema:"enum=zero_or_one,enum=exactly_one,enum=zero_or_more,enum=one_or_more,enum="` ParentTable string `json:"parent_table"` ParentColumns []string `json:"parent_columns"` - ParentCardinality string `json:"parent_cardinality,omitempty"` + ParentCardinality string `json:"parent_cardinality,omitempty" jsonschema:"enum=zero_or_one,enum=exactly_one,enum=zero_or_more,enum=one_or_more,enum="` Def string `json:"def"` Virtual bool `json:"virtual,omitempty"` } diff --git a/scripts/jsonschema/main.go b/scripts/jsonschema/main.go index a84c11b9..ac3b4106 100644 --- a/scripts/jsonschema/main.go +++ b/scripts/jsonschema/main.go @@ -4,6 +4,8 @@ import ( "encoding/json" "fmt" "os" + "reflect" + "strings" "github.com/iancoleman/strcase" "github.com/invopop/jsonschema" @@ -19,6 +21,9 @@ func main() { func _main() error { r := new(jsonschema.Reflector) + r.Namer = func(t reflect.Type) string { + return strings.TrimSuffix(t.Name(), "JSON") + } r.KeyNamer = strcase.ToSnake s := r.Reflect(&schema.SchemaJSON{}) b, err := json.MarshalIndent(s, "", " ") diff --git a/testdata/json_output_schema.golden b/testdata/json_output_schema.golden index 98a54973..fbe17658 100644 --- a/testdata/json_output_schema.golden +++ b/testdata/json_output_schema.golden @@ -107,12 +107,12 @@ "columns": [ "b" ], - "cardinality": "One or more", + "cardinality": "one_or_more", "parent_table": "a", "parent_columns": [ "a" ], - "parent_cardinality": "Exactly one", + "parent_cardinality": "exactly_one", "def": "FOREIGN KEY (b) REFERENCES a(a)" } ], diff --git a/testdata/modify_schema_.golden b/testdata/modify_schema_.golden index 0398b70b..c9448bae 100644 --- a/testdata/modify_schema_.golden +++ b/testdata/modify_schema_.golden @@ -297,12 +297,12 @@ "columns": [ "category_id" ], - "cardinality": "Zero or more", + "cardinality": "zero_or_more", "parent_table": "categories", "parent_columns": [ "id" ], - "parent_cardinality": "Exactly one", + "parent_cardinality": "exactly_one", "def": "FOREIGN KEY (category_id) REFERENCES categories (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" }, { @@ -310,12 +310,12 @@ "columns": [ "user_id" ], - "cardinality": "Zero or more", + "cardinality": "zero_or_more", "parent_table": "users", "parent_columns": [ "id" ], - "parent_cardinality": "Exactly one", + "parent_cardinality": "exactly_one", "def": "FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" }, { @@ -323,12 +323,12 @@ "columns": [ "user_id" ], - "cardinality": "Zero or more", + "cardinality": "zero_or_more", "parent_table": "users", "parent_columns": [ "id" ], - "parent_cardinality": "Exactly one", + "parent_cardinality": "exactly_one", "def": "FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" } ], diff --git a/testdata/modify_schema_mod_name_and_desc.golden b/testdata/modify_schema_mod_name_and_desc.golden index 174285c0..2cacef09 100644 --- a/testdata/modify_schema_mod_name_and_desc.golden +++ b/testdata/modify_schema_mod_name_and_desc.golden @@ -298,12 +298,12 @@ "columns": [ "category_id" ], - "cardinality": "Zero or more", + "cardinality": "zero_or_more", "parent_table": "categories", "parent_columns": [ "id" ], - "parent_cardinality": "Exactly one", + "parent_cardinality": "exactly_one", "def": "FOREIGN KEY (category_id) REFERENCES categories (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" }, { @@ -311,12 +311,12 @@ "columns": [ "user_id" ], - "cardinality": "Zero or more", + "cardinality": "zero_or_more", "parent_table": "users", "parent_columns": [ "id" ], - "parent_cardinality": "Exactly one", + "parent_cardinality": "exactly_one", "def": "FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" }, { @@ -324,12 +324,12 @@ "columns": [ "user_id" ], - "cardinality": "Zero or more", + "cardinality": "zero_or_more", "parent_table": "users", "parent_columns": [ "id" ], - "parent_cardinality": "Exactly one", + "parent_cardinality": "exactly_one", "def": "FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" } ], diff --git a/testdata/modify_schema_not_override.golden b/testdata/modify_schema_not_override.golden index 6d647249..599a5b39 100644 --- a/testdata/modify_schema_not_override.golden +++ b/testdata/modify_schema_not_override.golden @@ -297,12 +297,12 @@ "columns": [ "category_id" ], - "cardinality": "Zero or more", + "cardinality": "zero_or_more", "parent_table": "categories", "parent_columns": [ "id" ], - "parent_cardinality": "Exactly one", + "parent_cardinality": "exactly_one", "def": "FOREIGN KEY (category_id) REFERENCES categories (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" }, { @@ -310,12 +310,12 @@ "columns": [ "user_id" ], - "cardinality": "Zero or more", + "cardinality": "zero_or_more", "parent_table": "users", "parent_columns": [ "id" ], - "parent_cardinality": "Exactly one", + "parent_cardinality": "exactly_one", "def": "FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" }, { @@ -323,12 +323,12 @@ "columns": [ "user_id" ], - "cardinality": "Zero or more", + "cardinality": "zero_or_more", "parent_table": "users", "parent_columns": [ "id" ], - "parent_cardinality": "Exactly one", + "parent_cardinality": "exactly_one", "def": "FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" }, { @@ -336,12 +336,12 @@ "columns": [ "id" ], - "cardinality": "Zero or one", + "cardinality": "zero_or_one", "parent_table": "posts", "parent_columns": [ "user_id" ], - "parent_cardinality": "Exactly one", + "parent_cardinality": "exactly_one", "def": "Additional Relation", "virtual": true } diff --git a/testdata/modify_schema_override.golden b/testdata/modify_schema_override.golden index a885aba3..0c38a2b7 100644 --- a/testdata/modify_schema_override.golden +++ b/testdata/modify_schema_override.golden @@ -297,12 +297,12 @@ "columns": [ "category_id" ], - "cardinality": "Zero or more", + "cardinality": "zero_or_more", "parent_table": "categories", "parent_columns": [ "id" ], - "parent_cardinality": "Exactly one", + "parent_cardinality": "exactly_one", "def": "FOREIGN KEY (category_id) REFERENCES categories (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" }, { @@ -310,12 +310,12 @@ "columns": [ "user_id" ], - "cardinality": "Zero or one", + "cardinality": "zero_or_one", "parent_table": "users", "parent_columns": [ "id" ], - "parent_cardinality": "One or more", + "parent_cardinality": "one_or_more", "def": "Override Relation", "virtual": true }, @@ -324,12 +324,12 @@ "columns": [ "user_id" ], - "cardinality": "Zero or more", + "cardinality": "zero_or_more", "parent_table": "users", "parent_columns": [ "id" ], - "parent_cardinality": "Exactly one", + "parent_cardinality": "exactly_one", "def": "FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" } ], diff --git a/testdata/modify_schema_relations.golden b/testdata/modify_schema_relations.golden index 3d086fe7..c6f436c6 100644 --- a/testdata/modify_schema_relations.golden +++ b/testdata/modify_schema_relations.golden @@ -297,12 +297,12 @@ "columns": [ "category_id" ], - "cardinality": "Zero or more", + "cardinality": "zero_or_more", "parent_table": "categories", "parent_columns": [ "id" ], - "parent_cardinality": "Exactly one", + "parent_cardinality": "exactly_one", "def": "FOREIGN KEY (category_id) REFERENCES categories (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" }, { @@ -310,12 +310,12 @@ "columns": [ "user_id" ], - "cardinality": "Zero or more", + "cardinality": "zero_or_more", "parent_table": "users", "parent_columns": [ "id" ], - "parent_cardinality": "Exactly one", + "parent_cardinality": "exactly_one", "def": "FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" }, { @@ -323,12 +323,12 @@ "columns": [ "user_id" ], - "cardinality": "Zero or more", + "cardinality": "zero_or_more", "parent_table": "users", "parent_columns": [ "id" ], - "parent_cardinality": "Exactly one", + "parent_cardinality": "exactly_one", "def": "FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE" }, { @@ -336,12 +336,12 @@ "columns": [ "id" ], - "cardinality": "Zero or one", + "cardinality": "zero_or_one", "parent_table": "categories", "parent_columns": [ "id" ], - "parent_cardinality": "Exactly one", + "parent_cardinality": "exactly_one", "def": "Additional Relation", "virtual": true } diff --git a/testdata/yaml_output_schema.golden b/testdata/yaml_output_schema.golden index 2623a4e0..96d42340 100644 --- a/testdata/yaml_output_schema.golden +++ b/testdata/yaml_output_schema.golden @@ -63,11 +63,11 @@ relations: - table: b columns: - b - cardinality: One or more + cardinality: one_or_more parentTable: a parentColumns: - a - parentCardinality: Exactly one + parentCardinality: exactly_one def: FOREIGN KEY (b) REFERENCES a(a) virtual: false enums: From 1880e629b79f72740488011b4f621420a63bd0fc Mon Sep 17 00:00:00 2001 From: k1LoW Date: Sat, 25 Jan 2025 16:15:46 +0900 Subject: [PATCH 12/13] fix: Add JSON Schema --- Makefile | 8 +- scripts/jsonschema/main.go | 2 + spec/schema_schema.json | 479 +++++++++++++++++++++++++++++++++++++ 3 files changed, 488 insertions(+), 1 deletion(-) create mode 100644 spec/schema_schema.json diff --git a/Makefile b/Makefile index 34ff0b5a..14d47f06 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ TBLS ?= ./tbls default: test -ci: depsdev build db test testdoc testdoc_hide_auto_increment test_too_many_tables test_json test_ext_subcommand doc +ci: depsdev build db test testdoc testdoc_hide_auto_increment test_too_many_tables test_json test_ext_subcommand test_jsonschema doc ci_windows: depsdev build db_sqlite testdoc_sqlite @@ -147,6 +147,12 @@ test_ext_subcommand: build env PATH="${PWD}/testdata/bin:${PATH}" TBLS_DSN=pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable $(TBLS) echo | grep 'TBLS_DSN=pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable' > /dev/null echo hello | env PATH="${PWD}/testdata/bin:${PATH}" $(TBLS) echo -c ./testdata/ext_subcommand_tbls.yml | grep 'STDIN=hello' > /dev/null +test_jsonschema: + cd scripts/jsonschema && go run main.go | diff -u ../../spec/schema_schema.json - + +generate_jsonschema: + cd scripts/jsonschema && go run main.go > ../../spec/schema_schema.json + generate_test_json: build sqlite3 $(PWD)/filter_tables.sqlite3 < testdata/ddl/filter_tables.sql $(TBLS) out sq://$(PWD)/filter_tables.sqlite3 -t json > testdata/filter_tables.json diff --git a/scripts/jsonschema/main.go b/scripts/jsonschema/main.go index ac3b4106..c60baaaf 100644 --- a/scripts/jsonschema/main.go +++ b/scripts/jsonschema/main.go @@ -12,6 +12,7 @@ import ( "github.com/k1LoW/tbls/schema" ) +// Generate JSON Schema of schema.json. func main() { if err := _main(); err != nil { fmt.Println(err) @@ -31,5 +32,6 @@ func _main() error { return err } fmt.Println(string(b)) + fmt.Println() return nil } diff --git a/spec/schema_schema.json b/spec/schema_schema.json new file mode 100644 index 00000000..c2a16923 --- /dev/null +++ b/spec/schema_schema.json @@ -0,0 +1,479 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/k1LoW/tbls/schema/schema", + "$ref": "#/$defs/Schema", + "$defs": { + "Column": { + "properties": { + "name": { + "type": "string" + }, + "type": { + "type": "string" + }, + "nullable": { + "type": "boolean" + }, + "default": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + }, + "extra_def": { + "type": "string" + }, + "labels": { + "$ref": "#/$defs/Labels" + }, + "comment": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "name", + "type", + "nullable" + ] + }, + "Constraint": { + "properties": { + "name": { + "type": "string" + }, + "type": { + "type": "string" + }, + "def": { + "type": "string" + }, + "table": { + "type": "string" + }, + "referenced_table": { + "type": "string" + }, + "columns": { + "items": { + "type": "string" + }, + "type": "array" + }, + "referenced_columns": { + "items": { + "type": "string" + }, + "type": "array" + }, + "comment": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "name", + "type", + "def", + "table", + "columns" + ] + }, + "Dict": { + "properties": {}, + "additionalProperties": false, + "type": "object" + }, + "Driver": { + "properties": { + "name": { + "type": "string" + }, + "database_version": { + "type": "string" + }, + "meta": { + "$ref": "#/$defs/DriverMeta" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "name" + ] + }, + "DriverMeta": { + "properties": { + "current_schema": { + "type": "string" + }, + "search_paths": { + "items": { + "type": "string" + }, + "type": "array" + }, + "dict": { + "$ref": "#/$defs/Dict" + } + }, + "additionalProperties": false, + "type": "object" + }, + "Enum": { + "properties": { + "name": { + "type": "string" + }, + "values": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "name", + "values" + ] + }, + "Function": { + "properties": { + "name": { + "type": "string" + }, + "return_type": { + "type": "string" + }, + "arguments": { + "type": "string" + }, + "type": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "name", + "return_type", + "arguments", + "type" + ] + }, + "Index": { + "properties": { + "name": { + "type": "string" + }, + "def": { + "type": "string" + }, + "table": { + "type": "string" + }, + "columns": { + "items": { + "type": "string" + }, + "type": "array" + }, + "comment": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "name", + "def", + "table", + "columns" + ] + }, + "Label": { + "properties": { + "name": { + "type": "string" + }, + "virtual": { + "type": "boolean" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "name" + ] + }, + "Labels": { + "items": { + "$ref": "#/$defs/Label" + }, + "type": "array" + }, + "Relation": { + "properties": { + "table": { + "type": "string" + }, + "columns": { + "items": { + "type": "string" + }, + "type": "array" + }, + "cardinality": { + "type": "string", + "enum": [ + "zero_or_one", + "exactly_one", + "zero_or_more", + "one_or_more", + "" + ] + }, + "parent_table": { + "type": "string" + }, + "parent_columns": { + "items": { + "type": "string" + }, + "type": "array" + }, + "parent_cardinality": { + "type": "string", + "enum": [ + "zero_or_one", + "exactly_one", + "zero_or_more", + "one_or_more", + "" + ] + }, + "def": { + "type": "string" + }, + "virtual": { + "type": "boolean" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "table", + "columns", + "parent_table", + "parent_columns", + "def" + ] + }, + "Schema": { + "properties": { + "name": { + "type": "string" + }, + "desc": { + "type": "string" + }, + "tables": { + "items": { + "$ref": "#/$defs/Table" + }, + "type": "array" + }, + "relations": { + "items": { + "$ref": "#/$defs/Relation" + }, + "type": "array" + }, + "functions": { + "items": { + "$ref": "#/$defs/Function" + }, + "type": "array" + }, + "enums": { + "items": { + "$ref": "#/$defs/Enum" + }, + "type": "array" + }, + "driver": { + "$ref": "#/$defs/Driver" + }, + "labels": { + "$ref": "#/$defs/Labels" + }, + "viewpoints": { + "$ref": "#/$defs/Viewpoints" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "tables" + ] + }, + "Table": { + "properties": { + "name": { + "type": "string" + }, + "type": { + "type": "string" + }, + "comment": { + "type": "string" + }, + "columns": { + "items": { + "$ref": "#/$defs/Column" + }, + "type": "array" + }, + "indexes": { + "items": { + "$ref": "#/$defs/Index" + }, + "type": "array" + }, + "constraints": { + "items": { + "$ref": "#/$defs/Constraint" + }, + "type": "array" + }, + "triggers": { + "items": { + "$ref": "#/$defs/Trigger" + }, + "type": "array" + }, + "def": { + "type": "string" + }, + "labels": { + "$ref": "#/$defs/Labels" + }, + "referenced_tables": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "name", + "type", + "columns" + ] + }, + "Trigger": { + "properties": { + "name": { + "type": "string" + }, + "def": { + "type": "string" + }, + "comment": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "name", + "def" + ] + }, + "Viewpoint": { + "properties": { + "name": { + "type": "string" + }, + "desc": { + "type": "string" + }, + "labels": { + "items": { + "type": "string" + }, + "type": "array" + }, + "tables": { + "items": { + "type": "string" + }, + "type": "array" + }, + "distance": { + "type": "integer" + }, + "groups": { + "items": { + "$ref": "#/$defs/ViewpointGroup" + }, + "type": "array" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "name", + "desc" + ] + }, + "ViewpointGroup": { + "properties": { + "name": { + "type": "string" + }, + "desc": { + "type": "string" + }, + "labels": { + "items": { + "type": "string" + }, + "type": "array" + }, + "tables": { + "items": { + "type": "string" + }, + "type": "array" + }, + "color": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "name", + "desc" + ] + }, + "Viewpoints": { + "items": { + "$ref": "#/$defs/Viewpoint" + }, + "type": "array" + } + } +} + From e0d1148072e46ba53ca6dd98af3c1f3b6e40f1e6 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Sun, 26 Jan 2025 10:02:39 +0900 Subject: [PATCH 13/13] fix: Rename json --- Makefile | 4 ++-- spec/{schema_schema.json => tbls.schema.json_schema.json} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename spec/{schema_schema.json => tbls.schema.json_schema.json} (100%) diff --git a/Makefile b/Makefile index 14d47f06..b8bb306e 100644 --- a/Makefile +++ b/Makefile @@ -148,10 +148,10 @@ test_ext_subcommand: build echo hello | env PATH="${PWD}/testdata/bin:${PATH}" $(TBLS) echo -c ./testdata/ext_subcommand_tbls.yml | grep 'STDIN=hello' > /dev/null test_jsonschema: - cd scripts/jsonschema && go run main.go | diff -u ../../spec/schema_schema.json - + cd scripts/jsonschema && go run main.go | diff -u ../../spec/tbls.schema.json_schema.json - generate_jsonschema: - cd scripts/jsonschema && go run main.go > ../../spec/schema_schema.json + cd scripts/jsonschema && go run main.go > ../../spec/tbls.schema.json_schema.json generate_test_json: build sqlite3 $(PWD)/filter_tables.sqlite3 < testdata/ddl/filter_tables.sql diff --git a/spec/schema_schema.json b/spec/tbls.schema.json_schema.json similarity index 100% rename from spec/schema_schema.json rename to spec/tbls.schema.json_schema.json