Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: parse to metadata write to user comment (#12086)
h3n4ld70c6f5b63ff
diff --git a/backend/plugin/schema/mysql/state.go b/backend/plugin/schema/mysql/state.goindex 4dc3493b68..e52c2544ec 100644--- a/backend/plugin/schema/mysql/state.go+++ b/backend/plugin/schema/mysql/state.go@@ -345,6 +345,7 @@ func (t *tableState) convertToTableMetadata() *storepb.TableMetadata {Columns: columns,Indexes: indexes,ForeignKeys: fks,+ UserComment: t.comment,Comment: t.comment,Engine: t.engine,Collation: t.collation,@@ -1352,11 +1353,12 @@ func (c *columnState) toString(buf io.StringWriter) error {func (c *columnState) convertToColumnMetadata() *storepb.ColumnMetadata {result := &storepb.ColumnMetadata{- Name: c.name,- Type: c.tp,- Nullable: c.nullable,- OnUpdate: c.onUpdate,- Comment: c.comment,+ Name: c.name,+ Type: c.tp,+ Nullable: c.nullable,+ OnUpdate: c.onUpdate,+ Comment: c.comment,+ UserComment: c.comment,}if c.defaultValue != nil {switch value := c.defaultValue.(type) {diff --git a/backend/plugin/schema/mysql/testdata/parse-to-metadata/standard.yaml b/backend/plugin/schema/mysql/testdata/parse-to-metadata/standard.yamlindex 3a54028164..566a655eaf 100644--- a/backend/plugin/schema/mysql/testdata/parse-to-metadata/standard.yaml+++ b/backend/plugin/schema/mysql/testdata/parse-to-metadata/standard.yaml@@ -29,7 +29,8 @@"name": "a","position": 1,"type": "int",- "comment": "this is comment"+ "comment": "this is comment",+ "userComment": "this is comment"},{"name": "b",@@ -164,7 +165,8 @@],"engine": "InnoDB","collation": "utf8mb4_0900_ai_ci",- "comment": "this is comment with ' escaped"+ "comment": "this is comment with ' escaped",+ "userComment": "this is comment with ' escaped"}]}@@ -201,7 +203,8 @@"defaultExpression": "1","nullable": true,"type": "int",- "comment": "abcdefg"+ "comment": "abcdefg",+ "userComment": "abcdefg"},{"name": "b",@@ -228,6 +231,7 @@}],"comment": "this is comment with ' escaped",+ "userComment": "this is comment with ' escaped","foreignKeys": [{"name": "fk1",@@ -269,4 +273,4 @@]}]- }\ No newline at end of file+ }diff --git a/backend/plugin/schema/mysql/testdata/parse-to-metadata/view.yaml b/backend/plugin/schema/mysql/testdata/parse-to-metadata/view.yamlindex 1fdf0ca82c..ea9fa93a99 100644--- a/backend/plugin/schema/mysql/testdata/parse-to-metadata/view.yaml+++ b/backend/plugin/schema/mysql/testdata/parse-to-metadata/view.yaml@@ -1,12 +1,12 @@- schema: CREATE VIEW v1 AS select 1 AS `id`;metadata: |-{- "schemas": [+ "schemas": [{- "views": [+ "views": [{- "name": "v1",- "definition": "select 1 AS `id`"+ "name": "v1",+ "definition": "select 1 AS `id`"}]}@@ -15,12 +15,12 @@- schema: CREATE VIEW v1 AS select * from t;metadata: |-{- "schemas": [+ "schemas": [{- "views": [+ "views": [{- "name": "v1",- "definition": "select * from t"+ "name": "v1",+ "definition": "select * from t"}]}diff --git a/backend/plugin/schema/oracle/state.go b/backend/plugin/schema/oracle/state.goindex ebb716cdb3..9a13ff26e7 100644--- a/backend/plugin/schema/oracle/state.go+++ b/backend/plugin/schema/oracle/state.go@@ -225,10 +225,11 @@ func (t *tableState) convertToTableMetadata() *storepb.TableMetadata {}return &storepb.TableMetadata{- Name: t.name,- Columns: columns,- Indexes: indexes,- Comment: t.comment,+ Name: t.name,+ Columns: columns,+ Indexes: indexes,+ Comment: t.comment,+ UserComment: t.comment,}}@@ -306,10 +307,11 @@ func (c *columnState) toString(buf *strings.Builder) error {func (c *columnState) convertToColumnMetadata() *storepb.ColumnMetadata {result := &storepb.ColumnMetadata{- Name: c.name,- Type: c.tp,- Nullable: c.nullable,- Comment: c.comment,+ Name: c.name,+ Type: c.tp,+ Nullable: c.nullable,+ Comment: c.comment,+ UserComment: c.comment,}if c.defaultValue != nil {switch value := c.defaultValue.(type) {diff --git a/backend/plugin/schema/pg/parse_to_metadata.go b/backend/plugin/schema/pg/parse_to_metadata.goindex 8a9b8e4aab..273a28dab3 100644--- a/backend/plugin/schema/pg/parse_to_metadata.go+++ b/backend/plugin/schema/pg/parse_to_metadata.go@@ -490,6 +490,7 @@ func (t *tableState) convertToTableMetadata() *storepb.TableMetadata {Indexes: indexes,ForeignKeys: fks,Comment: t.comment,+ UserComment: t.comment,}}@@ -739,10 +740,11 @@ func (c *columnState) toString(buf *strings.Builder) error {func (c *columnState) convertToColumnMetadata() *storepb.ColumnMetadata {result := &storepb.ColumnMetadata{- Name: c.name,- Type: c.tp,- Nullable: c.nullable,- Comment: c.comment,+ Name: c.name,+ Type: c.tp,+ Nullable: c.nullable,+ Comment: c.comment,+ UserComment: c.comment,}if c.hasDefault {switch value := c.defaultValue.(type) {diff --git a/backend/plugin/schema/pg/testdata/parse_to_metadata.yaml b/backend/plugin/schema/pg/testdata/parse_to_metadata.yamlindex 394bba5dfd..342be216f5 100644--- a/backend/plugin/schema/pg/testdata/parse_to_metadata.yaml+++ b/backend/plugin/schema/pg/testdata/parse_to_metadata.yaml@@ -12,83 +12,84 @@CREATE INDEX idx_t_c ON public.t USING btree (c);metadata: |-{- "schemas": [+ "schemas": [{- "name": "public",- "tables": [+ "name": "public",+ "tables": [{- "name": "t",- "columns": [+ "name": "t",+ "columns": [{- "name": "c",- "nullable": true,- "type": "integer"+ "name": "c",+ "nullable": true,+ "type": "integer"},{- "name": "a",- "defaultExpression": "1",- "nullable": true,- "type": "integer",- "comment": "this is a comment"+ "name": "a",+ "defaultExpression": "1",+ "nullable": true,+ "type": "integer",+ "comment": "this is a comment",+ "userComment": "this is a comment"},{- "name": "b",- "defaultExpression": "'NULL'",- "nullable": true,- "type": "character varying(20)"+ "name": "b",+ "defaultExpression": "'NULL'",+ "nullable": true,+ "type": "character varying(20)"}],- "indexes": [+ "indexes": [{- "name": "t_pk",- "expressions": [+ "name": "t_pk",+ "expressions": ["a","b"],- "unique": true,- "primary": true,- "visible": true+ "unique": true,+ "primary": true,+ "visible": true},{- "name": "idx_t_c",- "expressions": [+ "name": "idx_t_c",+ "expressions": ["c"],- "visible": true,- "definition": "CREATE INDEX idx_t_c ON public.t USING btree (c);"+ "visible": true,+ "definition": "CREATE INDEX idx_t_c ON public.t USING btree (c);"}],- "foreignKeys": [+ "foreignKeys": [{- "name": "t_fk1",- "columns": [+ "name": "t_fk1",+ "columns": ["a"],- "referencedTable": "t2",- "referencedColumns": [+ "referencedTable": "t2",+ "referencedColumns": ["b"]}]},{- "name": "t2",- "columns": [+ "name": "t2",+ "columns": [{- "name": "b",- "defaultExpression": "NULL",- "type": "integer"+ "name": "b",+ "defaultExpression": "NULL",+ "type": "integer"}],- "indexes": [+ "indexes": [{- "name": "t2_pk",- "expressions": [+ "name": "t2_pk",+ "expressions": ["b"],- "unique": true,- "primary": true,- "visible": true+ "unique": true,+ "primary": true,+ "visible": true}]}diff --git a/backend/plugin/schema/tidb/state.go b/backend/plugin/schema/tidb/state.goindex 3d94c1f86a..c8994b9630 100644--- a/backend/plugin/schema/tidb/state.go+++ b/backend/plugin/schema/tidb/state.go@@ -279,6 +279,7 @@ func (t *tableState) convertToTableMetadata() *storepb.TableMetadata {Columns: columns,Indexes: indexes,ForeignKeys: fks,+ UserComment: t.comment,Comment: t.comment,Engine: t.engine,Collation: t.collation,@@ -546,11 +547,12 @@ func (c *columnState) toString(buf *strings.Builder) error {func (c *columnState) convertToColumnMetadata() *storepb.ColumnMetadata {result := &storepb.ColumnMetadata{- Name: c.name,- Type: c.tp,- Nullable: c.nullable,- OnUpdate: c.onUpdate,- Comment: c.comment,+ Name: c.name,+ Type: c.tp,+ Nullable: c.nullable,+ OnUpdate: c.onUpdate,+ Comment: c.comment,+ UserComment: c.comment,}if c.defaultValue != nil {switch value := c.defaultValue.(type) {diff --git a/backend/plugin/schema/tidb/testdata/parse_to_metadata.yaml b/backend/plugin/schema/tidb/testdata/parse_to_metadata.yamlindex c1941afd14..55958f4bb5 100644--- a/backend/plugin/schema/tidb/testdata/parse_to_metadata.yaml+++ b/backend/plugin/schema/tidb/testdata/parse_to_metadata.yaml@@ -13,87 +13,89 @@) ENGINE=InnoDB DEFAULT COLLATE=utf8mb4_bin COMMENT 'this is comment with '' escaped';metadata: |-{- "schemas": [+ "schemas": [{- "tables": [+ "tables": [{- "name": "t",- "columns": [+ "name": "t",+ "columns": [{- "name": "a",- "position": 1,- "type": "int(11)",- "comment": "this is comment"+ "name": "a",+ "position": 1,+ "type": "int(11)",+ "comment": "this is comment",+ "userComment": "this is comment"},{- "name": "b",- "position": 2,- "type": "varchar(20)"+ "name": "b",+ "position": 2,+ "type": "varchar(20)"},{- "name": "c",- "position": 3,- "defaultExpression": "CURRENT_TIMESTAMP(3)",- "onUpdate": "CURRENT_TIMESTAMP(3)",- "type": "timestamp(3)"+ "name": "c",+ "position": 3,+ "defaultExpression": "CURRENT_TIMESTAMP(3)",+ "onUpdate": "CURRENT_TIMESTAMP(3)",+ "type": "timestamp(3)"},{- "name": "d",- "position": 4,- "defaultExpression": "CURRENT_TIMESTAMP",- "onUpdate": "CURRENT_TIMESTAMP",- "type": "datetime"+ "name": "d",+ "position": 4,+ "defaultExpression": "CURRENT_TIMESTAMP",+ "onUpdate": "CURRENT_TIMESTAMP",+ "type": "datetime"},{- "name": "e",- "position": 5,- "defaultExpression": "CURRENT_TIMESTAMP",- "onUpdate": "CURRENT_TIMESTAMP",- "type": "datetime"+ "name": "e",+ "position": 5,+ "defaultExpression": "CURRENT_TIMESTAMP",+ "onUpdate": "CURRENT_TIMESTAMP",+ "type": "datetime"}],- "indexes": [+ "indexes": [{- "name": "idx",- "expressions": [+ "name": "idx",+ "expressions": ["((`a`+20))"],- "visible": true+ "visible": true},{- "name": "idx2",- "expressions": [+ "name": "idx2",+ "expressions": ["a"],- "keyLength": [+ "keyLength": ["-1"],- "unique": true,- "visible": true+ "unique": true,+ "visible": true},{- "name": "idx_length",- "expressions": [+ "name": "idx_length",+ "expressions": ["b"],- "keyLength": [+ "keyLength": ["10"],- "visible": true+ "visible": true},{- "name": "PRIMARY",- "expressions": [+ "name": "PRIMARY",+ "expressions": ["a"],- "unique": true,- "primary": true,- "visible": true+ "unique": true,+ "primary": true,+ "visible": true}],- "engine": "InnoDB",- "collation": "utf8mb4_bin",- "comment": "this is comment with ' escaped"+ "engine": "InnoDB",+ "collation": "utf8mb4_bin",+ "comment": "this is comment with ' escaped",+ "userComment": "this is comment with ' escaped"}]}@@ -122,192 +124,193 @@create table t5(a bigint NOT NULL /*T![auto_rand] AUTO_RANDOM(6, 54) */, primary key (a));metadata: |-{- "schemas": [+ "schemas": [{- "tables": [+ "tables": [{- "name": "t",- "columns": [+ "name": "t",+ "columns": [{- "name": "c",- "position": 1,- "nullable": true,- "type": "int(11)"+ "name": "c",+ "position": 1,+ "nullable": true,+ "type": "int(11)"},{- "name": "a",- "position": 2,- "defaultExpression": "1",- "nullable": true,- "type": "int(11)",- "comment": "abcdefg"+ "name": "a",+ "position": 2,+ "defaultExpression": "1",+ "nullable": true,+ "type": "int(11)",+ "comment": "abcdefg",+ "userComment": "abcdefg"},{- "name": "b",- "position": 3,- "defaultNull": true,- "nullable": true,- "type": "varchar(20)"+ "name": "b",+ "position": 3,+ "defaultNull": true,+ "nullable": true,+ "type": "varchar(20)"},{- "name": "d",- "position": 4,- "nullable": true,- "type": "varbinary(500)"+ "name": "d",+ "position": 4,+ "nullable": true,+ "type": "varbinary(500)"},{- "name": "e",- "position": 5,- "nullable": true,- "type": "binary(20)"+ "name": "e",+ "position": 5,+ "nullable": true,+ "type": "binary(20)"},{- "name": "f",- "position": 6,- "nullable": true,- "type": "blob"+ "name": "f",+ "position": 6,+ "nullable": true,+ "type": "blob"},{- "name": "g",- "position": 7,- "nullable": true,- "type": "tinyblob"+ "name": "g",+ "position": 7,+ "nullable": true,+ "type": "tinyblob"},{- "name": "h",- "position": 8,- "nullable": true,- "type": "mediumblob"+ "name": "h",+ "position": 8,+ "nullable": true,+ "type": "mediumblob"},{- "name": "i",- "position": 9,- "nullable": true,- "type": "longblob"+ "name": "i",+ "position": 9,+ "nullable": true,+ "type": "longblob"},{- "name": "j",- "position": 10,- "nullable": true,- "type": "text"+ "name": "j",+ "position": 10,+ "nullable": true,+ "type": "text"},{- "name": "k",- "position": 11,- "nullable": true,- "type": "tinytext"+ "name": "k",+ "position": 11,+ "nullable": true,+ "type": "tinytext"}],- "indexes": [+ "indexes": [{- "name": "PRIMARY",- "expressions": [+ "name": "PRIMARY",+ "expressions": ["a","b"],- "unique": true,- "primary": true,- "visible": true+ "unique": true,+ "primary": true,+ "visible": true}],- "foreignKeys": [+ "foreignKeys": [{- "name": "fk1",- "columns": [+ "name": "fk1",+ "columns": ["a"],- "referencedTable": "t2",- "referencedColumns": [+ "referencedTable": "t2",+ "referencedColumns": ["b"]}]},{- "name": "t2",- "columns": [+ "name": "t2",+ "columns": [{- "name": "b",- "position": 1,- "defaultNull": true,- "type": "int(11)"+ "name": "b",+ "position": 1,+ "defaultNull": true,+ "type": "int(11)"}],- "indexes": [+ "indexes": [{- "name": "PRIMARY",- "expressions": [+ "name": "PRIMARY",+ "expressions": ["b"],- "unique": true,- "primary": true,- "visible": true+ "unique": true,+ "primary": true,+ "visible": true}]},{- "name": "t3",- "columns": [+ "name": "t3",+ "columns": [{- "name": "a",- "position": 1,- "defaultExpression": "AUTO_RANDOM",- "type": "bigint(20)"+ "name": "a",+ "position": 1,+ "defaultExpression": "AUTO_RANDOM",+ "type": "bigint(20)"}],- "indexes": [+ "indexes": [{- "name": "PRIMARY",- "expressions": [+ "name": "PRIMARY",+ "expressions": ["a"],- "unique": true,- "primary": true,- "visible": true+ "unique": true,+ "primary": true,+ "visible": true}]},{- "name": "t4",- "columns": [+ "name": "t4",+ "columns": [{- "name": "a",- "position": 1,- "defaultExpression": "AUTO_RANDOM(6)",- "type": "bigint(20)"+ "name": "a",+ "position": 1,+ "defaultExpression": "AUTO_RANDOM(6)",+ "type": "bigint(20)"}],- "indexes": [+ "indexes": [{- "name": "PRIMARY",- "expressions": [+ "name": "PRIMARY",+ "expressions": ["a"],- "unique": true,- "primary": true,- "visible": true+ "unique": true,+ "primary": true,+ "visible": true}]},{- "name": "t5",- "columns": [+ "name": "t5",+ "columns": [{- "name": "a",- "position": 1,- "defaultExpression": "AUTO_RANDOM(6, 54)",- "type": "bigint(20)"+ "name": "a",+ "position": 1,+ "defaultExpression": "AUTO_RANDOM(6, 54)",+ "type": "bigint(20)"}],- "indexes": [+ "indexes": [{- "name": "PRIMARY",- "expressions": [+ "name": "PRIMARY",+ "expressions": ["a"],- "unique": true,- "primary": true,- "visible": true+ "unique": true,+ "primary": true,+ "visible": true}]}