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: mergeDatabaseConfig (#8613)
Danny Xu017c0237a6fd
diff --git a/backend/runner/taskrun/database_config_merge.go b/backend/runner/taskrun/database_config_merge.goindex 023c668ece..217f8c66a8 100644--- a/backend/runner/taskrun/database_config_merge.go+++ b/backend/runner/taskrun/database_config_merge.go@@ -1,301 +1,179 @@package taskrunimport (+ "reflect"+ "sort"+"google.golang.org/protobuf/proto"storepb "github.com/bytebase/bytebase/proto/generated-go/store")-type updateDatabaseConfigAction string--const (- updateDatabaseConfigActionUpdate updateDatabaseConfigAction = "UPDATE"-)--type databaseConfigNode struct {- schemaChildren []*schemaConfigNode-}--type schemaConfigNode struct {- action updateDatabaseConfigAction- name string- tableChildren []*tableConfigNode-}--type tableConfigNode struct {- action updateDatabaseConfigAction- name string-- columnChildren []*columnConfigNode-}--type columnConfigNode struct {- action updateDatabaseConfigAction- name string-- // semanticTypeAttributeChildren is the semantic type attribute config after the migration, only be used when action is updated.- semanticTypeAttributeChildren *columnConfigSemanticTypeAttributeNode-}--type columnConfigSemanticTypeAttributeNode struct {- action updateDatabaseConfigAction-- to string-}--// mergeDatabaseConfig computes the migration from databaseConfig and baselineDatabaseConfig, and applies the migration to appliedTarget, returns the updated databaseConfig.-func mergeDatabaseConfig(databaseConfig, baselineDatabaseConfig, appliedTarget *storepb.DatabaseConfig) *storepb.DatabaseConfig {- // To avoid determining the databaseConfig, baselineDatabaseConfig and appliedTarget are nil or not, we will replace the nil with empty config at the beginning.- if databaseConfig == nil {- databaseConfig = &storepb.DatabaseConfig{}+// mergeDatabaseConfig computes the migration from target and baseline, and applies the migration to current databaseConfig.+// Return the merged databaseConfig.+func mergeDatabaseConfig(target, baseline, current *storepb.DatabaseConfig) *storepb.DatabaseConfig {+ // Avoid nil values.+ if target == nil {+ target = &storepb.DatabaseConfig{}}- if baselineDatabaseConfig == nil {- baselineDatabaseConfig = &storepb.DatabaseConfig{}+ if baseline == nil {+ baseline = &storepb.DatabaseConfig{}}- if appliedTarget == nil {- appliedTarget = &storepb.DatabaseConfig{}- }-- diff := &databaseConfigNode{}-- schemaConfigInBaselineMap := make(map[string]*storepb.SchemaConfig)- for _, schemaConfig := range baselineDatabaseConfig.SchemaConfigs {- schemaConfigInBaselineMap[schemaConfig.Name] = schemaConfig+ if current == nil {+ current = &storepb.DatabaseConfig{}}- // Computing the diff between databaseConfig and baselineDatabaseConfig, we only use `UPDATE` action.- for _, schemaConfigWanted := range databaseConfig.SchemaConfigs {- schemaNode := &schemaConfigNode{- action: updateDatabaseConfigActionUpdate,- name: schemaConfigWanted.Name,+ targetMap, baselineMap, currentMap := buildSchemaMap(target), buildSchemaMap(baseline), buildSchemaMap(current)+ for schemaName, targetSchema := range targetMap {+ currentSchema, hasCurrent := currentMap[schemaName]+ baselineSchema := baselineMap[schemaName]+ if hasCurrent {+ currentMap[schemaName] = mergeSchemaConfig(targetSchema, baselineSchema, currentSchema)+ } else {+ currentMap[schemaName] = targetSchema}- schemaConfigInBaseline, ok := schemaConfigInBaselineMap[schemaConfigWanted.Name]- if !ok {- for _, tableConfigWanted := range schemaConfigWanted.TableConfigs {- tableNode := &tableConfigNode{- action: updateDatabaseConfigActionUpdate,- name: tableConfigWanted.Name,- }- for _, columnConfigWanted := range tableConfigWanted.ColumnConfigs {- columnNode := buildColumnConfigUpdateNodeFromColumnConfig(columnConfigWanted)- tableNode.columnChildren = append(tableNode.columnChildren, columnNode)- }- schemaNode.tableChildren = append(schemaNode.tableChildren, tableNode)- }- diff.schemaChildren = append(diff.schemaChildren, schemaNode)+ }+ for schemaName := range baselineMap {+ if _, ok := targetMap[schemaName]; ok {+ // Already checked above.continue}+ // Remove from the current since the change is to delete the schema..+ delete(currentMap, schemaName)+ }- tableConfigInBaselineMap := make(map[string]*storepb.TableConfig)- for _, tableConfig := range schemaConfigInBaseline.TableConfigs {- tableConfigInBaselineMap[tableConfig.Name] = tableConfig- }-- for _, tableConfigWanted := range schemaConfigWanted.TableConfigs {- tableNode := &tableConfigNode{- action: updateDatabaseConfigActionUpdate,- name: tableConfigWanted.Name,- }- tableConfigInBaseline, ok := tableConfigInBaselineMap[tableConfigWanted.Name]- if !ok {- for _, columnConfigWanted := range tableConfigWanted.ColumnConfigs {- columnNode := buildColumnConfigUpdateNodeFromColumnConfig(columnConfigWanted)- tableNode.columnChildren = append(tableNode.columnChildren, columnNode)- }- schemaNode.tableChildren = append(schemaNode.tableChildren, tableNode)- continue- }-- columnConfigInBaselineMap := make(map[string]*storepb.ColumnConfig)- for _, columnConfig := range tableConfigInBaseline.ColumnConfigs {- columnConfigInBaselineMap[columnConfig.Name] = columnConfig- }-- for _, columnConfigWanted := range tableConfigWanted.ColumnConfigs {- columnNode := &columnConfigNode{- action: updateDatabaseConfigActionUpdate,- name: columnConfigWanted.Name,- }-- columnConfigInBaseline, ok := columnConfigInBaselineMap[columnConfigWanted.Name]- if !ok {- columnNode.semanticTypeAttributeChildren = &columnConfigSemanticTypeAttributeNode{- action: updateDatabaseConfigActionUpdate,- to: columnConfigWanted.SemanticTypeId,- }- tableNode.columnChildren = append(tableNode.columnChildren, columnNode)- continue- }-- // Compare the attribute- hasAttributesUpdate := false- if columnConfigWanted.SemanticTypeId != columnConfigInBaseline.SemanticTypeId {- hasAttributesUpdate = true- }-- if hasAttributesUpdate {- columnNode.semanticTypeAttributeChildren = &columnConfigSemanticTypeAttributeNode{- action: updateDatabaseConfigActionUpdate,- to: columnConfigWanted.SemanticTypeId,- }- }-- // Append to table node if there is any update.- if columnNode.semanticTypeAttributeChildren != nil {- tableNode.columnChildren = append(tableNode.columnChildren, columnNode)- }- delete(columnConfigInBaselineMap, columnConfigWanted.Name)- }- for _, deletedColumnConfig := range columnConfigInBaselineMap {- columnNode := getEmptyColumnConfigNode(deletedColumnConfig.Name)- tableNode.columnChildren = append(tableNode.columnChildren, columnNode)- schemaNode.tableChildren = append(schemaNode.tableChildren, tableNode)- diff.schemaChildren = append(diff.schemaChildren, schemaNode)- }+ result := &storepb.DatabaseConfig{Name: current.Name}+ for _, v := range currentMap {+ result.SchemaConfigs = append(result.SchemaConfigs, v)+ }+ sort.Slice(result.SchemaConfigs, func(i, j int) bool {+ return result.SchemaConfigs[i].Name < result.SchemaConfigs[j].Name+ })+ return result+}- // Append to schema node if there is any update.- if len(tableNode.columnChildren) > 0 {- schemaNode.tableChildren = append(schemaNode.tableChildren, tableNode)- }- delete(tableConfigInBaselineMap, tableConfigWanted.Name)- }+func mergeSchemaConfig(target, baseline, current *storepb.SchemaConfig) *storepb.SchemaConfig {+ // Avoid nil values.+ if target == nil {+ target = &storepb.SchemaConfig{}+ }+ if baseline == nil {+ baseline = &storepb.SchemaConfig{}+ }+ if current == nil {+ current = &storepb.SchemaConfig{}+ }- for _, deletedTableConfig := range tableConfigInBaselineMap {- tableNode := &tableConfigNode{- action: updateDatabaseConfigActionUpdate,- name: deletedTableConfig.Name,- }- for _, columnConfigInBaseline := range deletedTableConfig.ColumnConfigs {- columnNode := getEmptyColumnConfigNode(columnConfigInBaseline.Name)- tableNode.columnChildren = append(tableNode.columnChildren, columnNode)- }- schemaNode.tableChildren = append(schemaNode.tableChildren, tableNode)- }- if len(schemaNode.tableChildren) > 0 {- diff.schemaChildren = append(diff.schemaChildren, schemaNode)+ targetMap, baselineMap, currentMap := buildTableMap(target), buildTableMap(baseline), buildTableMap(current)+ for tableName, targetTable := range targetMap {+ currentTable, hasCurrent := currentMap[tableName]+ baselineTable := baselineMap[tableName]+ if hasCurrent {+ currentMap[tableName] = mergeTableConfig(targetTable, baselineTable, currentTable)+ } else {+ currentMap[tableName] = targetTable}- delete(schemaConfigInBaselineMap, schemaConfigWanted.Name)}- for _, deletedSchemaConfig := range schemaConfigInBaselineMap {- schemaNode := &schemaConfigNode{- action: updateDatabaseConfigActionUpdate,- name: deletedSchemaConfig.Name,- }- for _, tableInBaseline := range deletedSchemaConfig.TableConfigs {- tableNode := &tableConfigNode{- action: updateDatabaseConfigActionUpdate,- name: tableInBaseline.Name,- }- for _, columnInBaseline := range tableInBaseline.ColumnConfigs {- columnNode := getEmptyColumnConfigNode(columnInBaseline.Name)- tableNode.columnChildren = append(tableNode.columnChildren, columnNode)- }- schemaNode.tableChildren = append(schemaNode.tableChildren, tableNode)+ for tableName := range baselineMap {+ if _, ok := targetMap[tableName]; ok {+ // Already checked above.+ continue}- diff.schemaChildren = append(diff.schemaChildren, schemaNode)+ // Remove from the current since the change is to delete the schema..+ delete(currentMap, tableName)}- // Applying the diff to appliedTarget.- result := proto.Clone(appliedTarget).(*storepb.DatabaseConfig)+ result := &storepb.SchemaConfig{Name: current.Name}+ for _, v := range currentMap {+ result.TableConfigs = append(result.TableConfigs, v)+ }+ sort.Slice(result.TableConfigs, func(i, j int) bool {+ return result.TableConfigs[i].Name < result.TableConfigs[j].Name+ })+ return result+}- // The value of the schemaConfigInTarget is the index of the schemaConfig in appliedTarget.- schemaConfigInTarget := make(map[string]int)- for idx, schemaNode := range result.SchemaConfigs {- schemaConfigInTarget[schemaNode.Name] = idx+func mergeTableConfig(target, baseline, current *storepb.TableConfig) *storepb.TableConfig {+ // Avoid nil values.+ if target == nil {+ target = &storepb.TableConfig{}+ }+ if baseline == nil {+ baseline = &storepb.TableConfig{}+ }+ if current == nil {+ current = &storepb.TableConfig{}}- for _, schemaNodeInDiff := range diff.schemaChildren {- schemaInTargetIdx, ok := schemaConfigInTarget[schemaNodeInDiff.name]- if !ok {- schemaNode := &storepb.SchemaConfig{- Name: schemaNodeInDiff.name,- }- for _, tableNodeInDiff := range schemaNodeInDiff.tableChildren {- tableNode := &storepb.TableConfig{- Name: tableNodeInDiff.name,- }- for _, columnInTarget := range tableNodeInDiff.columnChildren {- columnNode := &storepb.ColumnConfig{- Name: columnInTarget.name,- SemanticTypeId: columnInTarget.semanticTypeAttributeChildren.to,- }- tableNode.ColumnConfigs = append(tableNode.ColumnConfigs, columnNode)- }- schemaNode.TableConfigs = append(schemaNode.TableConfigs, tableNode)- }- result.SchemaConfigs = append(result.SchemaConfigs, schemaNode)- continue+ targetMap, baselineMap, currentMap := buildColumnMap(target), buildColumnMap(baseline), buildColumnMap(current)+ for columnName, targetColumn := range targetMap {+ currentColumn, hasCurrent := currentMap[columnName]+ baselineColumn := baselineMap[columnName]+ if hasCurrent {+ currentMap[columnName] = mergeColumnConfig(targetColumn, baselineColumn, currentColumn)+ } else {+ currentMap[columnName] = targetColumn}-- tableConfigInTarget := make(map[string]int)- for idx, tableNode := range result.SchemaConfigs[schemaInTargetIdx].TableConfigs {- tableConfigInTarget[tableNode.Name] = idx+ }+ for tableName := range baselineMap {+ if _, ok := targetMap[tableName]; ok {+ // Already checked above.+ continue}+ // Remove from the current since the change is to delete the schema..+ delete(currentMap, tableName)+ }- for _, tableNodeInDiff := range schemaNodeInDiff.tableChildren {- tableInTargetIdx, ok := tableConfigInTarget[tableNodeInDiff.name]- if !ok {- tableNode := &storepb.TableConfig{- Name: tableNodeInDiff.name,- }+ result := &storepb.TableConfig{Name: current.Name}+ for _, v := range currentMap {+ result.ColumnConfigs = append(result.ColumnConfigs, v)+ }+ sort.Slice(result.ColumnConfigs, func(i, j int) bool {+ return result.ColumnConfigs[i].Name < result.ColumnConfigs[j].Name+ })+ return result+}- for _, columnNodeInDiff := range tableNodeInDiff.columnChildren {- columnNode := &storepb.ColumnConfig{- Name: columnNodeInDiff.name,- SemanticTypeId: columnNodeInDiff.semanticTypeAttributeChildren.to,- }- tableNode.ColumnConfigs = append(tableNode.ColumnConfigs, columnNode)- }- result.SchemaConfigs[schemaInTargetIdx].TableConfigs = append(result.SchemaConfigs[schemaInTargetIdx].TableConfigs, tableNode)- continue- }+func mergeColumnConfig(target, baseline, current *storepb.ColumnConfig) *storepb.ColumnConfig {+ if baseline == nil {+ // Baseline could be nil. When it's nil, we should set the current stale value to target value.+ return target+ }+ // Current is never nil.+ // If baseline = A, target = B, current = C, we should set merged value to B.+ // If baseline = A, target = A, current = B, we should set merged value to B since there is no change intentially.+ current = proto.Clone(current).(*storepb.ColumnConfig)+ if target.SemanticTypeId != baseline.SemanticTypeId {+ current.SemanticTypeId = target.SemanticTypeId+ }- columnConfigInTarget := make(map[string]int)- for idx, columnNode := range result.SchemaConfigs[schemaInTargetIdx].TableConfigs[tableInTargetIdx].ColumnConfigs {- columnConfigInTarget[columnNode.Name] = idx- }+ if !reflect.DeepEqual(target.Labels, baseline.Labels) {+ current.Labels = target.Labels+ }- for _, columnNodeInDiff := range tableNodeInDiff.columnChildren {- columnInTargetIdx, ok := columnConfigInTarget[columnNodeInDiff.name]- if !ok {- columnNode := &storepb.ColumnConfig{- Name: columnNodeInDiff.name,- SemanticTypeId: columnNodeInDiff.semanticTypeAttributeChildren.to,- }- result.SchemaConfigs[schemaInTargetIdx].TableConfigs[tableInTargetIdx].ColumnConfigs = append(result.SchemaConfigs[schemaInTargetIdx].TableConfigs[tableInTargetIdx].ColumnConfigs, columnNode)- continue- }+ return current+}- if columnNodeInDiff.semanticTypeAttributeChildren != nil {- result.SchemaConfigs[schemaInTargetIdx].TableConfigs[tableInTargetIdx].ColumnConfigs[columnInTargetIdx].SemanticTypeId = columnNodeInDiff.semanticTypeAttributeChildren.to- }- }- }+func buildSchemaMap(config *storepb.DatabaseConfig) map[string]*storepb.SchemaConfig {+ m := make(map[string]*storepb.SchemaConfig)+ for _, v := range config.SchemaConfigs {+ m[v.Name] = v}-- return result+ return m}-// buildColumnConfigUpdateNodeFromColumnConfig builds the column config update node from the column config, copy all the attributes.-func buildColumnConfigUpdateNodeFromColumnConfig(columnConfig *storepb.ColumnConfig) *columnConfigNode {- return &columnConfigNode{- action: updateDatabaseConfigActionUpdate,- name: columnConfig.Name,- semanticTypeAttributeChildren: &columnConfigSemanticTypeAttributeNode{- action: updateDatabaseConfigActionUpdate,- to: columnConfig.SemanticTypeId,- },+func buildTableMap(config *storepb.SchemaConfig) map[string]*storepb.TableConfig {+ m := make(map[string]*storepb.TableConfig)+ for _, v := range config.TableConfigs {+ m[v.Name] = v}+ return m}-// getEmptyColumnConfigNode returns an empty column config node, whose fields are filled with meaningless value.-func getEmptyColumnConfigNode(name string) *columnConfigNode {- return &columnConfigNode{- action: updateDatabaseConfigActionUpdate,- name: name,- semanticTypeAttributeChildren: &columnConfigSemanticTypeAttributeNode{- action: updateDatabaseConfigActionUpdate,- to: "",- },+func buildColumnMap(config *storepb.TableConfig) map[string]*storepb.ColumnConfig {+ m := make(map[string]*storepb.ColumnConfig)+ for _, v := range config.ColumnConfigs {+ m[v.Name] = v}+ return m}diff --git a/backend/runner/taskrun/database_config_merge_test.go b/backend/runner/taskrun/database_config_merge_test.goindex 38d05573c1..216b3254ce 100644--- a/backend/runner/taskrun/database_config_merge_test.go+++ b/backend/runner/taskrun/database_config_merge_test.go@@ -12,17 +12,17 @@ import (func TestUpdateDatabaseConfig(t *testing.T) {type testCase struct {- description string- databaseConfig *storepb.DatabaseConfig- baselineDatabaseConfig *storepb.DatabaseConfig- targetConfig *storepb.DatabaseConfig- expectedConfig *storepb.DatabaseConfig+ description string+ target *storepb.DatabaseConfig+ baseline *storepb.DatabaseConfig+ current *storepb.DatabaseConfig+ want *storepb.DatabaseConfig}testCases := []testCase{{description: "easy change and the target config is the same as the baseline config",- databaseConfig: &storepb.DatabaseConfig{+ target: &storepb.DatabaseConfig{Name: "db1",SchemaConfigs: []*storepb.SchemaConfig{{@@ -38,6 +38,7 @@ func TestUpdateDatabaseConfig(t *testing.T) {{Name: "b",SemanticTypeId: "id_b",+ Labels: map[string]string{"hello": "world"},},},},@@ -45,7 +46,7 @@ func TestUpdateDatabaseConfig(t *testing.T) {},},},- baselineDatabaseConfig: &storepb.DatabaseConfig{+ baseline: &storepb.DatabaseConfig{Name: "db1",SchemaConfigs: []*storepb.SchemaConfig{{@@ -64,7 +65,7 @@ func TestUpdateDatabaseConfig(t *testing.T) {},},},- targetConfig: &storepb.DatabaseConfig{+ current: &storepb.DatabaseConfig{Name: "db1",SchemaConfigs: []*storepb.SchemaConfig{{@@ -83,7 +84,7 @@ func TestUpdateDatabaseConfig(t *testing.T) {},},},- expectedConfig: &storepb.DatabaseConfig{+ want: &storepb.DatabaseConfig{Name: "db1",SchemaConfigs: []*storepb.SchemaConfig{{@@ -99,6 +100,7 @@ func TestUpdateDatabaseConfig(t *testing.T) {{Name: "b",SemanticTypeId: "id_b",+ Labels: map[string]string{"hello": "world"},},},},@@ -109,7 +111,7 @@ func TestUpdateDatabaseConfig(t *testing.T) {},{description: "if the target config has changed the same column, we should overwrite it",- databaseConfig: &storepb.DatabaseConfig{+ target: &storepb.DatabaseConfig{Name: "db1",SchemaConfigs: []*storepb.SchemaConfig{{@@ -128,7 +130,7 @@ func TestUpdateDatabaseConfig(t *testing.T) {},},},- baselineDatabaseConfig: &storepb.DatabaseConfig{+ baseline: &storepb.DatabaseConfig{Name: "db1",SchemaConfigs: []*storepb.SchemaConfig{{@@ -147,7 +149,7 @@ func TestUpdateDatabaseConfig(t *testing.T) {},},},- targetConfig: &storepb.DatabaseConfig{+ current: &storepb.DatabaseConfig{Name: "db1",SchemaConfigs: []*storepb.SchemaConfig{{@@ -166,7 +168,7 @@ func TestUpdateDatabaseConfig(t *testing.T) {},},},- expectedConfig: &storepb.DatabaseConfig{+ want: &storepb.DatabaseConfig{Name: "db1",SchemaConfigs: []*storepb.SchemaConfig{{@@ -188,7 +190,7 @@ func TestUpdateDatabaseConfig(t *testing.T) {},{description: "if the target config has changed, we should not overwrite the difference set",- databaseConfig: &storepb.DatabaseConfig{+ target: &storepb.DatabaseConfig{Name: "db1",SchemaConfigs: []*storepb.SchemaConfig{{@@ -201,6 +203,7 @@ func TestUpdateDatabaseConfig(t *testing.T) {// Modify the semantic type id to id_b.Name: "a",SemanticTypeId: "id_b",+ Labels: map[string]string{"hello": "world"},},{// Do not change.@@ -242,7 +245,7 @@ func TestUpdateDatabaseConfig(t *testing.T) {},},},- baselineDatabaseConfig: &storepb.DatabaseConfig{+ baseline: &storepb.DatabaseConfig{Name: "db1",SchemaConfigs: []*storepb.SchemaConfig{{@@ -254,6 +257,7 @@ func TestUpdateDatabaseConfig(t *testing.T) {{Name: "a",SemanticTypeId: "id_a",+ Labels: map[string]string{"world": "hello"},},{Name: "b",@@ -274,7 +278,7 @@ func TestUpdateDatabaseConfig(t *testing.T) {},},},- targetConfig: &storepb.DatabaseConfig{+ current: &storepb.DatabaseConfig{Name: "db1",SchemaConfigs: []*storepb.SchemaConfig{{@@ -306,7 +310,7 @@ func TestUpdateDatabaseConfig(t *testing.T) {},},},- expectedConfig: &storepb.DatabaseConfig{+ want: &storepb.DatabaseConfig{Name: "db1",SchemaConfigs: []*storepb.SchemaConfig{{@@ -318,6 +322,7 @@ func TestUpdateDatabaseConfig(t *testing.T) {{Name: "a",SemanticTypeId: "id_b",+ Labels: map[string]string{"hello": "world"},},{Name: "b",@@ -329,18 +334,6 @@ func TestUpdateDatabaseConfig(t *testing.T) {},},},- {- Name: "table2",- ColumnConfigs: []*storepb.ColumnConfig{- {- Name: "b",- SemanticTypeId: "id_b",- },- {- Name: "a",- },- },- },{Name: "table3",ColumnConfigs: []*storepb.ColumnConfig{@@ -363,8 +356,8 @@ func TestUpdateDatabaseConfig(t *testing.T) {a := require.New(t)for _, tc := range testCases {- got := mergeDatabaseConfig(tc.databaseConfig, tc.baselineDatabaseConfig, tc.targetConfig)- equal := proto.Equal(got, tc.expectedConfig)- a.True(equal, fmt.Sprintf("%s: \ngot:\t%%+v, \nexpected:\t%%+v", tc.description), got, tc.expectedConfig)+ got := mergeDatabaseConfig(tc.target, tc.baseline, tc.current)+ equal := proto.Equal(got, tc.want)+ a.True(equal, fmt.Sprintf("%s: \ngot:\t%%+v, \nexpected:\t%%+v", tc.description), got, tc.want)}}diff --git a/backend/runner/taskrun/executor.go b/backend/runner/taskrun/executor.goindex 60ef2eb349..23f9e79a9b 100644--- a/backend/runner/taskrun/executor.go+++ b/backend/runner/taskrun/executor.go@@ -525,11 +525,11 @@ func postMigration(ctx context.Context, stores *store.Store, activityManager *acif err != nil {slog.Error("Failed to get sheet from store", slog.Int("sheetID", *sheetID), log.BBError(err))} else if sheet.Payload != nil && (sheet.Payload.DatabaseConfig != nil || sheet.Payload.BaselineDatabaseConfig != nil) {- effectiveDatabaseSchema, err := stores.GetDBSchema(ctx, *task.DatabaseID)+ databaseSchema, err := stores.GetDBSchema(ctx, *task.DatabaseID)if err != nil {slog.Error("Failed to get database config from store", slog.Int("sheetID", *sheetID), slog.Int("databaseUID", *task.DatabaseID), log.BBError(err))} else {- updatedDatabaseConfig := mergeDatabaseConfig(sheet.Payload.DatabaseConfig, sheet.Payload.BaselineDatabaseConfig, effectiveDatabaseSchema.Config)+ updatedDatabaseConfig := mergeDatabaseConfig(sheet.Payload.DatabaseConfig, sheet.Payload.BaselineDatabaseConfig, databaseSchema.Config)err = stores.UpdateDBSchema(ctx, *task.DatabaseID, &store.UpdateDBSchemaMessage{Config: updatedDatabaseConfig,}, api.SystemBotID)