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: source branch (#13260)
h3n4l1f1537803ba9
diff --git a/backend/api/v1/branch_service.go b/backend/api/v1/branch_service.goindex 75f090f96f..3f147e1cf1 100644--- a/backend/api/v1/branch_service.go+++ b/backend/api/v1/branch_service.go@@ -1554,7 +1554,7 @@ func updateDatabaseConfigLastModifierForMerge(baseMetadata *storepb.DatabaseScheif baseTable == nil {//nolintnewBaseTableConfig := proto.Clone(headTableConfig).(*storepb.TableConfig)- newBaseTableConfig.SourceBranch = ""+ newBaseTableConfig.SourceBranch = headTableConfig.SourceBranchnewBaseTableConfig.Updater = headTableConfig.UpdaternewBaseTableConfig.UpdateTime = nownewBaseTableConfigs = append(newBaseTableConfigs, newBaseTableConfig)@@ -1567,7 +1567,7 @@ func updateDatabaseConfigLastModifierForMerge(baseMetadata *storepb.DatabaseSchebaseTableConfig = initTableConfig(baseTable.GetProto(), "", "", now)}if !cmp.Equal(headTable, baseTable.GetProto(), protocmp.Transform()) {- baseTableConfig.SourceBranch = ""+ baseTableConfig.SourceBranch = headTableConfig.SourceBranchbaseTableConfig.Updater = headTableConfig.UpdaterbaseTableConfig.UpdateTime = now}@@ -1592,7 +1592,7 @@ func updateDatabaseConfigLastModifierForMerge(baseMetadata *storepb.DatabaseScheif baseFunction == nil {//nolintnewBaseFunctionConfig := proto.Clone(headFunctionConfig).(*storepb.FunctionConfig)- newBaseFunctionConfig.SourceBranch = ""+ newBaseFunctionConfig.SourceBranch = headFunctionConfig.SourceBranchnewBaseFunctionConfig.Updater = headFunctionConfig.UpdaternewBaseFunctionConfig.UpdateTime = nownewBaseFunctionConfigs = append(newBaseFunctionConfigs, newBaseFunctionConfig)@@ -1605,7 +1605,7 @@ func updateDatabaseConfigLastModifierForMerge(baseMetadata *storepb.DatabaseSchebaseFunctionConfig = initFunctionConfig(baseFunction.GetProto(), "", "", now)}if !cmp.Equal(headFunction, baseFunction.GetProto(), protocmp.Transform()) {- baseFunctionConfig.SourceBranch = ""+ baseFunctionConfig.SourceBranch = headFunctionConfig.SourceBranchbaseFunctionConfig.Updater = headFunctionConfig.UpdaterbaseFunctionConfig.UpdateTime = now}@@ -1630,7 +1630,7 @@ func updateDatabaseConfigLastModifierForMerge(baseMetadata *storepb.DatabaseScheif baseView == nil {//nolintnewBaseViewConfig := proto.Clone(headViewConfig).(*storepb.ViewConfig)- newBaseViewConfig.SourceBranch = ""+ newBaseViewConfig.SourceBranch = headViewConfig.SourceBranchnewBaseViewConfig.Updater = headViewConfig.UpdaternewBaseViewConfig.UpdateTime = nownewBaseViewConfigs = append(newBaseViewConfigs, newBaseViewConfig)@@ -1643,7 +1643,7 @@ func updateDatabaseConfigLastModifierForMerge(baseMetadata *storepb.DatabaseSchebaseViewConfig = initViewConfig(baseView.GetProto(), "", "", now)}if !cmp.Equal(headView, baseView.GetProto(), protocmp.Transform()) {- baseViewConfig.SourceBranch = ""+ baseViewConfig.SourceBranch = headViewConfig.SourceBranchbaseViewConfig.Updater = headViewConfig.UpdaterbaseViewConfig.UpdateTime = now}@@ -1668,7 +1668,7 @@ func updateDatabaseConfigLastModifierForMerge(baseMetadata *storepb.DatabaseScheif baseProcedure == nil {//nolintnewBaseProcedureConfig := proto.Clone(headProcedureConfig).(*storepb.ProcedureConfig)- newBaseProcedureConfig.SourceBranch = ""+ newBaseProcedureConfig.SourceBranch = headProcedureConfig.SourceBranchnewBaseProcedureConfig.Updater = headProcedureConfig.UpdaternewBaseProcedureConfig.UpdateTime = nownewBaseProcedureConfigs = append(newBaseProcedureConfigs, newBaseProcedureConfig)@@ -1677,7 +1677,7 @@ func updateDatabaseConfigLastModifierForMerge(baseMetadata *storepb.DatabaseSche// Modified procedure, set the last updater as head in base.baseProcedureConfig := baseProcedureConfigMap[headProcedure.Name]if !cmp.Equal(headProcedure, baseProcedure.GetProto(), protocmp.Transform()) {- baseProcedureConfig.SourceBranch = ""+ baseProcedureConfig.SourceBranch = headProcedureConfig.SourceBranchbaseProcedureConfig.Updater = headProcedureConfig.UpdaterbaseProcedureConfig.UpdateTime = now}diff --git a/backend/api/v1/database_converter.go b/backend/api/v1/database_converter.goindex f2334092a8..cf533f221a 100644--- a/backend/api/v1/database_converter.go+++ b/backend/api/v1/database_converter.go@@ -749,25 +749,28 @@ func convertV1DatabaseConfig(ctx context.Context, databaseConfig *v1pb.DatabaseCfunc convertV1ViewConfig(ctx context.Context, view *v1pb.ViewConfig, optionalStores *store.Store) *storepb.ViewConfig {return &storepb.ViewConfig{- Name: view.Name,- Updater: getUpdaterFromEmail(ctx, view.Updater, optionalStores),- UpdateTime: view.UpdateTime,+ Name: view.Name,+ Updater: getUpdaterFromEmail(ctx, view.Updater, optionalStores),+ UpdateTime: view.UpdateTime,+ SourceBranch: view.SourceBranch,}}func convertV1FunctionConfig(ctx context.Context, function *v1pb.FunctionConfig, optionalStores *store.Store) *storepb.FunctionConfig {return &storepb.FunctionConfig{- Name: function.Name,- Updater: getUpdaterFromEmail(ctx, function.Updater, optionalStores),- UpdateTime: function.UpdateTime,+ Name: function.Name,+ Updater: getUpdaterFromEmail(ctx, function.Updater, optionalStores),+ UpdateTime: function.UpdateTime,+ SourceBranch: function.SourceBranch,}}func convertV1ProcedureConfig(ctx context.Context, procedure *v1pb.ProcedureConfig, optionalStores *store.Store) *storepb.ProcedureConfig {return &storepb.ProcedureConfig{- Name: procedure.Name,- Updater: getUpdaterFromEmail(ctx, procedure.Updater, optionalStores),- UpdateTime: procedure.UpdateTime,+ Name: procedure.Name,+ Updater: getUpdaterFromEmail(ctx, procedure.Updater, optionalStores),+ UpdateTime: procedure.UpdateTime,+ SourceBranch: procedure.SourceBranch,}}@@ -777,6 +780,7 @@ func convertV1TableConfig(ctx context.Context, table *v1pb.TableConfig, optionalClassificationId: table.ClassificationId,Updater: getUpdaterFromEmail(ctx, table.Updater, optionalStores),UpdateTime: table.UpdateTime,+ SourceBranch: table.SourceBranch,}for _, column := range table.ColumnConfigs {if column == nil {diff --git a/backend/utils/database_config_merge.go b/backend/utils/database_config_merge.goindex 93f20eb24b..fcc49c4890 100644--- a/backend/utils/database_config_merge.go+++ b/backend/utils/database_config_merge.go@@ -136,29 +136,32 @@ func mergeSchemaConfig(target, baseline, current *storepb.SchemaConfig) *storepb}func mergeFunctionConfig(target, baseline, current *storepb.FunctionConfig) *storepb.FunctionConfig {- lastUpdater, lastUpdateTime := getLastUpdater(target.Updater, target.UpdateTime, baseline.Updater, current.Updater, current.UpdateTime)+ lastUpdater, lastUpdateTime, sourceBranch := getLastUpdaterAndSourceBranch(target.Updater, target.UpdateTime, target.SourceBranch, baseline.Updater, current.Updater, current.UpdateTime, current.SourceBranch)return &storepb.FunctionConfig{- Name: current.Name,- Updater: lastUpdater,- UpdateTime: lastUpdateTime,+ Name: current.Name,+ Updater: lastUpdater,+ UpdateTime: lastUpdateTime,+ SourceBranch: sourceBranch,}}func mergeProcedureConfig(target, baseline, current *storepb.ProcedureConfig) *storepb.ProcedureConfig {- lastUpdater, lastUpdateTime := getLastUpdater(target.Updater, target.UpdateTime, baseline.Updater, current.Updater, current.UpdateTime)+ lastUpdater, lastUpdateTime, sourceBranch := getLastUpdaterAndSourceBranch(target.Updater, target.UpdateTime, target.SourceBranch, baseline.Updater, current.Updater, current.UpdateTime, current.SourceBranch)return &storepb.ProcedureConfig{- Name: current.Name,- Updater: lastUpdater,- UpdateTime: lastUpdateTime,+ Name: current.Name,+ Updater: lastUpdater,+ UpdateTime: lastUpdateTime,+ SourceBranch: sourceBranch,}}func mergeViewConfig(target, baseline, current *storepb.ViewConfig) *storepb.ViewConfig {- lastUpdater, lastUpdateTime := getLastUpdater(target.Updater, target.UpdateTime, baseline.Updater, current.Updater, current.UpdateTime)+ lastUpdater, lastUpdateTime, sourceBranch := getLastUpdaterAndSourceBranch(target.Updater, target.UpdateTime, target.SourceBranch, baseline.Updater, current.Updater, current.UpdateTime, current.SourceBranch)return &storepb.ViewConfig{- Name: current.Name,- Updater: lastUpdater,- UpdateTime: lastUpdateTime,+ Name: current.Name,+ Updater: lastUpdater,+ UpdateTime: lastUpdateTime,+ SourceBranch: sourceBranch,}}@@ -194,9 +197,10 @@ func mergeTableConfig(target, baseline, current *storepb.TableConfig) *storepb.T}result := &storepb.TableConfig{Name: current.Name, ClassificationId: current.ClassificationId}- lastUpdater, lastUpdateTime := getLastUpdater(target.Updater, target.UpdateTime, baseline.Updater, current.Updater, current.UpdateTime)+ lastUpdater, lastUpdateTime, sourceBranch := getLastUpdaterAndSourceBranch(target.Updater, target.UpdateTime, target.SourceBranch, baseline.Updater, current.Updater, current.UpdateTime, current.SourceBranch)result.Updater = lastUpdaterresult.UpdateTime = lastUpdateTime+ result.SourceBranch = sourceBranchfor _, v := range currentMap {result.ColumnConfigs = append(result.ColumnConfigs, v)}@@ -279,9 +283,9 @@ func buildColumnMap(config *storepb.TableConfig) map[string]*storepb.ColumnConfireturn m}-func getLastUpdater(target string, targetTime *timestamppb.Timestamp, baseline string, current string, currentTime *timestamppb.Timestamp) (string, *timestamppb.Timestamp) {+func getLastUpdaterAndSourceBranch(target string, targetTime *timestamppb.Timestamp, targetBranch string, baseline string, current string, currentTime *timestamppb.Timestamp, currentBranch string) (string, *timestamppb.Timestamp, string) {if target == baseline {- return current, currentTime+ return current, currentTime, currentBranch}- return target, targetTime+ return target, targetTime, targetBranch}