Skip to content

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

chore: update branch update (#9678)

Danny Xuf122f7e21b65
diff --git a/backend/api/v1/branch_service.go b/backend/api/v1/branch_service.go
index b8b4ccb9b5..ac68d087ce 100644
--- a/backend/api/v1/branch_service.go
+++ b/backend/api/v1/branch_service.go
@@ -279,13 +279,12 @@ func (s *BranchService) UpdateBranch(ctx context.Context, request *v1pb.UpdateBr
headUpdate := branch.Head
hasHeadUpdate := false
+ // The update includes the following cases.
+ // 1) schema_metadata: update the current branch. We need to update schema accordingly, or we lazily update it till merge branch.
+ // 2) baseline_database and schema: rebase the baseline schema metadata and baseline schema. Use schema to create schema_metadata.
+
// TODO(d): this section needs some clarifications for merging branches.
- if slices.Contains(request.UpdateMask.Paths, "schema") && slices.Contains(request.UpdateMask.Paths, "metadata") {
- headUpdate.Schema = []byte(request.Branch.Schema)
- sanitizeBranchSchemaMetadata(request.Branch)
- // TODO(d): update database metadata and config.
- hasHeadUpdate = true
- } else if slices.Contains(request.UpdateMask.Paths, "schema") {
+ if slices.Contains(request.UpdateMask.Paths, "schema") {
headUpdate.Schema = []byte(request.Branch.Schema)
hasHeadUpdate = true
// TODO(d): convert schema to metadata.
@@ -293,7 +292,7 @@ func (s *BranchService) UpdateBranch(ctx context.Context, request *v1pb.UpdateBr
// if _, err := transformSchemaStringToDatabaseMetadata(schemaDesign.Engine, *sheetUpdate.Statement); err != nil {
// return nil, status.Errorf(codes.Internal, fmt.Sprintf("failed to transform schema string to database metadata: %v", err))
// }
- } else if slices.Contains(request.UpdateMask.Paths, "metadata") {
+ } else if slices.Contains(request.UpdateMask.Paths, "schema_metadata") {
sanitizeBranchSchemaMetadata(request.Branch)
// schema, err := getDesignSchema(schemaDesign.Engine, schemaDesign.BaselineSchema, schemaDesign.SchemaMetadata)
// if err != nil {
diff --git a/frontend/src/components/Branch/BranchDetailView.vue b/frontend/src/components/Branch/BranchDetailView.vue
index 19997f2c43..aa782d04f4 100644
--- a/frontend/src/components/Branch/BranchDetailView.vue
+++ b/frontend/src/components/Branch/BranchDetailView.vue
@@ -376,7 +376,7 @@ const handleSaveBranch = async () => {
return;
}
if (!isEqual(mergedMetadata, branch.value.schemaMetadata)) {
- updateMask.push("metadata");
+ updateMask.push("schema_metadata");
}
state.isSaving = true;
diff --git a/frontend/src/components/Branch/MergeBranchPanel.vue b/frontend/src/components/Branch/MergeBranchPanel.vue
index fd11159b0b..e694287ca3 100644
--- a/frontend/src/components/Branch/MergeBranchPanel.vue
+++ b/frontend/src/components/Branch/MergeBranchPanel.vue
@@ -82,18 +82,9 @@ import { Status } from "nice-grpc-common";
import { computed, reactive, ref, watch } from "vue";
import { useI18n } from "vue-i18n";
import { Drawer, DrawerContent } from "@/components/v2";
-import { pushNotification, useSheetV1Store } from "@/store";
+import { pushNotification } from "@/store";
import { useBranchStore } from "@/store/modules/branch";
-import {
- getProjectAndBranchId,
- projectNamePrefix,
-} from "@/store/modules/v1/common";
import { Branch } from "@/types/proto/v1/branch_service";
-import {
- Sheet_Source,
- Sheet_Type,
- Sheet_Visibility,
-} from "@/types/proto/v1/sheet_service";
import { DiffEditor } from "../MonacoEditor";
interface LocalState {
@@ -119,7 +110,6 @@ const state = reactive<LocalState>({
});
const { t } = useI18n();
const dialog = useDialog();
-const sheetStore = useSheetV1Store();
const branchStore = useBranchStore();
const isLoadingSourceBranch = ref(false);
const isLoadingTargetBranch = ref(false);
@@ -166,29 +156,14 @@ const targetBranchFilter = (branch: Branch) => {
};
const handleSaveDraft = async (ignoreNotify?: boolean) => {
- const updateMask = ["schema", "parent_branch"];
- const [projectName] = getProjectAndBranchId(sourceBranch.value.name);
- // Create a baseline sheet for the schema design.
- const baselineSheet = await sheetStore.createSheet(
- `${projectNamePrefix}${projectName}`,
- {
- title: `baseline schema of ${targetBranch.value.branchId}`,
- database: targetBranch.value.baselineDatabase,
- content: new TextEncoder().encode(targetBranch.value.schema),
- visibility: Sheet_Visibility.VISIBILITY_PROJECT,
- source: Sheet_Source.SOURCE_BYTEBASE_ARTIFACT,
- type: Sheet_Type.TYPE_SQL,
- }
- );
-
+ const updateMask = ["schema"];
// Update the schema design draft first.
+ // TODO(d): rebase the baseline schema metadata.
await branchStore.updateBranch(
Branch.fromPartial({
name: sourceBranch.value.name,
- engine: sourceBranch.value.engine,
baselineDatabase: sourceBranch.value.baselineDatabase,
schema: state.editingSchema,
- parentBranch: baselineSheet.name,
}),
updateMask
);