Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
refactor: remove redundant `len` check (#8541)
Eng Zer Jun22f0a4afe101
diff --git a/backend/plugin/parser/sql/edit/mysql/deparse.go b/backend/plugin/parser/sql/edit/mysql/deparse.goindex ee0331cfd3..6836accdce 100644--- a/backend/plugin/parser/sql/edit/mysql/deparse.go+++ b/backend/plugin/parser/sql/edit/mysql/deparse.go@@ -120,11 +120,9 @@ func transformCreateTableContext(createTableContext *api.CreateTableContext) (*tcreateTableStmt.Constraints = append(createTableStmt.Constraints, &pkConstrains)}- if len(createTableContext.AddForeignKeyList) != 0 {- for _, addForeignKeyContext := range createTableContext.AddForeignKeyList {- constraint := transfromAddForeignKeyContext(addForeignKeyContext)- createTableStmt.Constraints = append(createTableStmt.Constraints, constraint)- }+ for _, addForeignKeyContext := range createTableContext.AddForeignKeyList {+ constraint := transfromAddForeignKeyContext(addForeignKeyContext)+ createTableStmt.Constraints = append(createTableStmt.Constraints, constraint)}return createTableStmt, nil@@ -139,16 +137,14 @@ func transformAlterTableContext(alterTableContext *api.AlterTableContext) (*tidbSpecs: []*tidbast.AlterTableSpec{},}- if len(alterTableContext.DropColumnList) > 0 {- for _, dropColumnContext := range alterTableContext.DropColumnList {- alterTableSpec := &tidbast.AlterTableSpec{- Tp: tidbast.AlterTableDropColumn,- OldColumnName: &tidbast.ColumnName{- Name: model.NewCIStr(dropColumnContext.Name),- },- }- alterTableStmt.Specs = append(alterTableStmt.Specs, alterTableSpec)+ for _, dropColumnContext := range alterTableContext.DropColumnList {+ alterTableSpec := &tidbast.AlterTableSpec{+ Tp: tidbast.AlterTableDropColumn,+ OldColumnName: &tidbast.ColumnName{+ Name: model.NewCIStr(dropColumnContext.Name),+ },}+ alterTableStmt.Specs = append(alterTableStmt.Specs, alterTableSpec)}if len(alterTableContext.AddColumnList) > 0 {@@ -166,30 +162,28 @@ func transformAlterTableContext(alterTableContext *api.AlterTableContext) (*tidbalterTableStmt.Specs = append(alterTableStmt.Specs, alterTableSpec)}- if len(alterTableContext.ChangeColumnList) > 0 {- for _, changeColumnContext := range alterTableContext.ChangeColumnList {- oldColumnName := &tidbast.ColumnName{- Name: model.NewCIStr(changeColumnContext.OldName),- }- newColumnName := &tidbast.ColumnName{- Name: model.NewCIStr(changeColumnContext.NewName),- }- alterTableSpec := &tidbast.AlterTableSpec{- Tp: tidbast.AlterTableChangeColumn,- OldColumnName: oldColumnName,- NewColumnName: newColumnName,- // TODO(steven): support modify the column position.- Position: &tidbast.ColumnPosition{- Tp: tidbast.ColumnPositionNone,- },- }- column, err := transformChangeColumnContext(changeColumnContext)- if err != nil {- return nil, err- }- alterTableSpec.NewColumns = []*tidbast.ColumnDef{column}- alterTableStmt.Specs = append(alterTableStmt.Specs, alterTableSpec)+ for _, changeColumnContext := range alterTableContext.ChangeColumnList {+ oldColumnName := &tidbast.ColumnName{+ Name: model.NewCIStr(changeColumnContext.OldName),+ }+ newColumnName := &tidbast.ColumnName{+ Name: model.NewCIStr(changeColumnContext.NewName),}+ alterTableSpec := &tidbast.AlterTableSpec{+ Tp: tidbast.AlterTableChangeColumn,+ OldColumnName: oldColumnName,+ NewColumnName: newColumnName,+ // TODO(steven): support modify the column position.+ Position: &tidbast.ColumnPosition{+ Tp: tidbast.ColumnPositionNone,+ },+ }+ column, err := transformChangeColumnContext(changeColumnContext)+ if err != nil {+ return nil, err+ }+ alterTableSpec.NewColumns = []*tidbast.ColumnDef{column}+ alterTableStmt.Specs = append(alterTableStmt.Specs, alterTableSpec)}if alterTableContext.PrimaryKeyList != nil {@@ -221,25 +215,21 @@ func transformAlterTableContext(alterTableContext *api.AlterTableContext) (*tidb}}- if len(alterTableContext.DropForeignKeyList) != 0 {- for _, name := range alterTableContext.DropForeignKeyList {- alterTableSpec := tidbast.AlterTableSpec{- Tp: tidbast.AlterTableDropForeignKey,- Name: name,- }- alterTableStmt.Specs = append(alterTableStmt.Specs, &alterTableSpec)+ for _, name := range alterTableContext.DropForeignKeyList {+ alterTableSpec := tidbast.AlterTableSpec{+ Tp: tidbast.AlterTableDropForeignKey,+ Name: name,}+ alterTableStmt.Specs = append(alterTableStmt.Specs, &alterTableSpec)}- if len(alterTableContext.AddForeignKeyList) != 0 {- for _, addForeignKeyContext := range alterTableContext.AddForeignKeyList {- alterTableSpec := tidbast.AlterTableSpec{- Tp: tidbast.AlterTableAddConstraint,- }- constraint := transfromAddForeignKeyContext(addForeignKeyContext)- alterTableSpec.Constraint = constraint- alterTableStmt.Specs = append(alterTableStmt.Specs, &alterTableSpec)+ for _, addForeignKeyContext := range alterTableContext.AddForeignKeyList {+ alterTableSpec := tidbast.AlterTableSpec{+ Tp: tidbast.AlterTableAddConstraint,}+ constraint := transfromAddForeignKeyContext(addForeignKeyContext)+ alterTableSpec.Constraint = constraint+ alterTableStmt.Specs = append(alterTableStmt.Specs, &alterTableSpec)}return alterTableStmt, nil