Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: boolean bug (#16743)
h3n4l1fa281e4f907
diff --git a/backend/common/engine.go b/backend/common/engine.goindex 08392a4ee0..0d94dbce1e 100644--- a/backend/common/engine.go+++ b/backend/common/engine.go@@ -459,19 +459,19 @@ func BackupDatabaseNameOfEngine(e storepb.Engine) string {}}-// EngineNeedsColumnDefaultMigration returns true if the engine needs column default migration.+// EngineDBSchemaReadyToMigrate returns true if the engine needs column default migration.// This is used by both the migrator and the sync process to determine if a database// needs the column default migration.// When an engine's sync.go is updated to write to the Default field with proper// normalization (like schema qualification), we move it to the false case.-func EngineNeedsColumnDefaultMigration(e storepb.Engine) bool {+func EngineDBSchemaReadyToMigrate(e storepb.Engine) bool {//exhaustive:enforceswitch e {casestorepb.Engine_POSTGRES:// PostgreSQL sync.go has been updated to write to Default field with// proper schema qualification, so it doesn't need migration anymore.- return false+ return truecasestorepb.Engine_MYSQL,storepb.Engine_TIDB,@@ -491,7 +491,7 @@ func EngineNeedsColumnDefaultMigration(e storepb.Engine) bool {storepb.Engine_STARROCKS,storepb.Engine_DORIS:// These engines still need migration as their sync.go hasn't been updated yet.- return true+ return falsecasestorepb.Engine_ENGINE_UNSPECIFIED,storepb.Engine_CASSANDRA,@@ -505,8 +505,8 @@ func EngineNeedsColumnDefaultMigration(e storepb.Engine) bool {storepb.Engine_COSMOSDB,storepb.Engine_TRINO:// These engines don't have traditional column defaults or are NoSQL databases.- return false+ return truedefault:- return false+ return true}}diff --git a/backend/runner/migrator/column_default_migrator.go b/backend/runner/migrator/column_default_migrator.goindex 6db6c06eb9..c657e59140 100644--- a/backend/runner/migrator/column_default_migrator.go+++ b/backend/runner/migrator/column_default_migrator.go@@ -42,7 +42,7 @@ func EnginesNeedingMigration() []storepb.Engine {var engines []storepb.Engine// Check all known enginesfor _, engine := range storepb.Engine_value {- if common.EngineNeedsColumnDefaultMigration(storepb.Engine(engine)) {+ if common.EngineDBSchemaReadyToMigrate(storepb.Engine(engine)) {engines = append(engines, storepb.Engine(engine))}}diff --git a/backend/runner/schemasync/syncer.go b/backend/runner/schemasync/syncer.goindex b0e72f25c2..28a554000b 100644--- a/backend/runner/schemasync/syncer.go+++ b/backend/runner/schemasync/syncer.go@@ -434,7 +434,7 @@ func (s *Syncer) SyncDatabaseSchemaToHistory(ctx context.Context, database *stor}rawDump := schemaBuf.Bytes()- todo := common.EngineNeedsColumnDefaultMigration(instance.Metadata.GetEngine())+ todo := !common.EngineDBSchemaReadyToMigrate(instance.Metadata.GetEngine())if err := s.store.UpsertDBSchema(ctx,database.InstanceID, database.DatabaseName,databaseMetadata, dbModelConfig.BuildDatabaseConfig(), rawDump, todo,@@ -544,7 +544,7 @@ func (s *Syncer) SyncDatabaseSchema(ctx context.Context, database *store.Databasreturn errors.Wrapf(err, "failed to update database %q for instance %q", database.DatabaseName, database.InstanceID)}- todo := common.EngineNeedsColumnDefaultMigration(instance.Metadata.GetEngine())+ todo := !common.EngineDBSchemaReadyToMigrate(instance.Metadata.GetEngine())if err := s.store.UpsertDBSchema(ctx,database.InstanceID, database.DatabaseName,databaseMetadata, dbModelConfig.BuildDatabaseConfig(), rawDump, todo,diff --git a/backend/runner/schemasync/syncer_test.go b/backend/runner/schemasync/syncer_test.godeleted file mode 100644index 740d6c0402..0000000000--- a/backend/runner/schemasync/syncer_test.go+++ /dev/null@@ -1,73 +0,0 @@-package schemasync--import (- "testing"-- "github.com/stretchr/testify/require"-- "github.com/bytebase/bytebase/backend/common"- storepb "github.com/bytebase/bytebase/proto/generated-go/store"-)--func TestTodoLogicForColumnDefaultMigration(t *testing.T) {- testCases := []struct {- name string- engine storepb.Engine- expectedTodo bool- description string- }{- {- name: "PostgreSQL",- engine: storepb.Engine_POSTGRES,- expectedTodo: false,- description: "PostgreSQL sync now writes to Default field with schema qualification",- },- {- name: "MySQL",- engine: storepb.Engine_MYSQL,- expectedTodo: true,- description: "MySQL sync hasn't been updated yet, needs migration",- },- {- name: "SQL Server",- engine: storepb.Engine_MSSQL,- expectedTodo: true,- description: "SQL Server sync hasn't been updated yet, needs migration",- },- {- name: "Oracle",- engine: storepb.Engine_ORACLE,- expectedTodo: true,- description: "Oracle sync hasn't been updated yet, needs migration",- },- {- name: "TiDB",- engine: storepb.Engine_TIDB,- expectedTodo: true,- description: "TiDB sync hasn't been updated yet, needs migration",- },- }-- for _, tc := range testCases {- t.Run(tc.name, func(t *testing.T) {- // Use the centralized logic- todo := common.EngineNeedsColumnDefaultMigration(tc.engine)-- require.Equal(t, tc.expectedTodo, todo,- "Engine %s: %s. Expected todo=%t, got todo=%t",- tc.name, tc.description, tc.expectedTodo, todo)- })- }-}--func TestEnginesNeedingMigrationConsistency(t *testing.T) {- // Verify that PostgreSQL doesn't need migration using the centralized logic- require.False(t, common.EngineNeedsColumnDefaultMigration(storepb.Engine_POSTGRES),- "PostgreSQL should not need migration")-- // Verify that other common engines do need migration- require.True(t, common.EngineNeedsColumnDefaultMigration(storepb.Engine_MYSQL),- "MySQL should need migration")- require.True(t, common.EngineNeedsColumnDefaultMigration(storepb.Engine_MSSQL),- "SQL Server should need migration")-}