Skip to content

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

chore: improve branch (#9717)

Danny Xu423bbf858459
diff --git a/frontend/src/components/Branch/BranchCreateView.vue b/frontend/src/components/Branch/BranchCreateView.vue
index e3f0b1db3c..631bfdfa77 100644
--- a/frontend/src/components/Branch/BranchCreateView.vue
+++ b/frontend/src/components/Branch/BranchCreateView.vue
@@ -7,7 +7,7 @@
$t("database.branch-name")
}}</span>
<NInput
- v-model:value="branchTitle"
+ v-model:value="branchId"
type="text"
class="!w-60 text-sm"
:placeholder="'feature/add-billing'"
@@ -75,10 +75,7 @@ import {
useSchemaEditorV1Store,
} from "@/store";
import { useBranchStore } from "@/store/modules/branch";
-import {
- databaseNamePrefix,
- getProjectAndBranchId,
-} from "@/store/modules/v1/common";
+import { databaseNamePrefix } from "@/store/modules/v1/common";
import { Branch } from "@/types/proto/v1/branch_service";
import { DatabaseMetadata } from "@/types/proto/v1/database_service";
import { projectV1Slug } from "@/utils";
@@ -119,7 +116,7 @@ const state = reactive<LocalState>({
branch: Branch.fromPartial({}),
isCreating: false,
});
-const branchTitle = ref<string>("");
+const branchId = ref<string>("");
const refreshId = ref<string>("");
const project = computed(() => {
@@ -164,7 +161,7 @@ watch(
}
);
-const prepareSchemaDesign = async () => {
+const prepareBranch = async () => {
if (
state.baselineSchema.databaseId &&
state.baselineSchema.databaseMetadata
@@ -182,9 +179,7 @@ const prepareSchemaDesign = async () => {
};
const allowConfirm = computed(() => {
- return (
- branchTitle.value && state.baselineSchema.databaseId && !state.isCreating
- );
+ return branchId.value && state.baselineSchema.databaseId && !state.isCreating;
});
const confirmText = computed(() => {
@@ -199,7 +194,7 @@ const handleBaselineSchemaChange = async (baselineSchema: BaselineSchema) => {
state.baselineSchema = baselineSchema;
console.time("prepareSchemaDesign");
state.loading = true;
- state.branch = await prepareSchemaDesign();
+ state.branch = await prepareBranch();
state.loading = false;
console.timeEnd("prepareSchemaDesign");
};
@@ -209,7 +204,7 @@ const handleConfirm = async () => {
return;
}
- if (!validateBranchName(branchTitle.value)) {
+ if (!validateBranchName(branchId.value)) {
pushNotification({
module: "bytebase",
style: "CRITICAL",
@@ -231,11 +226,10 @@ const handleConfirm = async () => {
state.isCreating = true;
const baselineDatabase = `${database.instanceEntity.name}/${databaseNamePrefix}${database.databaseName}`;
- let createdSchemaDesign;
if (!state.parentBranchName) {
- createdSchemaDesign = await branchStore.createBranch(
+ await branchStore.createBranch(
project.value.name,
- branchTitle.value,
+ branchId.value,
Branch.fromPartial({
baselineDatabase: baselineDatabase,
})
@@ -245,10 +239,12 @@ const handleConfirm = async () => {
state.parentBranchName,
false /* useCache */
);
- createdSchemaDesign = await branchStore.createBranchDraft(
+ await branchStore.createBranch(
project.value.name,
- branchTitle.value,
- parentBranch.name
+ branchId.value,
+ Branch.fromPartial({
+ parentBranch: parentBranch.name,
+ })
);
}
state.isCreating = false;
@@ -259,12 +255,11 @@ const handleConfirm = async () => {
});
// Go to branch detail page after created.
- const [_, branchId] = getProjectAndBranchId(createdSchemaDesign.name);
router.replace({
name: "workspace.project.branch.detail",
params: {
projectSlug: projectV1Slug(project.value),
- branchName: branchId,
+ branchName: branchId.value,
},
});
};
diff --git a/frontend/src/components/Branch/MergeBranchPanel.vue b/frontend/src/components/Branch/MergeBranchPanel.vue
index 009cb4f245..92b4456f4a 100644
--- a/frontend/src/components/Branch/MergeBranchPanel.vue
+++ b/frontend/src/components/Branch/MergeBranchPanel.vue
@@ -110,7 +110,7 @@ const emit = defineEmits<{
const state = reactive<LocalState>({
targetBranchName: "",
editingSchema: "",
- deleteBranchAfterMerged: true,
+ deleteBranchAfterMerged: false,
});
const { t } = useI18n();
const dialog = useDialog();
@@ -194,7 +194,7 @@ const handleMergeBranch = async () => {
});
} catch (error: any) {
// If there is conflict, we need to show the conflict and let user resolve it.
- if (error.code === Status.FAILED_PRECONDITION) {
+ if (error.code === Status.ABORTED) {
dialog.create({
negativeText: t("schema-designer.save-draft"),
positiveText: t("schema-designer.diff-editor.resolve"),
diff --git a/frontend/src/store/modules/branch.ts b/frontend/src/store/modules/branch.ts
index 047dabee7f..332b218ffb 100644
--- a/frontend/src/store/modules/branch.ts
+++ b/frontend/src/store/modules/branch.ts
@@ -36,20 +36,6 @@ export const useBranchStore = defineStore("schema_design", () => {
return createdBranch;
};
- const createBranchDraft = async (
- projectName: string,
- branchId: string,
- parentBranch: string
- ) => {
- return createBranch(
- projectName,
- branchId,
- Branch.fromPartial({
- parentBranch: parentBranch,
- })
- );
- };
-
const updateBranch = async (branch: Branch, updateMask: string[]) => {
const updatedBranch = await branchServiceClient.updateBranch({
branch,
@@ -112,7 +98,6 @@ export const useBranchStore = defineStore("schema_design", () => {
return {
fetchBranchList,
createBranch,
- createBranchDraft,
updateBranch,
mergeBranch,
fetchBranchByName,
diff --git a/frontend/src/views/branch/BranchDetail.vue b/frontend/src/views/branch/BranchDetail.vue
index 16658d99aa..b57beed7cc 100644
--- a/frontend/src/views/branch/BranchDetail.vue
+++ b/frontend/src/views/branch/BranchDetail.vue
@@ -50,11 +50,11 @@ watch(
}
// Prepare branch name from route params.
- const sheetId = (route.params.branchName as string) || "";
- if (!sheetId || !project.value) {
+ const branchId = (route.params.branchName as string) || "";
+ if (!branchId || !project.value) {
return;
}
- branchFullName.value = `${project.value.name}/branches/${sheetId}`;
+ branchFullName.value = `${project.value.name}/branches/${branchId}`;
},
{
immediate: true,