Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat: source branch (#13260)

h3n4l1f1537803ba9
diff --git a/backend/api/v1/branch_service.go b/backend/api/v1/branch_service.go
index 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.DatabaseSche
if baseTable == nil {
//nolint
newBaseTableConfig := proto.Clone(headTableConfig).(*storepb.TableConfig)
- newBaseTableConfig.SourceBranch = ""
+ newBaseTableConfig.SourceBranch = headTableConfig.SourceBranch
newBaseTableConfig.Updater = headTableConfig.Updater
newBaseTableConfig.UpdateTime = now
newBaseTableConfigs = append(newBaseTableConfigs, newBaseTableConfig)
@@ -1567,7 +1567,7 @@ func updateDatabaseConfigLastModifierForMerge(baseMetadata *storepb.DatabaseSche
baseTableConfig = initTableConfig(baseTable.GetProto(), "", "", now)
}
if !cmp.Equal(headTable, baseTable.GetProto(), protocmp.Transform()) {
- baseTableConfig.SourceBranch = ""
+ baseTableConfig.SourceBranch = headTableConfig.SourceBranch
baseTableConfig.Updater = headTableConfig.Updater
baseTableConfig.UpdateTime = now
}
@@ -1592,7 +1592,7 @@ func updateDatabaseConfigLastModifierForMerge(baseMetadata *storepb.DatabaseSche
if baseFunction == nil {
//nolint
newBaseFunctionConfig := proto.Clone(headFunctionConfig).(*storepb.FunctionConfig)
- newBaseFunctionConfig.SourceBranch = ""
+ newBaseFunctionConfig.SourceBranch = headFunctionConfig.SourceBranch
newBaseFunctionConfig.Updater = headFunctionConfig.Updater
newBaseFunctionConfig.UpdateTime = now
newBaseFunctionConfigs = append(newBaseFunctionConfigs, newBaseFunctionConfig)
@@ -1605,7 +1605,7 @@ func updateDatabaseConfigLastModifierForMerge(baseMetadata *storepb.DatabaseSche
baseFunctionConfig = initFunctionConfig(baseFunction.GetProto(), "", "", now)
}
if !cmp.Equal(headFunction, baseFunction.GetProto(), protocmp.Transform()) {
- baseFunctionConfig.SourceBranch = ""
+ baseFunctionConfig.SourceBranch = headFunctionConfig.SourceBranch
baseFunctionConfig.Updater = headFunctionConfig.Updater
baseFunctionConfig.UpdateTime = now
}
@@ -1630,7 +1630,7 @@ func updateDatabaseConfigLastModifierForMerge(baseMetadata *storepb.DatabaseSche
if baseView == nil {
//nolint
newBaseViewConfig := proto.Clone(headViewConfig).(*storepb.ViewConfig)
- newBaseViewConfig.SourceBranch = ""
+ newBaseViewConfig.SourceBranch = headViewConfig.SourceBranch
newBaseViewConfig.Updater = headViewConfig.Updater
newBaseViewConfig.UpdateTime = now
newBaseViewConfigs = append(newBaseViewConfigs, newBaseViewConfig)
@@ -1643,7 +1643,7 @@ func updateDatabaseConfigLastModifierForMerge(baseMetadata *storepb.DatabaseSche
baseViewConfig = initViewConfig(baseView.GetProto(), "", "", now)
}
if !cmp.Equal(headView, baseView.GetProto(), protocmp.Transform()) {
- baseViewConfig.SourceBranch = ""
+ baseViewConfig.SourceBranch = headViewConfig.SourceBranch
baseViewConfig.Updater = headViewConfig.Updater
baseViewConfig.UpdateTime = now
}
@@ -1668,7 +1668,7 @@ func updateDatabaseConfigLastModifierForMerge(baseMetadata *storepb.DatabaseSche
if baseProcedure == nil {
//nolint
newBaseProcedureConfig := proto.Clone(headProcedureConfig).(*storepb.ProcedureConfig)
- newBaseProcedureConfig.SourceBranch = ""
+ newBaseProcedureConfig.SourceBranch = headProcedureConfig.SourceBranch
newBaseProcedureConfig.Updater = headProcedureConfig.Updater
newBaseProcedureConfig.UpdateTime = now
newBaseProcedureConfigs = 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.SourceBranch
baseProcedureConfig.Updater = headProcedureConfig.Updater
baseProcedureConfig.UpdateTime = now
}
diff --git a/backend/api/v1/database_converter.go b/backend/api/v1/database_converter.go
index 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.DatabaseC
func 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, optional
ClassificationId: 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.go
index 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 = lastUpdater
result.UpdateTime = lastUpdateTime
+ result.SourceBranch = sourceBranch
for _, v := range currentMap {
result.ColumnConfigs = append(result.ColumnConfigs, v)
}
@@ -279,9 +283,9 @@ func buildColumnMap(config *storepb.TableConfig) map[string]*storepb.ColumnConfi
return 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
}