Skip to content

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

chore(branch): use parent branch baseline schema as origin (#8359)

boojack7798ded3d88f
diff --git a/frontend/src/components/SchemaEditorV1/index.vue b/frontend/src/components/SchemaEditorV1/index.vue
index 2420900409..6b366a59df 100644
--- a/frontend/src/components/SchemaEditorV1/index.vue
+++ b/frontend/src/components/SchemaEditorV1/index.vue
@@ -21,8 +21,12 @@
import { Splitpanes, Pane } from "splitpanes";
import { onMounted, watch, reactive } from "vue";
import { useSchemaEditorV1Store, useSettingV1Store } from "@/store";
+import { useSchemaDesignStore } from "@/store/modules/schemaDesign";
import { ComposedProject, ComposedDatabase } from "@/types";
-import { SchemaDesign } from "@/types/proto/v1/schema_design_service";
+import {
+ SchemaDesign,
+ SchemaDesign_Type,
+} from "@/types/proto/v1/schema_design_service";
import Aside from "./Aside/index.vue";
import Editor from "./Editor.vue";
import { convertBranchToBranchSchema } from "./utils/branch";
@@ -41,12 +45,26 @@ interface LocalState {
}
const settingStore = useSettingV1Store();
-
const schemaEditorV1Store = useSchemaEditorV1Store();
+const schemaDesignStore = useSchemaDesignStore();
const state = reactive<LocalState>({
initialized: false,
});
+const prepareBranchContext = async () => {
+ if (props.resourceType !== "branch" || !props.branches) {
+ return;
+ }
+ for (const branch of props.branches) {
+ if (branch.type === SchemaDesign_Type.PERSONAL_DRAFT) {
+ // Prepare parent branch for personal draft.
+ await schemaDesignStore.getOrFetchSchemaDesignByName(
+ branch.baselineSheetName
+ );
+ }
+ }
+};
+
const updateSchemaEditorState = () => {
schemaEditorV1Store.setState({
project: props.project,
@@ -93,6 +111,8 @@ const updateSchemaEditorState = () => {
// Prepare schema template contexts.
onMounted(async () => {
await settingStore.getOrFetchSettingByName("bb.workspace.schema-template");
+ await prepareBranchContext();
+
updateSchemaEditorState();
state.initialized = true;
});
diff --git a/frontend/src/components/SchemaEditorV1/utils/branch.ts b/frontend/src/components/SchemaEditorV1/utils/branch.ts
index 8a608e1d68..c73d800874 100644
--- a/frontend/src/components/SchemaEditorV1/utils/branch.ts
+++ b/frontend/src/components/SchemaEditorV1/utils/branch.ts
@@ -1,4 +1,8 @@
-import { SchemaDesign } from "@/types/proto/v1/schema_design_service";
+import { useSchemaDesignStore } from "@/store/modules/schemaDesign";
+import {
+ SchemaDesign,
+ SchemaDesign_Type,
+} from "@/types/proto/v1/schema_design_service";
import {
BranchSchema,
convertSchemaMetadataList,
@@ -8,13 +12,25 @@ import { rebuildEditableSchemas } from "./metadataV1";
export const convertBranchToBranchSchema = (
branch: SchemaDesign
): BranchSchema => {
- const originalSchemas = convertSchemaMetadataList(
- branch.baselineSchemaMetadata?.schemas || []
- );
+ let originalSchemas = [];
+ // For personal branches, we use its parent branch's schema as the original schema in editing state.
+ if (branch.type === SchemaDesign_Type.PERSONAL_DRAFT) {
+ const parentBranch = useSchemaDesignStore().getSchemaDesignByName(
+ branch.baselineSheetName
+ );
+ originalSchemas = convertSchemaMetadataList(
+ parentBranch?.baselineSchemaMetadata?.schemas || []
+ );
+ } else {
+ originalSchemas = convertSchemaMetadataList(
+ branch.baselineSchemaMetadata?.schemas || []
+ );
+ }
const editableSchemas = rebuildEditableSchemas(
originalSchemas,
branch.schemaMetadata?.schemas || []
);
+
return {
branch,
schemaList: editableSchemas,