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: support ON UPDATE in branch and schema editor for MySQL and TiDB (#10613)
rebelicefdb8c53fbab1
diff --git a/backend/api/v1/branch_service.go b/backend/api/v1/branch_service.goindex 12a97e6cdf..5008f7b4a3 100644--- a/backend/api/v1/branch_service.go+++ b/backend/api/v1/branch_service.go@@ -945,6 +945,7 @@ func filterDatabaseMetadata(metadata *storepb.DatabaseSchemaMetadata) *storepb.Dfor _, column := range table.Columns {filteredColumn := &storepb.ColumnMetadata{Name: column.Name,+ OnUpdate: column.OnUpdate,Comment: column.Comment,UserComment: column.UserComment,Classification: column.Classification,@@ -1061,6 +1062,9 @@ func equalTable(s, t *storepb.TableMetadata) bool {if sc.Name != tc.Name {return false}+ if sc.OnUpdate != tc.OnUpdate {+ return false+ }if sc.Comment != tc.Comment {return false}diff --git a/backend/api/v1/database_converter.go b/backend/api/v1/database_converter.goindex 2ce12de2e3..d2a0aaf086 100644--- a/backend/api/v1/database_converter.go+++ b/backend/api/v1/database_converter.go@@ -248,6 +248,7 @@ func convertStoreColumnMetadata(column *storepb.ColumnMetadata) *v1pb.ColumnMetaName: column.GetName(),Position: column.GetPosition(),HasDefault: column.GetDefaultValue() != nil,+ OnUpdate: column.GetOnUpdate(),Nullable: column.GetNullable(),Type: column.GetType(),CharacterSet: column.GetCharacterSet(),@@ -511,6 +512,7 @@ func convertV1ColumnMetadata(column *v1pb.ColumnMetadata) *storepb.ColumnMetadatComment: column.GetComment(),Classification: column.GetClassification(),UserComment: column.GetUserComment(),+ OnUpdate: column.GetOnUpdate(),}if column.HasDefault {diff --git a/backend/plugin/db/mysql/sync.go b/backend/plugin/db/mysql/sync.goindex 74f1c1b2af..07563c7cd3 100644--- a/backend/plugin/db/mysql/sync.go+++ b/backend/plugin/db/mysql/sync.go@@ -6,6 +6,7 @@ import ("fmt""log/slog""math/rand"+ "regexp""sort""strconv""strings"@@ -297,6 +298,17 @@ func (driver *Driver) SyncDBSchema(ctx context.Context) (*storepb.DatabaseSchema}}+ if strings.Contains(extra, "on update CURRENT_TIMESTAMP") {+ re := regexp.MustCompile(`CURRENT_TIMESTAMP\((\d+)\)`)+ match := re.FindStringSubmatch(extra)+ if len(match) > 0 {+ digits := match[1]+ column.OnUpdate = fmt.Sprintf("CURRENT_TIMESTAMP(%s)", digits)+ } else {+ column.OnUpdate = "CURRENT_TIMESTAMP"+ }+ }+key := db.TableKey{Schema: "", Table: tableName}columnMap[key] = append(columnMap[key], column)}diff --git a/backend/plugin/db/tidb/sync.go b/backend/plugin/db/tidb/sync.goindex 224d9b25c1..cd73e827ce 100644--- a/backend/plugin/db/tidb/sync.go+++ b/backend/plugin/db/tidb/sync.go@@ -324,6 +324,17 @@ func (driver *Driver) SyncDBSchema(ctx context.Context) (*storepb.DatabaseSchema}}+ if strings.Contains(extra, "on update CURRENT_TIMESTAMP") {+ re := regexp.MustCompile(`CURRENT_TIMESTAMP\((\d+)\)`)+ match := re.FindStringSubmatch(extra)+ if len(match) > 0 {+ digits := match[1]+ column.OnUpdate = fmt.Sprintf("CURRENT_TIMESTAMP(%s)", digits)+ } else {+ column.OnUpdate = "CURRENT_TIMESTAMP"+ }+ }+key := db.TableKey{Schema: "", Table: tableName}columnMap[key] = append(columnMap[key], column)}diff --git a/backend/plugin/parser/tidb/strings.go b/backend/plugin/parser/tidb/strings.goindex 5065061eda..4db2460aff 100644--- a/backend/plugin/parser/tidb/strings.go+++ b/backend/plugin/parser/tidb/strings.go@@ -936,16 +936,9 @@ func (r *rewriter) EnterColumnDef(ctx *parser.ColumnDefContext) {}// ON UPDATE.- // TODO: we don't support ON UPDATE for now.- if option, exists := optionMap[tidbast.ColumnOptionOnUpdate]; exists {- if err := buf.WriteByte(' '); err != nil {- r.err = errors.Wrap(err, "failed to write byte")- return- }- if _, err := buf.WriteString(option.GetParser().GetTokenStream().GetTextFromRuleContext(option)); err != nil {- r.err = errors.Wrap(err, "failed to write string")- return- }+ if err := writeOnUpdateOption(&buf, optionMap, optionActionMap); err != nil {+ r.err = err+ return}// COMMENT.@@ -957,6 +950,42 @@ func (r *rewriter) EnterColumnDef(ctx *parser.ColumnDefContext) {r.columnDefines = append(r.columnDefines, buf.String())}+func writeOnUpdateOption(buf *strings.Builder, optionMap map[tidbast.ColumnOptionType]parser.IColumnOptionContext, optionActionMap map[tidbast.ColumnOptionType]StringsManipulatorAction) error {+ needOrigin := true+ if action, exists := optionActionMap[tidbast.ColumnOptionOnUpdate]; exists {+ switch action := action.(type) {+ case *StringsManipulatorActionDropColumnOption:+ // Drop column option+ needOrigin = false+ case *StringsManipulatorActionModifyColumnOption:+ needOrigin = false+ if err := buf.WriteByte(' '); err != nil {+ return errors.Wrap(err, "failed to write byte")+ }+ if _, err := buf.WriteString(action.NewOptionDefine); err != nil {+ return errors.Wrap(err, "failed to write string")+ }+ case *StringsManipulatorActionAddColumnOption:+ needOrigin = false+ if err := buf.WriteByte(' '); err != nil {+ return errors.Wrap(err, "failed to write byte")+ }+ if _, err := buf.WriteString(action.NewOptionDefine); err != nil {+ return errors.Wrap(err, "failed to write string")+ }+ }+ }+ if option, exists := optionMap[tidbast.ColumnOptionOnUpdate]; exists && needOrigin {+ if err := buf.WriteByte(' '); err != nil {+ return errors.Wrap(err, "failed to write byte")+ }+ if _, err := buf.WriteString(option.GetParser().GetTokenStream().GetTextFromRuleContext(option)); err != nil {+ return errors.Wrap(err, "failed to write string")+ }+ }+ return nil+}+func writeColumnCommentOption(buf *strings.Builder, optionMap map[tidbast.ColumnOptionType]parser.IColumnOptionContext, optionActionMap map[tidbast.ColumnOptionType]StringsManipulatorAction) error {needOrigin := trueif action, exists := optionActionMap[tidbast.ColumnOptionComment]; exists {diff --git a/backend/plugin/schema/mysql/get_design_schema.go b/backend/plugin/schema/mysql/get_design_schema.goindex 5da9634449..41be02b757 100644--- a/backend/plugin/schema/mysql/get_design_schema.go+++ b/backend/plugin/schema/mysql/get_design_schema.go@@ -4,6 +4,7 @@ import ("fmt""io""log/slog"+ "regexp""sort""strings"@@ -815,6 +816,33 @@ func (g *mysqlDesignSchemaGenerator) EnterColumnDefinition(ctx *mysql.ColumnDefi}}}+ case attribute.ON_SYMBOL() != nil && attribute.UPDATE_SYMBOL() != nil:+ attOnUpdate := "CURRENT_TIMESTAMP"+ if attribute.TimeFunctionParameters() != nil && attribute.TimeFunctionParameters().FractionalPrecision() != nil {+ attOnUpdate += fmt.Sprintf("(%s)", attribute.TimeFunctionParameters().FractionalPrecision().GetText())+ }+ onUpdate := normalizeOnUpdate(column.onUpdate)+ if onUpdate == attOnUpdate {+ if _, err := g.columnDefine.WriteString(ctx.GetParser().GetTokenStream().GetTextFromInterval(antlr.Interval{+ Start: startPos,+ Stop: attribute.GetStop().GetTokenIndex(),+ })); err != nil {+ g.err = err+ return+ }+ } else if onUpdate != "" {+ if _, err := g.columnDefine.WriteString(ctx.GetParser().GetTokenStream().GetTextFromInterval(antlr.Interval{+ Start: startPos,+ Stop: attribute.GetStart().GetTokenIndex() - 1,+ })); err != nil {+ g.err = err+ return+ }+ if _, err := g.columnDefine.WriteString(fmt.Sprintf("ON UPDATE %s", onUpdate)); err != nil {+ g.err = err+ return+ }+ }case attribute.COMMENT_SYMBOL() != nil:commentStart := nextDefaultChannelTokenIndex(attribute.GetParser().GetTokenStream(), attribute.COMMENT_SYMBOL().GetSymbol().GetTokenIndex())commentValue := attribute.GetParser().GetTokenStream().GetTextFromInterval(antlr.Interval{@@ -873,6 +901,26 @@ func (g *mysqlDesignSchemaGenerator) EnterColumnDefinition(ctx *mysql.ColumnDefi}}+func normalizeOnUpdate(s string) string {+ if s == "" {+ return ""+ }++ lowerS := strings.ToLower(s)+ re := regexp.MustCompile(`(current_timestamp|now|localtime|localtimestamp)(?:\((\d+)\))?`)+ match := re.FindStringSubmatch(lowerS)+ if len(match) > 0 {+ if len(match) > 1 && match[1] != "" {+ // has precision+ return fmt.Sprintf("CURRENT_TIMESTAMP(%s)", match[2])+ }+ // no precision+ return "CURRENT_TIMESTAMP"+ }+ // not a current_timestamp family function+ return s+}+// DropViewStatement is called when production dropViewStatement is entered.//// mysqldump generate drop view if exists statement after all create table statement.diff --git a/backend/plugin/schema/mysql/parse_to_metadata.go b/backend/plugin/schema/mysql/parse_to_metadata.goindex 3db3d1629a..6b4c4588aa 100644--- a/backend/plugin/schema/mysql/parse_to_metadata.go+++ b/backend/plugin/schema/mysql/parse_to_metadata.go@@ -176,6 +176,14 @@ func (t *mysqlTransformer) EnterColumnDefinition(ctx *mysql.ColumnDefinitionContcase attribute.AUTO_INCREMENT_SYMBOL() != nil:defaultValue := autoIncrementSymbolcolumnState.defaultValue = &defaultValueExpression{value: defaultValue}+ case attribute.ON_SYMBOL() != nil && attribute.UPDATE_SYMBOL() != nil:+ onUpdateValue := ""+ if attribute.TimeFunctionParameters() != nil && attribute.TimeFunctionParameters().FractionalPrecision() != nil {+ onUpdateValue = "CURRENT_TIMESTAMP(" + attribute.TimeFunctionParameters().FractionalPrecision().GetText() + ")"+ } else {+ onUpdateValue = "CURRENT_TIMESTAMP"+ }+ columnState.onUpdate = onUpdateValue}}diff --git a/backend/plugin/schema/mysql/state.go b/backend/plugin/schema/mysql/state.goindex 3488b8cc43..f1ea8494ad 100644--- a/backend/plugin/schema/mysql/state.go+++ b/backend/plugin/schema/mysql/state.go@@ -519,6 +519,7 @@ type columnState struct {name stringtp stringdefaultValue defaultValue+ onUpdate stringcomment stringnullable bool}@@ -553,6 +554,11 @@ func (c *columnState) toString(buf io.StringWriter) error {}}}+ if len(c.onUpdate) > 0 {+ if _, err := buf.WriteString(fmt.Sprintf(" ON UPDATE %s", c.onUpdate)); err != nil {+ return err+ }+ }if c.comment != "" {if _, err := buf.WriteString(fmt.Sprintf(" COMMENT '%s'", c.comment)); err != nil {return err@@ -566,6 +572,7 @@ func (c *columnState) convertToColumnMetadata() *storepb.ColumnMetadata {Name: c.name,Type: c.tp,Nullable: c.nullable,+ OnUpdate: c.onUpdate,Comment: c.comment,}if c.defaultValue != nil {@@ -590,6 +597,7 @@ func convertToColumnState(id int, column *storepb.ColumnMetadata) *columnState {name: column.Name,tp: column.Type,nullable: column.Nullable,+ onUpdate: normalizeOnUpdate(column.OnUpdate),comment: column.Comment,}if column.GetDefaultValue() != nil {diff --git a/backend/plugin/schema/mysql/testdata/get_design_schema.yaml b/backend/plugin/schema/mysql/testdata/get_design_schema.yamlindex 48e09f81b8..e428ae5e21 100644--- a/backend/plugin/schema/mysql/testdata/get_design_schema.yaml+++ b/backend/plugin/schema/mysql/testdata/get_design_schema.yaml@@ -659,3 +659,57 @@CREATE TABLE `t4` (`a` int DEFAULT 1 primary key);+- description: ""+ baseline: |-+ CREATE TABLE `t` (+ `c` timestamp(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),+ `d` timestamp DEFAULT CURRENT_TIMESTAMP,+ `e` timestamp(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)+ );+ target: |-+ {+ "schemas": [+ {+ "tables": [+ {+ "name": "t",+ "columns": [+ {+ "name": "a",+ "type": "int"+ },+ {+ "name": "b",+ "type": "varchar(255)"+ },+ {+ "name": "c",+ "type": "timestamp(3)",+ "defaultExpression": "CURRENT_TIMESTAMP(3)",+ "onUpdate": "CURRENT_TIMESTAMP(3)"+ },+ {+ "name": "d",+ "type": "timestamp",+ "defaultExpression": "CURRENT_TIMESTAMP",+ "onUpdate": "CURRENT_TIMESTAMP"+ },+ {+ "name": "e",+ "type": "timestamp",+ "defaultExpression": "CURRENT_TIMESTAMP"+ }+ ]+ }+ ]+ }+ ]+ }+ result: |+ CREATE TABLE `t` (+ `c` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),+ `d` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP(),+ `e` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,+ `a` int NOT NULL,+ `b` varchar(255) NOT NULL+ );diff --git a/backend/plugin/schema/mysql/testdata/parse_to_metadata.yaml b/backend/plugin/schema/mysql/testdata/parse_to_metadata.yamlindex 57596cba9a..f70b87871c 100644--- a/backend/plugin/schema/mysql/testdata/parse_to_metadata.yaml+++ b/backend/plugin/schema/mysql/testdata/parse_to_metadata.yaml@@ -7,6 +7,7 @@`d` text NULL,`t_not_null` text NOT NULL,`e` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,+ `g` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,PRIMARY KEY (`a`),UNIQUE KEY `t_c_uniq_idx` (`c` DESC),UNIQUE KEY `t_c_plus_5_uniq_idx` (((`c` + 5)) DESC),@@ -56,6 +57,13 @@"name": "e","position": 6,"type": "varchar(20)"+ },+ {+ "name": "g",+ "position": 7,+ "defaultExpression": "CURRENT_TIMESTAMP",+ "onUpdate": "CURRENT_TIMESTAMP",+ "type": "TIMESTAMP"}],"indexes": [diff --git a/backend/plugin/schema/mysql/utils.go b/backend/plugin/schema/mysql/utils.goindex fe47844eb3..85d75d2bbb 100644--- a/backend/plugin/schema/mysql/utils.go+++ b/backend/plugin/schema/mysql/utils.go@@ -130,19 +130,19 @@ type columnAttr struct {var columnAttrOrder = map[string]int{"NULL": 1,"DEFAULT": 2,- "VISIBLE": 3,- "AUTO_INCREMENT": 4,- "AUTO_RAND": 4,- "UNIQUE": 5,- "KEY": 6,- "COMMENT": 7,- "COLLATE": 8,- "COLUMN_FORMAT": 9,- "SECONDARY": 10,- "STORAGE": 11,- "SERIAL": 12,- "SRID": 13,- "ON": 14,+ "ON": 3,+ "VISIBLE": 4,+ "AUTO_INCREMENT": 5,+ "AUTO_RAND": 5,+ "UNIQUE": 6,+ "KEY": 7,+ "COMMENT": 8,+ "COLLATE": 9,+ "COLUMN_FORMAT": 10,+ "SECONDARY": 11,+ "STORAGE": 12,+ "SERIAL": 13,+ "SRID": 14,"CHECK": 15,"ENFORCED": 16,}@@ -151,6 +151,7 @@ func extractNewAttrs(column *columnState, attrs []mysql.IColumnAttributeContext)var result []columnAttrnullExists := falsedefaultExists := false+ onUpdateExists := falsecommentExists := falsefor _, attr := range attrs {if attr.GetValue() != nil {@@ -159,6 +160,8 @@ func extractNewAttrs(column *columnState, attrs []mysql.IColumnAttributeContext)defaultExists = truecase "COMMENT":commentExists = true+ case "ON":+ onUpdateExists = true}} else if attr.NullLiteral() != nil {nullExists = true@@ -195,6 +198,12 @@ func extractNewAttrs(column *columnState, attrs []mysql.IColumnAttributeContext)order: columnAttrOrder["COMMENT"],})}+ if !onUpdateExists && column.onUpdate != "" {+ result = append(result, columnAttr{+ text: "ON UPDATE " + column.onUpdate,+ order: columnAttrOrder["ON"],+ })+ }return result}diff --git a/backend/plugin/schema/tidb/get_design_schema.go b/backend/plugin/schema/tidb/get_design_schema.goindex 3d59783ff9..60275fe32a 100644--- a/backend/plugin/schema/tidb/get_design_schema.go+++ b/backend/plugin/schema/tidb/get_design_schema.go@@ -207,6 +207,24 @@ func (g *tidbDesignSchemaGenerator) Enter(in tidbast.Node) (tidbast.Node, bool)}}+ // On update.+ if option, exists := optionMap[tidbast.ColumnOptionOnUpdate]; exists {+ onUpdate, err := restoreExpr(option.Expr)+ if err != nil {+ g.err = err+ return in, true+ }+ if *onUpdate != stateColumn.onUpdate {+ if stateColumn.onUpdate != "" {+ g.actions = append(g.actions, tidbparser.NewModifyColumnOptionAction(tableName, columnName, tidbast.ColumnOptionOnUpdate, fmt.Sprintf("ON UPDATE %s", stateColumn.onUpdate)))+ } else {+ g.actions = append(g.actions, tidbparser.NewDropColumnOptionAction(tableName, columnName, tidbast.ColumnOptionOnUpdate))+ }+ }+ } else if stateColumn.onUpdate != "" {+ g.actions = append(g.actions, tidbparser.NewAddColumnOptionAction(tableName, columnName, tidbast.ColumnOptionOnUpdate, fmt.Sprintf("ON UPDATE %s", stateColumn.onUpdate)))+ }+// Comment.if option, exists := optionMap[tidbast.ColumnOptionComment]; exists {comment, err := restoreComment(option.Expr)diff --git a/backend/plugin/schema/tidb/parse_to_metadata.go b/backend/plugin/schema/tidb/parse_to_metadata.goindex a231867276..892703f1e0 100644--- a/backend/plugin/schema/tidb/parse_to_metadata.go+++ b/backend/plugin/schema/tidb/parse_to_metadata.go@@ -131,6 +131,13 @@ func (t *tidbTransformer) Enter(in tidbast.Node) (tidbast.Node, bool) {}}columnState.defaultValue = &defaultValueExpression{value: defaultValue}+ case tidbast.ColumnOptionOnUpdate:+ onUpdate, err := restoreExpr(option.Expr)+ if err != nil {+ t.err = err+ return in, true+ }+ columnState.onUpdate = *onUpdate}}table.columns[columnName] = columnStatediff --git a/backend/plugin/schema/tidb/state.go b/backend/plugin/schema/tidb/state.goindex 29ced6f322..f33ff9b200 100644--- a/backend/plugin/schema/tidb/state.go+++ b/backend/plugin/schema/tidb/state.go@@ -2,6 +2,7 @@ package tidbimport ("fmt"+ "regexp""sort""strings"@@ -492,6 +493,7 @@ type columnState struct {name stringtp stringdefaultValue defaultValue+ onUpdate stringcomment stringnullable bool}@@ -529,6 +531,11 @@ func (c *columnState) toString(buf *strings.Builder) error {}}}+ if c.onUpdate != "" {+ if _, err := buf.WriteString(fmt.Sprintf(" ON UPDATE %s", c.onUpdate)); err != nil {+ return err+ }+ }if c.comment != "" {if _, err := buf.WriteString(fmt.Sprintf(" COMMENT '%s'", c.comment)); err != nil {return err@@ -542,6 +549,7 @@ func (c *columnState) convertToColumnMetadata() *storepb.ColumnMetadata {Name: c.name,Type: c.tp,Nullable: c.nullable,+ OnUpdate: c.onUpdate,Comment: c.comment,}if c.defaultValue != nil {@@ -563,6 +571,7 @@ func convertToColumnState(id int, column *storepb.ColumnMetadata) *columnState {name: column.Name,tp: column.Type,nullable: column.Nullable,+ onUpdate: normalizeOnUpdate(column.OnUpdate),comment: column.Comment,}if column.GetDefaultValue() != nil {@@ -581,3 +590,23 @@ func convertToColumnState(id int, column *storepb.ColumnMetadata) *columnState {}return result}++func normalizeOnUpdate(s string) string {+ if s == "" {+ return ""+ }++ lowerS := strings.ToLower(s)+ re := regexp.MustCompile(`(current_timestamp|now|localtime|localtimestamp)(?:\((\d+)\))?`)+ match := re.FindStringSubmatch(lowerS)+ if len(match) > 0 {+ if len(match) > 1 && match[1] != "" {+ // has precision+ return fmt.Sprintf("CURRENT_TIMESTAMP(%s)", match[2])+ }+ // no precision+ return "CURRENT_TIMESTAMP"+ }+ // not a current_timestamp family function+ return s+}diff --git a/backend/plugin/schema/tidb/testdata/get_design_schema.yaml b/backend/plugin/schema/tidb/testdata/get_design_schema.yamlindex 36dc2ec1c7..6f77822331 100644--- a/backend/plugin/schema/tidb/testdata/get_design_schema.yaml+++ b/backend/plugin/schema/tidb/testdata/get_design_schema.yaml@@ -2,6 +2,9 @@CREATE TABLE `t` (`a` int,`b` varchar(255),+ `c` timestamp(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),+ `d` timestamp DEFAULT CURRENT_TIMESTAMP,+ `e` timestamp(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),KEY `idx_t_b` (`b`(20)) COMMENT 'this is comment with',KEY `delete_idx` (`b`(20)) COMMENT 'need to delete');@@ -20,6 +23,23 @@{"name": "b","type": "varchar(255)"+ },+ {+ "name": "c",+ "type": "timestamp(3)",+ "defaultExpression": "CURRENT_TIMESTAMP(3)",+ "onUpdate": "CURRENT_TIMESTAMP(3)"+ },+ {+ "name": "d",+ "type": "timestamp",+ "defaultExpression": "CURRENT_TIMESTAMP",+ "onUpdate": "CURRENT_TIMESTAMP"+ },+ {+ "name": "e",+ "type": "timestamp",+ "defaultExpression": "CURRENT_TIMESTAMP"}],"indexes": [@@ -52,6 +72,9 @@CREATE TABLE `t` (`a` int NOT NULL,`b` varchar(255) NOT NULL,+ `c` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),+ `d` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP(),+ `e` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,KEY `idx_t_b` (`b`(20)) COMMENT 'this is comment with',KEY `idx_t_b2` (`b`(20)));diff --git a/backend/plugin/schema/tidb/testdata/parse_to_metadata.yaml b/backend/plugin/schema/tidb/testdata/parse_to_metadata.yamlindex 7ee147e612..d0adf8e6fc 100644--- a/backend/plugin/schema/tidb/testdata/parse_to_metadata.yaml+++ b/backend/plugin/schema/tidb/testdata/parse_to_metadata.yaml@@ -3,6 +3,7 @@(`a` int NOT NULL COMMENT 'this is comment',`b` VARCHAR(20) NOT NULL,+ `c` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),KEY `idx` (((`a` + 20))),UNIQUE KEY `idx2` (`a`),KEY `idx_length` (`b`(10)),@@ -10,66 +11,73 @@) 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"},{- "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)"}],- "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"}]}@@ -98,192 +106,192 @@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"},{- "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}]}diff --git a/frontend/src/components/SchemaEditorLite/Panels/TableColumnEditor/TableColumnEditor.vue b/frontend/src/components/SchemaEditorLite/Panels/TableColumnEditor/TableColumnEditor.vueindex 90d0db5f93..f6e2ea9077 100644--- a/frontend/src/components/SchemaEditorLite/Panels/TableColumnEditor/TableColumnEditor.vue+++ b/frontend/src/components/SchemaEditorLite/Panels/TableColumnEditor/TableColumnEditor.vue@@ -433,6 +433,31 @@ const columns = computed(() => {});},},+ {+ key: "on-update",+ title: t("schema-editor.column.on-update"),+ resizable: true,+ minWidth: 140,+ maxWidth: 320,+ hide: props.engine !== Engine.MYSQL && props.engine !== Engine.TIDB,+ className: "input-cell",+ render: (column) => {+ return h(InlineInput, {+ value: column.onUpdate,+ disabled: props.readonly || props.disableAlterColumn(column),+ placeholder: "on update",+ style: {+ "--n-padding-left": "6px",+ "--n-padding-right": "4px",+ "--n-text-color-disabled": "rgb(var(--color-main))",+ },+ "onUpdate:value": (value) => {+ column.onUpdate = value;+ markColumnStatus(column, "updated");+ },+ });+ },+ },{key: "comment",title: t("schema-editor.column.comment"),diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 22967e1459..0ab1afcd29 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -2348,7 +2348,8 @@"not-null": "Not Null","primary": "Primary","foreign-key": "Foreign Key",- "classification": "Classification"+ "classification": "Classification",+ "on-update": "On Update"},"default": {"no-default": "No default",diff --git a/frontend/src/utils/schemaEditor/filter.ts b/frontend/src/utils/schemaEditor/filter.tsindex 249da4f5bd..fb22053f91 100644--- a/frontend/src/utils/schemaEditor/filter.ts+++ b/frontend/src/utils/schemaEditor/filter.ts@@ -34,6 +34,7 @@ export const filterColumnMetadata = (column: ColumnMetadata) => {defaultExpression: column.defaultExpression,defaultNull: column.defaultNull,defaultString: column.defaultString,+ onUpdate: column.onUpdate,nullable: column.nullable,position: column.position,});