Skip to content

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

chore: update branching (#7839)

boojack54465895fce9
diff --git a/frontend/src/components/BranchTablePanel.vue b/frontend/src/components/BranchTablePanel.vue
index 006e49ba81..5cf1556016 100644
--- a/frontend/src/components/BranchTablePanel.vue
+++ b/frontend/src/components/BranchTablePanel.vue
@@ -15,6 +15,7 @@
<SchemaDesignTable
v-if="ready"
:schema-designs="sortedSchemaDesignList"
+ :hide-project-column="hideProjectColumn"
@click="handleSchemaDesignItemClick"
/>
<div v-else class="w-full h-[20rem] flex items-center justify-center">
@@ -54,6 +55,7 @@ import { SchemaDesign } from "@/types/proto/v1/schema_design_service";
const props = defineProps<{
projectId?: string;
+ hideProjectColumn?: boolean;
}>();
interface LocalState {
diff --git a/frontend/src/components/ProjectBranchesPanel.vue b/frontend/src/components/ProjectBranchesPanel.vue
index 19b4fe2740..32e416b890 100644
--- a/frontend/src/components/ProjectBranchesPanel.vue
+++ b/frontend/src/components/ProjectBranchesPanel.vue
@@ -1,5 +1,5 @@
<template>
- <BranchTablePanel :project-id="projectId" />
+ <BranchTablePanel :project-id="projectId" :hide-project-column="true" />
</template>
<script lang="ts" setup>
diff --git a/frontend/src/components/SchemaDesigner/BaselineSchemaSelector.vue b/frontend/src/components/SchemaDesigner/BaselineSchemaSelector.vue
index 6716bfcb88..b10265dabb 100644
--- a/frontend/src/components/SchemaDesigner/BaselineSchemaSelector.vue
+++ b/frontend/src/components/SchemaDesigner/BaselineSchemaSelector.vue
@@ -9,6 +9,7 @@
<EnvironmentSelect
class="!w-60 mr-4 shrink-0"
name="environment"
+ :disabled="props.readonly"
:selected-id="state.environmentId"
:select-default="false"
@select-environment-id="handleEnvironmentSelect"
@@ -17,6 +18,7 @@
class="!w-128"
:selected-id="state.databaseId ?? String(UNKNOWN_ID)"
:mode="'USER'"
+ :disabled="props.readonly"
:environment-id="state.environmentId"
:project-id="props.projectId"
:engine-type-list="allowedEngineTypeList"
@@ -46,6 +48,7 @@
>
<BBSelect
class="w-full"
+ :disabled="props.readonly"
:selected-item="state.changeHistory"
:item-list="
databaseChangeHistoryList(state.databaseId as string)
@@ -113,6 +116,7 @@ interface BaselineSchema {
const props = defineProps<{
projectId?: string;
baselineSchema?: BaselineSchema;
+ readonly?: boolean;
}>();
const emit = defineEmits<{
diff --git a/frontend/src/components/SchemaDesigner/CreateSchemaDesignPanel.vue b/frontend/src/components/SchemaDesigner/CreateSchemaDesignPanel.vue
index 88ae442554..ad9ffeec50 100644
--- a/frontend/src/components/SchemaDesigner/CreateSchemaDesignPanel.vue
+++ b/frontend/src/components/SchemaDesigner/CreateSchemaDesignPanel.vue
@@ -27,10 +27,12 @@
}}</span>
<BBTextField
class="w-60 text-sm"
- :value="state.schemaDesignName"
- :placeholder="$t('database.branch-name')"
+ :value="state.schemaDesignTitle"
+ :placeholder="'feature/add-billing'"
@input="
- state.schemaDesignName = ($event.target as HTMLInputElement).value
+ state.schemaDesignTitle = (
+ $event.target as HTMLInputElement
+ ).value
"
/>
</div>
@@ -90,6 +92,7 @@ import {
} from "@/store";
import { useSchemaDesignStore } from "@/store/modules/schemaDesign";
import { databaseNamePrefix } from "@/store/modules/v1/common";
+import { UNKNOWN_ID } from "@/types";
import {
ChangeHistory,
DatabaseMetadata,
@@ -104,7 +107,7 @@ import {
Sheet_Visibility,
} from "@/types/proto/v1/sheet_service";
import BaselineSchemaSelector from "./BaselineSchemaSelector.vue";
-import { mergeSchemaEditToMetadata } from "./common/util";
+import { mergeSchemaEditToMetadata, validateBranchName } from "./common/util";
import SchemaDesigner from "./index.vue";
interface BaselineSchema {
@@ -115,7 +118,7 @@ interface BaselineSchema {
interface LocalState {
projectId?: string;
- schemaDesignName: string;
+ schemaDesignTitle: string;
baselineSchema: BaselineSchema;
schemaDesign: SchemaDesign;
}
@@ -137,7 +140,7 @@ const databaseStore = useDatabaseV1Store();
const schemaDesignStore = useSchemaDesignStore();
const sheetStore = useSheetV1Store();
const state = reactive<LocalState>({
- schemaDesignName: "",
+ schemaDesignTitle: "",
projectId: props.projectId,
baselineSchema: {},
schemaDesign: SchemaDesign.fromPartial({
@@ -179,7 +182,9 @@ const prepareSchemaDesign = async () => {
const allowConfirm = computed(() => {
return (
- state.projectId && state.schemaDesignName && state.baselineSchema.databaseId
+ state.projectId &&
+ state.schemaDesignTitle &&
+ state.baselineSchema.databaseId
);
});
@@ -197,7 +202,10 @@ const handleProjectSelect = async (projectId: string) => {
const handleBaselineSchemaChange = async (baselineSchema: BaselineSchema) => {
state.baselineSchema = baselineSchema;
- if (baselineSchema.databaseId) {
+ if (
+ baselineSchema.databaseId &&
+ baselineSchema.databaseId !== String(UNKNOWN_ID)
+ ) {
const database = databaseStore.getDatabaseByUID(baselineSchema.databaseId);
state.projectId = database.projectEntity.uid;
}
@@ -218,7 +226,12 @@ const handleConfirm = async () => {
// Should not happen.
throw new Error("schema designer is undefined");
}
- if (state.schemaDesignName === "") {
+ if (!validateBranchName(state.schemaDesignTitle)) {
+ pushNotification({
+ module: "bytebase",
+ style: "CRITICAL",
+ title: "Branch name should valid characters: /^(a-zA-Z)[a-zA-Z0-9-_/]+$/",
+ });
return;
}
@@ -237,7 +250,7 @@ const handleConfirm = async () => {
const baselineDatabase = `${database.instanceEntity.name}/${databaseNamePrefix}${state.baselineSchema.databaseId}`;
// Create a baseline sheet for the schema design.
const baselineSheet = await sheetStore.createSheet(project.value.name, {
- name: `baseline schema of ${state.schemaDesignName}`,
+ title: `baseline schema of ${state.schemaDesignTitle}`,
database: baselineDatabase,
content: new TextEncoder().encode(state.schemaDesign.baselineSchema),
visibility: Sheet_Visibility.VISIBILITY_PROJECT,
@@ -248,7 +261,7 @@ const handleConfirm = async () => {
const createdSchemaDesign = await schemaDesignStore.createSchemaDesign(
project.value.name,
SchemaDesign.fromPartial({
- title: state.schemaDesignName,
+ title: state.schemaDesignTitle,
// Keep schema empty in frontend. Backend will generate the design schema.
schema: "",
schemaMetadata: metadata,
diff --git a/frontend/src/components/SchemaDesigner/EditSchemaDesignPanel.vue b/frontend/src/components/SchemaDesigner/EditSchemaDesignPanel.vue
index 413686d0e7..73e2ac1831 100644
--- a/frontend/src/components/SchemaDesigner/EditSchemaDesignPanel.vue
+++ b/frontend/src/components/SchemaDesigner/EditSchemaDesignPanel.vue
@@ -29,7 +29,7 @@
>
<NButton
v-if="parentBranch"
- @click="() => handleMergeSchemaDesign()"
+ @click="() => (state.showDiffEditor = true)"
>{{ $t("schema-designer.merge-branch") }}</NButton
>
<NButton type="primary" @click="handleApplySchemaDesignClick">{{
@@ -49,7 +49,7 @@
class="w-60 text-sm"
:readonly="!state.isEditingTitle"
:value="state.schemaDesignTitle"
- :placeholder="$t('database.branch-name')"
+ :placeholder="'feature/add-billing'"
@input="
state.schemaDesignTitle = (
$event.target as HTMLInputElement
@@ -63,8 +63,8 @@
@click="state.isEditingTitle = true"
>
<template #icon>
- <NIcon>
- <Pen class="w-4 h-auto" />
+ <NIcon size="16">
+ <Pen />
</NIcon>
</template>
</NButton>
@@ -94,16 +94,43 @@
<NDivider />
- <!--
- TODO(steven): show baseline database selectors.
+ <div class="w-full flex flex-row justify-start items-center mt-1">
+ <span class="flex w-40 items-center text-sm font-medium">{{
+ $t("schema-designer.baseline-version")
+ }}</span>
+ </div>
- <BaselineSchemaSelector
- :project-id="project.uid"
- :baseline-schema="state.baselineSchema"
- @update="handleBaselineSchemaChange"
- />
+ <div class="w-full flex flex-row justify-start items-center">
+ <span class="flex w-40 items-center shrink-0 text-sm">
+ {{ $t("common.database") }}
+ </span>
+ <DatabaseInfo :database="baselineDatabase" />
+ </div>
- <NDivider /> -->
+ <div class="w-full flex flex-row justify-start items-center">
+ <span class="flex w-40 items-center shrink-0 text-sm">
+ {{ $t("schema-designer.schema-version") }}
+ </span>
+ <div class="w-[calc(100%-10rem)]">
+ <div
+ v-if="changeHistory"
+ class="w-full flex flex-row justify-start items-center"
+ >
+ <span class="block pr-2 w-full max-w-[80%] truncate">
+ {{ changeHistory.version }} -
+ {{ changeHistory.description }}
+ </span>
+ <span class="text-control-light">
+ {{ humanizeDate(changeHistory.updateTime) }}
+ </span>
+ </div>
+ <template v-else>
+ {{ "Previously latest schema" }}
+ </template>
+ </div>
+ </div>
+
+ <NDivider />
<div class="w-full flex flex-row justify-end gap-2">
<template v-if="!state.isEditing">
@@ -152,7 +179,7 @@
<MergeBranchPanel
v-if="state.showDiffEditor"
- :source-branch-name="parentBranch!.name"
+ :source-branch-name="schemaDesign.baselineSheetName"
:target-branch-name="state.schemaDesignName"
@dismiss="state.showDiffEditor = false"
@try-merge="handleMergeAfterConflictResolved"
@@ -160,6 +187,7 @@
</template>
<script lang="ts" setup>
+import dayjs from "dayjs";
import { cloneDeep, isEqual } from "lodash-es";
import { Pen, X, Check } from "lucide-vue-next";
import {
@@ -172,10 +200,16 @@ import {
NIcon,
} from "naive-ui";
import { Status } from "nice-grpc-common";
-import { computed, onMounted, reactive, ref, watch } from "vue";
+import { computed, reactive, ref, watch } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
-import { pushNotification, useDatabaseV1Store } from "@/store";
+import DatabaseInfo from "@/components/DatabaseInfo.vue";
+import {
+ pushNotification,
+ useChangeHistoryStore,
+ useCurrentUserV1,
+ useDatabaseV1Store,
+} from "@/store";
import { useSchemaDesignStore } from "@/store/modules/schemaDesign";
import { DatabaseMetadata } from "@/types/proto/v1/database_service";
import {
@@ -188,6 +222,7 @@ import {
generateForkedBranchName,
mergeSchemaEditToMetadata,
validateDatabaseMetadata,
+ validateBranchName,
} from "./common/util";
import SchemaDesigner from "./index.vue";
@@ -209,7 +244,9 @@ const emit = defineEmits(["dismiss"]);
const { t } = useI18n();
const router = useRouter();
+const currentUser = useCurrentUserV1();
const databaseStore = useDatabaseV1Store();
+const changeHistoryStore = useChangeHistoryStore();
const schemaDesignStore = useSchemaDesignStore();
const dialog = useDialog();
const state = reactive<LocalState>({
@@ -227,7 +264,11 @@ const schemaDesign = computed(() => {
});
const parentBranch = computed(() => {
- if (schemaDesign.value.type === SchemaDesign_Type.PERSONAL_DRAFT) {
+ // Show parent branch when the current branch is a personal draft and it's not the new created one.
+ if (
+ schemaDesign.value.type === SchemaDesign_Type.PERSONAL_DRAFT &&
+ state.schemaDesignName !== createdBranchName.value
+ ) {
return schemaDesignStore.getSchemaDesignByName(
schemaDesign.value.baselineSheetName || ""
);
@@ -235,6 +276,11 @@ const parentBranch = computed(() => {
return undefined;
});
+const changeHistory = computed(() => {
+ const changeHistoryName = `${baselineDatabase.value.name}/changeHistories/${schemaDesign.value.baselineChangeHistoryId}`;
+ return changeHistoryStore.getChangeHistoryByName(changeHistoryName);
+});
+
const isSchemaDesignDraft = computed(() => {
return schemaDesign.value.type === SchemaDesign_Type.PERSONAL_DRAFT;
});
@@ -248,19 +294,20 @@ const project = computed(() => {
});
const prepareBaselineDatabase = async () => {
- await databaseStore.getOrFetchDatabaseByName(
+ const database = await databaseStore.getOrFetchDatabaseByName(
schemaDesign.value.baselineDatabase
);
+ await changeHistoryStore.getOrFetchChangeHistoryListOfDatabase(database.name);
};
-onMounted(async () => {
- await prepareBaselineDatabase();
-});
-
watch(
() => [state.schemaDesignName],
- () => {
- state.schemaDesignTitle = schemaDesign.value.title;
+ async () => {
+ // Only change branch title when it's not a new created one.
+ if (state.schemaDesignName !== createdBranchName.value) {
+ state.schemaDesignTitle = schemaDesign.value.title;
+ }
+ await prepareBaselineDatabase();
},
{
immediate: true,
@@ -272,7 +319,15 @@ const handleSaveBranchTitle = async () => {
pushNotification({
module: "bytebase",
style: "WARN",
- title: "Schema design name cannot be empty.",
+ title: "Branch name cannot be empty.",
+ });
+ return;
+ }
+ if (!validateBranchName(state.schemaDesignTitle)) {
+ pushNotification({
+ module: "bytebase",
+ style: "CRITICAL",
+ title: "Branch name should valid characters: /^(a-zA-Z)[a-zA-Z0-9-_/]+$/",
});
return;
}
@@ -308,16 +363,55 @@ const handleEdit = async () => {
if (schemaDesign.value.type === SchemaDesign_Type.PERSONAL_DRAFT) {
state.isEditing = true;
} else if (schemaDesign.value.type === SchemaDesign_Type.MAIN_BRANCH) {
- // Create a new draft if it's a main branch.
- const schemaDesignDraft = await schemaDesignStore.createSchemaDesignDraft({
- ...schemaDesign.value,
- title: generateForkedBranchName(schemaDesign.value),
- });
- // Select the newly created draft.
- state.schemaDesignName = schemaDesignDraft.name;
- createdBranchName.value = schemaDesignDraft.name;
- // Trigger the edit mode.
- handleEdit();
+ const branchName = generateForkedBranchName(schemaDesign.value);
+ const foundBranch = schemaDesignStore.schemaDesignList.find(
+ (schemaDesign) => {
+ return (
+ schemaDesign.creator === `users/${currentUser.value.email}` &&
+ schemaDesign.title === branchName
+ );
+ }
+ );
+ if (foundBranch) {
+ // Show a confirm dialog to let user decide whether to use the existing branch or create a new one.
+ dialog.create({
+ negativeText: t("schema-designer.action.use-the-existing-branch"),
+ positiveText: t("schema-designer.action.create-new-branch"),
+ title: t("schema-designer.diff-editor.action-confirm"),
+ content: t("schema-designer.diff-editor.duplicated-branch-name-found"),
+ autoFocus: true,
+ closable: true,
+ maskClosable: true,
+ closeOnEsc: true,
+ onNegativeClick: () => {
+ // Use the existing branch.
+ state.schemaDesignName = foundBranch.name;
+ handleEdit();
+ },
+ onPositiveClick: async () => {
+ // Create a new personal branch.
+ const newBranch = await schemaDesignStore.createSchemaDesignDraft({
+ ...schemaDesign.value,
+ title: branchName + `-${dayjs().format("YYYYMMDD")}`,
+ });
+ // Select the newly created draft.
+ state.schemaDesignName = newBranch.name;
+ createdBranchName.value = newBranch.name;
+ // Trigger the edit mode.
+ handleEdit();
+ },
+ });
+ } else {
+ const newBranch = await schemaDesignStore.createSchemaDesignDraft({
+ ...schemaDesign.value,
+ title: branchName,
+ });
+ // Select the newly created draft.
+ state.schemaDesignName = newBranch.name;
+ createdBranchName.value = newBranch.name;
+ // Trigger the edit mode.
+ handleEdit();
+ }
} else {
throw new Error(
`Unsupported schema design type: ${schemaDesign.value.type}`
@@ -333,12 +427,12 @@ const handleCancelEdit = async () => {
)
);
- const parentBranchName = parentBranch.value?.name || "";
// Only try to delete the branch if it's a new created personal draft.
if (
isSchemaDesignDraft.value &&
- createdBranchName.value === state.schemaDesignName
+ state.schemaDesignName === createdBranchName.value
) {
+ const parentBranchName = schemaDesign.value.baselineSheetName;
// If the metadata is changed, we need to confirm with user.
if (!isEqual(metadata, schemaDesign.value.schemaMetadata)) {
dialog.create({
@@ -347,10 +441,10 @@ const handleCancelEdit = async () => {
positiveText: t("schema-designer.diff-editor.discard-changes"),
title: t("schema-designer.diff-editor.action-confirm"),
content: t("schema-designer.diff-editor.discard-changes-confirm"),
- autoFocus: false,
- closable: false,
- maskClosable: false,
- closeOnEsc: false,
+ autoFocus: true,
+ closable: true,
+ maskClosable: true,
+ closeOnEsc: true,
onNegativeClick: () => {
// nothing to do
},
@@ -393,8 +487,11 @@ const handleSaveSchemaDesignDraft = async () => {
}
const updateMask = [];
- if (schemaDesign.value.title !== state.schemaDesignTitle) {
- updateMask.push("title");
+ // Don't update branch title for new created branch.
+ if (schemaDesign.value.name !== createdBranchName.value) {
+ if (schemaDesign.value.title !== state.schemaDesignTitle) {
+ updateMask.push("title");
+ }
}
const mergedMetadata = mergeSchemaEditToMetadata(
designerState.editableSchemas,
@@ -427,16 +524,19 @@ const handleSaveSchemaDesignDraft = async () => {
}),
updateMask
);
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("schema-designer.message.updated-succeed"),
- });
+ // Only show the notification when the branch is not a new created one.
+ if (schemaDesign.value.name !== createdBranchName.value) {
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("schema-designer.message.updated-succeed"),
+ });
+ }
}
state.isEditing = false;
// If it's a personal draft, we will try to merge it to the parent branch.
- if (isSchemaDesignDraft.value) {
+ if (schemaDesign.value.name === createdBranchName.value) {
await handleMergeSchemaDesign(true);
}
};
@@ -447,7 +547,7 @@ const handleMergeSchemaDesign = async (ignoreNotify = false) => {
await handleSaveSchemaDesignDraft();
}
- const parentBranchName = parentBranch.value!.name;
+ const parentBranchName = schemaDesign.value.baselineSheetName;
try {
await schemaDesignStore.mergeSchemaDesign({
name: schemaDesign.value.name,
@@ -461,10 +561,10 @@ const handleMergeSchemaDesign = async (ignoreNotify = false) => {
negativeText: t("common.cancel"),
title: t("schema-designer.diff-editor.auto-merge-failed"),
content: t("schema-designer.diff-editor.need-to-resolve-conflicts"),
- autoFocus: false,
- closable: false,
- maskClosable: false,
- closeOnEsc: false,
+ autoFocus: true,
+ closable: true,
+ maskClosable: true,
+ closeOnEsc: true,
onNegativeClick: () => {
// nothing to do
},
@@ -492,6 +592,7 @@ const handleMergeSchemaDesign = async (ignoreNotify = false) => {
}
// Auto select the parent branch after merged.
state.schemaDesignName = parentBranchName;
+ createdBranchName.value = "";
};
const handleMergeAfterConflictResolved = () => {
diff --git a/frontend/src/components/SchemaDesigner/MergeBranchPanel.vue b/frontend/src/components/SchemaDesigner/MergeBranchPanel.vue
index 1ab7286de9..9741c4b410 100644
--- a/frontend/src/components/SchemaDesigner/MergeBranchPanel.vue
+++ b/frontend/src/components/SchemaDesigner/MergeBranchPanel.vue
@@ -7,7 +7,7 @@
@update:show="(show: boolean) => !show && emit('dismiss')"
>
<NDrawerContent
- :title="$t('schema-designer.diff-editor.self')"
+ :title="$t('schema-designer.merge-branch')"
:closable="true"
>
<div
@@ -21,20 +21,26 @@
{{ $t("common.merge") }}
</NButton>
</div>
- <div class="pt-4 pb-6 w-full flex flex-row justify-center items-center">
- <NInput
- class="!w-40 text-center"
- readonly
- :value="sourceBranch.title"
- />
- <div class="mx-16">
- <MoveLeft :size="32" stroke-width="1" />
+ <div class="w-full pr-12 pt-4 pb-6 grid grid-cols-3">
+ <div class="flex flex-row justify-end">
+ <NInput
+ class="!w-4/5 text-center"
+ readonly
+ :value="sourceBranch.title"
+ size="large"
+ />
+ </div>
+ <div class="flex flex-row justify-center">
+ <MoveLeft :size="40" stroke-width="1" />
+ </div>
+ <div class="flex flex-row justify-start">
+ <NInput
+ class="!w-4/5 text-center"
+ readonly
+ :value="targetBranch.title"
+ size="large"
+ />
</div>
- <NInput
- class="!w-40 text-center"
- readonly
- :value="targetBranch.title"
- />
</div>
<div class="w-full grid grid-cols-2">
<div class="col-span-1">
@@ -44,7 +50,7 @@
<span>{{ $t("schema-designer.diff-editor.editing-schema") }}</span>
</div>
</div>
- <div class="w-full h-[calc(100%-8rem)] border">
+ <div class="w-full h-[calc(100%-12rem)] border">
<DiffEditor
v-if="state.initialized"
class="h-full"
@@ -103,6 +109,8 @@ const targetBranch = computed(() => {
});
onMounted(async () => {
+ // Fetching the latest source branch.
+ await schemaDesignStore.fetchSchemaDesignByName(props.sourceBranchName);
state.editingSchema = targetBranch.value.schema;
state.initialized = true;
});
@@ -116,7 +124,7 @@ const handleSaveDraft = async (ignoreNotify?: boolean) => {
const baselineSheet = await sheetStore.createSheet(
`projects/${projectName}`,
{
- name: `baseline schema of ${sourceBranch.value.title}`,
+ title: `baseline schema of ${sourceBranch.value.title}`,
database: targetBranch.value.baselineDatabase,
content: new TextEncoder().encode(sourceBranch.value.schema),
visibility: Sheet_Visibility.VISIBILITY_PROJECT,
diff --git a/frontend/src/components/SchemaDesigner/PrepForm/SchemaDesignTable.vue b/frontend/src/components/SchemaDesigner/PrepForm/SchemaDesignTable.vue
index 686e827d8f..abaf9511f1 100644
--- a/frontend/src/components/SchemaDesigner/PrepForm/SchemaDesignTable.vue
+++ b/frontend/src/components/SchemaDesigner/PrepForm/SchemaDesignTable.vue
@@ -8,14 +8,16 @@
@click-row="clickSchemaDesign"
>
<template #item="{ item: schemaDesign }: { item: SchemaDesign }">
- <div class="bb-grid-cell">
+ <div v-if="!hideProjectColumn" class="bb-grid-cell">
{{ projectV1Name(getFormatedValue(schemaDesign).project) }}
</div>
<div class="bb-grid-cell">
- {{ schemaDesign.title }}
+ <NEllipsis :line-clamp="1">{{ schemaDesign.title }}</NEllipsis>
</div>
<div class="bb-grid-cell">
- {{ getFormatedValue(schemaDesign).parentBranch }}
+ <NEllipsis :line-clamp="1">{{
+ getFormatedValue(schemaDesign).parentBranch
+ }}</NEllipsis>
</div>
<div class="bb-grid-cell">
<DatabaseInfo :database="getFormatedValue(schemaDesign).database" />
@@ -32,6 +34,7 @@
<script lang="ts" setup>
import dayjs from "dayjs";
+import { NEllipsis } from "naive-ui";
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { BBGridColumn } from "@/bbkit";
@@ -49,8 +52,9 @@ const emit = defineEmits<{
(event: "click", schemaDesign: SchemaDesign): void;
}>();
-defineProps<{
+const props = defineProps<{
schemaDesigns: SchemaDesign[];
+ hideProjectColumn?: boolean;
}>();
const { t } = useI18n();
@@ -61,15 +65,17 @@ const schemaDesignStore = useSchemaDesignStore();
const COLUMN_LIST = computed(() => {
const columns: BBGridColumn[] = [
- {
- title: t("common.project"),
- width: "minmax(auto, 0.5fr)",
- },
{ title: t("database.branch"), width: "minmax(auto, 0.5fr)" },
{ title: t("schema-designer.parent-branch"), width: "minmax(auto, 0.5fr)" },
{ title: t("common.database"), width: "1fr" },
{ title: "", width: "1fr" },
];
+ if (!props.hideProjectColumn) {
+ columns.unshift({
+ title: t("common.project"),
+ width: "minmax(auto, 0.5fr)",
+ });
+ }
return columns;
});
diff --git a/frontend/src/components/SchemaDesigner/common/util.ts b/frontend/src/components/SchemaDesigner/common/util.ts
index 84924c322e..994c9af58d 100644
--- a/frontend/src/components/SchemaDesigner/common/util.ts
+++ b/frontend/src/components/SchemaDesigner/common/util.ts
@@ -1,6 +1,5 @@
import { cloneDeep, isEqual, uniq } from "lodash-es";
import { useCurrentUserV1 } from "@/store";
-import { useSchemaDesignStore } from "@/store/modules/schemaDesign";
import {
Column,
ForeignKey,
@@ -27,6 +26,10 @@ export const mergeSchemaEditToMetadata = (
): DatabaseMetadata => {
for (const schemaEdit of schemaEdits) {
if (schemaEdit.status === "created") {
+ // Remove schema if it exists.
+ metadata.schemas = metadata.schemas.filter(
+ (item) => item.name !== schemaEdit.name
+ );
metadata.schemas.push(transformSchemaEditToMetadata(schemaEdit));
continue;
} else if (schemaEdit.status === "dropped") {
@@ -39,10 +42,15 @@ export const mergeSchemaEditToMetadata = (
(item) => item.name === schemaEdit.name
);
if (!schema) {
+ metadata.schemas.push(transformSchemaEditToMetadata(schemaEdit));
continue;
}
for (const tableEdit of schemaEdit.tableList) {
if (tableEdit.status === "created") {
+ // Remove table if it exists.
+ schema.tables = schema.tables.filter(
+ (item) => item.name !== tableEdit.name
+ );
schema.tables.push(transformTableEditToMetadata(tableEdit));
continue;
} else if (tableEdit.status === "dropped") {
@@ -55,10 +63,15 @@ export const mergeSchemaEditToMetadata = (
(item) => item.name === tableEdit.name
);
if (!table) {
+ schema.tables.push(transformTableEditToMetadata(tableEdit));
continue;
}
for (const columnEdit of tableEdit.columnList) {
if (columnEdit.status === "created") {
+ // Remove column if it exists.
+ table.columns = table.columns.filter(
+ (item) => item.name !== columnEdit.name
+ );
table.columns.push(transformColumnEditToMetadata(columnEdit));
continue;
} else if (columnEdit.status === "dropped") {
@@ -93,6 +106,16 @@ export const mergeSchemaEditToMetadata = (
}
}
}
+ for (const table of schema.tables) {
+ const tableEdit = schemaEdit.tableList.find(
+ (item) => item.name === table.name
+ );
+ if (!tableEdit) {
+ schema.tables = schema.tables.filter(
+ (item) => item.name !== table.name
+ );
+ }
+ }
}
// Build foreign keys.
@@ -168,6 +191,14 @@ export const mergeSchemaEditToMetadata = (
table.foreignKeys.push(fk);
}
}
+ for (const schema of metadata.schemas) {
+ const schemaEdit = schemaEdits.find((item) => item.name === schema.name);
+ if (!schemaEdit) {
+ metadata.schemas = metadata.schemas.filter(
+ (item) => item.name !== schema.name
+ );
+ }
+ }
return metadata;
};
@@ -476,17 +507,13 @@ export const validateDatabaseMetadata = (
export const generateForkedBranchName = (branch: SchemaDesign): string => {
const currentUser = useCurrentUserV1();
- const schemaDesignStore = useSchemaDesignStore();
const parentBranchName = branch.title;
- let branchName = `${currentUser.value.title}/${parentBranchName}`;
- const foundIndex = schemaDesignStore.schemaDesignList.findIndex((item) => {
- return item.title === branchName;
- });
- // If found, add a random string to the end of the branch name.
- if (foundIndex > -1) {
- branchName = `${
- currentUser.value.title
- }/${parentBranchName}-draft-${randomString(3).toLowerCase()}`;
- }
+ const branchName =
+ `${currentUser.value.title}/${parentBranchName}-draft`.replaceAll(" ", "-");
return branchName;
};
+
+export const validateBranchName = (branchName: string): boolean => {
+ const regex = /^(a-zA-Z)[a-zA-Z0-9-_/]+$/;
+ return regex.test(branchName);
+};
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 227c09af6f..0e6519193f 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -2853,6 +2853,7 @@
"resolve-and-merge-again": "Resolve and merge again",
"discard-changes": "Discard changes",
"action-confirm": "Action confirm",
+ "duplicated-branch-name-found": "Duplicated branch name found.",
"discard-changes-confirm": "Are you sure you want to discard all modifications?"
},
"tables": "Tables",
@@ -2865,6 +2866,10 @@
"updated-succeed": "Branch updated successfully",
"merge-to-main-successfully": "Merge to main successfully",
"updated-time-by-user": "Updated {time} by {user}"
+ },
+ "action": {
+ "use-the-existing-branch": "Use the existing branch",
+ "create-new-branch": "Create new branch"
}
},
"cel": {
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index e75d1e1fb1..a6c1d2482f 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -2851,6 +2851,7 @@
"resolve-and-merge-again": "Resolver y fusionar nuevamente",
"discard-changes": "Descartar cambios",
"action-confirm": "Acción confirmada",
+ "duplicated-branch-name-found": "Se encontró un nombre de rama duplicado. Por favor, elige otro.",
"discard-changes-confirm": "¿Estás seguro de que quieres descartar todas las modificaciones?"
},
"tables": "Tablas",
@@ -2863,6 +2864,10 @@
"updated-succeed": "Diseño de esquema actualizado con éxito",
"merge-to-main-successfully": "Fusionar con el principal exitosamente",
"updated-time-by-user": "Actualizado por {user} en {time}"
+ },
+ "action": {
+ "use-the-existing-branch": "Usar la rama existente",
+ "create-new-branch": "Crear nueva rama"
}
},
"cel": {
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 271288158c..3f2040f1ec 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -2846,6 +2846,7 @@
"resolve-and-merge-again": "解决冲突并再次合并",
"discard-changes": "丢弃修改",
"action-confirm": "确认操作",
+ "duplicated-branch-name-found": "发现重复的分支名称。",
"discard-changes-confirm": "您确定要丢弃所有修改吗?"
},
"tables": "表",
@@ -2858,6 +2859,10 @@
"updated-succeed": "分支更新成功",
"merge-to-main-successfully": "成功合并到主版本",
"updated-time-by-user": "由 {user} 于 {time} 更新"
+ },
+ "action": {
+ "use-the-existing-branch": "使用已有分支",
+ "create-new-branch": "创建新分支"
}
},
"cel": {
diff --git a/frontend/src/views/SyncDatabaseSchema/RawSQLEditor.vue b/frontend/src/views/SyncDatabaseSchema/RawSQLEditor.vue
index 863daef704..3030512564 100644
--- a/frontend/src/views/SyncDatabaseSchema/RawSQLEditor.vue
+++ b/frontend/src/views/SyncDatabaseSchema/RawSQLEditor.vue
@@ -200,7 +200,7 @@ const handleUploadFile = (e: Event) => {
fr.onload = async () => {
const statement = fr.result as string;
const sheet = await sheetStore.createSheet(DEFAULT_PROJECT_V1_NAME, {
- name: file.name,
+ title: file.name,
content: new TextEncoder().encode(statement),
visibility: Sheet_Visibility.VISIBILITY_PROJECT,
source: Sheet_Source.SOURCE_BYTEBASE_ARTIFACT,
diff --git a/frontend/src/views/SyncDatabaseSchema/SchemaDesignSelector.vue b/frontend/src/views/SyncDatabaseSchema/SchemaDesignSelector.vue
index 7c1b212fae..d849a82ba9 100644
--- a/frontend/src/views/SyncDatabaseSchema/SchemaDesignSelector.vue
+++ b/frontend/src/views/SyncDatabaseSchema/SchemaDesignSelector.vue
@@ -28,10 +28,12 @@
{{ projectV1Name(getFormatedValue(schemaDesign).project) }}
</div>
<div class="bb-grid-cell">
- {{ schemaDesign.title }}
+ <NEllipsis :line-clamp="1">{{ schemaDesign.title }}</NEllipsis>
</div>
<div class="bb-grid-cell">
- {{ getFormatedValue(schemaDesign).parentBranch }}
+ <NEllipsis :line-clamp="1">{{
+ getFormatedValue(schemaDesign).parentBranch
+ }}</NEllipsis>
</div>
<div class="bb-grid-cell">
<DatabaseInfo :database="getFormatedValue(schemaDesign).database" />
@@ -75,8 +77,7 @@
<script lang="ts" setup>
import dayjs from "dayjs";
-import { NButton } from "naive-ui";
-import { NRadio } from "naive-ui";
+import { NRadio, NButton, NEllipsis } from "naive-ui";
import { computed, ref, reactive } from "vue";
import { useI18n } from "vue-i18n";
import { BBGridColumn } from "@/bbkit";