Skip to content

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

chore: show schema editor in create plan drawer (#16911)

boojackfd5abcc4163a
diff --git a/frontend/src/components/Plan/components/AddSpecDrawer.vue b/frontend/src/components/Plan/components/AddSpecDrawer.vue
index c7c858ded6..e18d9803f1 100644
--- a/frontend/src/components/Plan/components/AddSpecDrawer.vue
+++ b/frontend/src/components/Plan/components/AddSpecDrawer.vue
@@ -1,23 +1,29 @@
<template>
<Drawer
v-model:show="show"
- :width="640"
- :mask-closable="true"
+ :mask-closable="false"
placement="right"
- class="!w-[1024px] !max-w-[100vw]"
+ :default-width="1024"
+ :resizable="true"
+ :width="undefined"
+ class="!max-w-[90vw]"
>
<DrawerContent :title="title ?? $t('plan.add-spec')" closable>
<div class="flex flex-col gap-y-4">
<!-- Steps indicator -->
<NSteps :current="currentStep">
- <NStep :title="stepTitle" />
+ <NStep :title="changeTypeTitle" />
<NStep :title="$t('plan.select-targets')" />
+ <NStep
+ v-if="shouldShowSchemaEditor"
+ :title="$t('schema-editor.self')"
+ />
</NSteps>
<!-- Step content -->
<div class="flex-1">
<!-- Step 1: Select Change Type -->
- <template v-if="currentStep === 1">
+ <template v-if="currentStep === Step.SELECT_CHANGE_TYPE">
<NRadioGroup
v-model:value="selectedChangeType"
size="large"
@@ -83,38 +89,73 @@
</template>
<!-- Step 2: Select Targets -->
- <template v-else-if="currentStep === 2">
+ <template v-else-if="currentStep === Step.SELECT_TARGETS">
<DatabaseAndGroupSelector
:project="project"
:value="databaseSelectState"
@update:value="handleUpdateSelection"
/>
</template>
+
+ <!-- Step 3: Schema Editor (only for MIGRATE with single database) -->
+ <template
+ v-else-if="
+ currentStep === Step.SCHEMA_EDITOR && shouldShowSchemaEditor
+ "
+ >
+ <div class="relative h-[600px]">
+ <MaskSpinner v-if="isPreparingMetadata" />
+ <SchemaEditorLite
+ ref="schemaEditorRef"
+ v-if="schemaEditTargets.length > 0"
+ :project="project"
+ :targets="schemaEditTargets"
+ :loading="isPreparingMetadata"
+ :diff-when-ready="false"
+ :hide-preview="false"
+ />
+ </div>
+ </template>
</div>
</div>
<template #footer>
- <div class="flex items-center justify-between">
+ <div class="w-full flex items-center justify-between">
+ <div>
+ <NButton
+ v-if="
+ currentStep === Step.SCHEMA_EDITOR && shouldShowSchemaEditor
+ "
+ :loading="isGeneratingPreview"
+ @click="handlePreviewDDL"
+ >
+ {{ $t("schema-editor.preview-schema-text") }}
+ </NButton>
+ </div>
<div class="flex items-center gap-x-3">
- <NButton quaternary v-if="currentStep === 1" @click="handleCancel">
+ <NButton
+ quaternary
+ v-if="currentStep === Step.SELECT_CHANGE_TYPE"
+ @click="handleCancel"
+ >
{{ $t("common.close") }}
</NButton>
<NButton
- v-if="currentStep === 2"
+ v-if="currentStep > Step.SELECT_CHANGE_TYPE"
quaternary
@click="handlePrevStep"
>
{{ $t("common.back") }}
</NButton>
<NButton
- v-if="currentStep === 1"
+ v-if="!isLastStep"
type="primary"
- :disabled="!selectedChangeType"
+ :disabled="!canProceedToNextStep"
@click="handleNextStep"
>
{{ $t("common.next") }}
</NButton>
<NButton
- v-else-if="currentStep === 2"
+ v-else
type="primary"
:disabled="!canSubmit"
:loading="isCreating"
@@ -127,21 +168,75 @@
</template>
</DrawerContent>
</Drawer>
+
+ <!-- Preview DDL Modal -->
+ <NModal
+ v-model:show="showPreviewModal"
+ :mask-closable="true"
+ :closable="true"
+ style="width: 80vw; max-width: 1200px"
+ >
+ <NCard
+ :title="$t('schema-editor.preview-schema-text')"
+ :bordered="false"
+ size="small"
+ role="dialog"
+ aria-modal="true"
+ class="max-h-[80vh] overflow-hidden"
+ >
+ <template #header-extra>
+ <NButton @click="showPreviewModal = false" :size="'small'"
+ ><XIcon :size="16"
+ /></NButton>
+ </template>
+ <div class="h-[60vh] min-h-[400px] border rounded">
+ <MonacoEditor
+ :readonly="true"
+ :content="previewDDL"
+ :auto-focus="false"
+ class="w-full h-full"
+ language="sql"
+ />
+ </div>
+ </NCard>
+ </NModal>
</template>
<script setup lang="ts">
import { create as createProto } from "@bufbuild/protobuf";
-import { FileDiffIcon, EditIcon } from "lucide-vue-next";
-import { NButton, NRadio, NRadioGroup, NSteps, NStep } from "naive-ui";
+import { cloneDeep } from "lodash-es";
+import { FileDiffIcon, EditIcon, XIcon } from "lucide-vue-next";
+import {
+ NButton,
+ NRadio,
+ NRadioGroup,
+ NSteps,
+ NStep,
+ NModal,
+ NCard,
+} from "naive-ui";
import { v4 as uuidv4 } from "uuid";
import type { Ref } from "vue";
import { computed, reactive, ref, watch } from "vue";
import { useI18n } from "vue-i18n";
import DatabaseAndGroupSelector from "@/components/DatabaseAndGroupSelector";
import type { DatabaseSelectState } from "@/components/DatabaseAndGroupSelector";
+import { MonacoEditor } from "@/components/MonacoEditor";
import { getLocalSheetByName, getNextLocalSheetUID } from "@/components/Plan";
+import SchemaEditorLite, {
+ generateDiffDDL,
+ type EditTarget,
+} from "@/components/SchemaEditorLite";
+import MaskSpinner from "@/components/misc/MaskSpinner.vue";
import { Drawer, DrawerContent } from "@/components/v2";
-import { useCurrentProjectV1 } from "@/store";
+import {
+ useCurrentProjectV1,
+ useDatabaseV1Store,
+ useDBSchemaV1Store,
+ useDatabaseCatalogV1Store,
+ batchGetOrFetchDatabases,
+ pushNotification,
+} from "@/store";
import {
Plan_ChangeDatabaseConfig_Type,
Plan_ChangeDatabaseConfigSchema,
@@ -150,7 +245,8 @@ import {
Plan_SpecSchema,
type Plan_Spec,
} from "@/types/proto-es/v1/plan_service_pb";
-import { SheetSchema } from "@/types/proto-es/v1/sheet_service_pb";
+import { setSheetStatement } from "@/utils";
+import { engineSupportsSchemaEditor } from "@/utils/schemaEditor";
defineProps<{
title?: string;
@@ -160,15 +256,30 @@ const emit = defineEmits<{
(event: "created", spec: Plan_Spec): void;
}>();
+enum Step {
+ SELECT_CHANGE_TYPE = 1,
+ SELECT_TARGETS = 2,
+ SCHEMA_EDITOR = 3,
+}
+
const { project } = useCurrentProjectV1();
const { t } = useI18n();
const show = defineModel<boolean>("show", { default: false });
+const databaseV1Store = useDatabaseV1Store();
+const dbSchemaStore = useDBSchemaV1Store();
+const dbCatalogStore = useDatabaseCatalogV1Store();
const selectedChangeType: Ref<Plan_ChangeDatabaseConfig_Type> = ref(
Plan_ChangeDatabaseConfig_Type.MIGRATE
);
const isCreating = ref(false);
-const currentStep = ref(1);
+const currentStep = ref(Step.SELECT_CHANGE_TYPE);
+const isPreparingMetadata = ref(false);
+const schemaEditTargets = ref<EditTarget[]>([]);
+const schemaEditorRef = ref<InstanceType<typeof SchemaEditorLite>>();
+const showPreviewModal = ref(false);
+const previewDDL = ref("");
+const isGeneratingPreview = ref(false);
const databaseSelectState = reactive<DatabaseSelectState>({
changeSource: "DATABASE",
@@ -187,13 +298,50 @@ const canSubmit = computed(() => {
return hasSelection.value && selectedChangeType.value;
});
-const stepTitle = computed(() => {
- if (currentStep.value === 1) {
- return t("plan.change-type");
+const canProceedToNextStep = computed(() => {
+ if (currentStep.value === Step.SELECT_CHANGE_TYPE) {
+ return !!selectedChangeType.value;
}
- return selectedChangeType.value === Plan_ChangeDatabaseConfig_Type.DATA
- ? t("plan.data-change")
- : t("plan.schema-migration");
+ if (currentStep.value === Step.SELECT_TARGETS) {
+ return hasSelection.value;
+ }
+ return false;
+});
+
+const shouldShowSchemaEditor = computed(() => {
+ if (!isMigrateSelected.value) return false;
+ if (databaseSelectState.changeSource !== "DATABASE") return false;
+ if (databaseSelectState.selectedDatabaseNameList.length !== 1) return false;
+
+ // Check if the selected database engine supports schema editor
+ const databaseName = databaseSelectState.selectedDatabaseNameList[0];
+ if (!databaseName) return false;
+
+ const database = databaseV1Store.getDatabaseByName(databaseName);
+ if (!database || !database.instanceResource) return false;
+
+ return engineSupportsSchemaEditor(database.instanceResource.engine);
+});
+
+const totalSteps = computed(() => {
+ return shouldShowSchemaEditor.value ? 3 : 2;
+});
+
+const isLastStep = computed(() => {
+ return currentStep.value === totalSteps.value;
+});
+
+const changeTypeTitle = computed(() => {
+ if (currentStep.value !== Step.SELECT_CHANGE_TYPE) {
+ if (selectedChangeType.value === Plan_ChangeDatabaseConfig_Type.MIGRATE) {
+ return t("plan.schema-migration");
+ } else if (
+ selectedChangeType.value === Plan_ChangeDatabaseConfig_Type.DATA
+ ) {
+ return t("plan.data-change");
+ }
+ }
+ return t("plan.change-type");
});
const isMigrateSelected = computed(() => {
@@ -207,32 +355,134 @@ const isDataSelected = computed(() => {
// Reset state when drawer opens
watch(show, (newVal) => {
if (newVal) {
- currentStep.value = 1;
+ currentStep.value = Step.SELECT_CHANGE_TYPE;
selectedChangeType.value = Plan_ChangeDatabaseConfig_Type.MIGRATE;
databaseSelectState.changeSource = "DATABASE";
databaseSelectState.selectedDatabaseNameList = [];
databaseSelectState.selectedDatabaseGroup = undefined;
isCreating.value = false;
+ isPreparingMetadata.value = false;
+ schemaEditTargets.value = [];
+ showPreviewModal.value = false;
+ previewDDL.value = "";
+ isGeneratingPreview.value = false;
}
});
-const handleUpdateSelection = (newState: DatabaseSelectState) => {
+const handleUpdateSelection = async (newState: DatabaseSelectState) => {
Object.assign(databaseSelectState, newState);
+
+ // Preload database information if databases are selected
+ if (
+ newState.changeSource === "DATABASE" &&
+ newState.selectedDatabaseNameList?.length > 0
+ ) {
+ await batchGetOrFetchDatabases(newState.selectedDatabaseNameList);
+ }
};
const handleCancel = () => {
show.value = false;
};
-const handleNextStep = () => {
- if (currentStep.value === 1 && selectedChangeType.value) {
- currentStep.value = 2;
+const prepareDatabaseMetadata = async () => {
+ if (!shouldShowSchemaEditor.value) return;
+
+ isPreparingMetadata.value = true;
+ schemaEditTargets.value = [];
+
+ try {
+ const databaseName = databaseSelectState.selectedDatabaseNameList[0];
+ await batchGetOrFetchDatabases([databaseName]);
+
+ const database = databaseV1Store.getDatabaseByName(databaseName);
+
+ const metadata = await dbSchemaStore.getOrFetchDatabaseMetadata({
+ database: database.name,
+ skipCache: true,
+ });
+
+ const catalog = await dbCatalogStore.getOrFetchDatabaseCatalog({
+ database: database.name,
+ skipCache: true,
+ });
+
+ schemaEditTargets.value = [
+ {
+ database,
+ metadata: cloneDeep(metadata),
+ baselineMetadata: metadata,
+ catalog: cloneDeep(catalog),
+ baselineCatalog: catalog,
+ },
+ ];
+ } finally {
+ isPreparingMetadata.value = false;
+ }
+};
+
+const handleNextStep = async () => {
+ if (
+ currentStep.value === Step.SELECT_CHANGE_TYPE &&
+ selectedChangeType.value
+ ) {
+ currentStep.value = Step.SELECT_TARGETS;
+ } else if (currentStep.value === Step.SELECT_TARGETS && hasSelection.value) {
+ if (shouldShowSchemaEditor.value) {
+ currentStep.value = Step.SCHEMA_EDITOR;
+ await prepareDatabaseMetadata();
+ } else {
+ await handleConfirm();
+ }
}
};
const handlePrevStep = () => {
- if (currentStep.value === 2) {
- currentStep.value = 1;
+ if (currentStep.value === Step.SELECT_TARGETS) {
+ currentStep.value = Step.SELECT_CHANGE_TYPE;
+ } else if (currentStep.value === Step.SCHEMA_EDITOR) {
+ currentStep.value = Step.SELECT_TARGETS;
+ }
+};
+
+const handlePreviewDDL = async () => {
+ if (!shouldShowSchemaEditor.value || schemaEditTargets.value.length === 0)
+ return;
+
+ isGeneratingPreview.value = true;
+ try {
+ const target = schemaEditTargets.value[0];
+ const applyMetadataEdit = schemaEditorRef.value?.applyMetadataEdit;
+
+ if (typeof applyMetadataEdit === "function") {
+ const { database, metadata, catalog, baselineMetadata, baselineCatalog } =
+ target;
+ applyMetadataEdit(database, metadata, catalog);
+
+ const result = await generateDiffDDL({
+ database,
+ sourceMetadata: baselineMetadata,
+ targetMetadata: metadata,
+ sourceCatalog: baselineCatalog,
+ targetCatalog: catalog,
+ allowEmptyDiffDDLWithConfigChange: false,
+ });
+
+ if (result.errors.length > 0) {
+ pushNotification({
+ module: "bytebase",
+ style: "CRITICAL",
+ title: t("common.error"),
+ description: result.errors.join("\n"),
+ });
+ return;
+ }
+
+ previewDDL.value = result.statement || "-- No changes detected";
+ showPreviewModal.value = true;
+ }
+ } finally {
+ isGeneratingPreview.value = false;
}
};
@@ -249,14 +499,61 @@ const handleConfirm = async () => {
targets.push(databaseSelectState.selectedDatabaseGroup);
}
+ let statement = "";
+
+ // Generate diff DDL if we're on step 3 (schema editor)
+ if (
+ currentStep.value === Step.SCHEMA_EDITOR &&
+ shouldShowSchemaEditor.value &&
+ schemaEditTargets.value.length > 0
+ ) {
+ const target = schemaEditTargets.value[0];
+ const applyMetadataEdit = schemaEditorRef.value?.applyMetadataEdit;
+
+ if (typeof applyMetadataEdit === "function") {
+ const {
+ database,
+ metadata,
+ catalog,
+ baselineMetadata,
+ baselineCatalog,
+ } = target;
+ applyMetadataEdit(database, metadata, catalog);
+
+ const result = await generateDiffDDL({
+ database,
+ sourceMetadata: baselineMetadata,
+ targetMetadata: metadata,
+ sourceCatalog: baselineCatalog,
+ targetCatalog: catalog,
+ allowEmptyDiffDDLWithConfigChange: false,
+ });
+
+ if (result.errors.length > 0) {
+ pushNotification({
+ module: "bytebase",
+ style: "CRITICAL",
+ title: t("common.error"),
+ description: result.errors.join("\n"),
+ });
+ return;
+ }
+
+ statement = result.statement;
+ }
+ }
+
const sheetUID = getNextLocalSheetUID();
- const sheet = createProto(SheetSchema, {
- ...getLocalSheetByName(`${project.value.name}/sheets/${sheetUID}`),
- title:
- selectedChangeType.value === Plan_ChangeDatabaseConfig_Type.MIGRATE
- ? "Schema Migration"
- : "Data Change",
- });
+ const localSheet = getLocalSheetByName(
+ `${project.value.name}/sheets/${sheetUID}`
+ );
+ localSheet.title =
+ selectedChangeType.value === Plan_ChangeDatabaseConfig_Type.MIGRATE
+ ? "Schema Migration"
+ : "Data Change";
+ if (statement) {
+ setSheetStatement(localSheet, statement);
+ }
// Create spec
const spec = createProto(Plan_SpecSchema, {
@@ -266,13 +563,20 @@ const handleConfirm = async () => {
value: createProto(Plan_ChangeDatabaseConfigSchema, {
targets,
type: selectedChangeType.value,
- sheet: sheet.name,
+ sheet: localSheet.name,
}),
},
});
emit("created", spec);
show.value = false;
+ } catch (error) {
+ pushNotification({
+ module: "bytebase",
+ style: "CRITICAL",
+ title: t("common.error"),
+ description: error instanceof Error ? error.message : String(error),
+ });
} finally {
isCreating.value = false;
}
diff --git a/frontend/src/components/Plan/components/SpecDetailView/SpecListSection.vue b/frontend/src/components/Plan/components/SpecDetailView/SpecListSection.vue
index 63d3ebb653..83269e5a12 100644
--- a/frontend/src/components/Plan/components/SpecDetailView/SpecListSection.vue
+++ b/frontend/src/components/Plan/components/SpecDetailView/SpecListSection.vue
@@ -49,12 +49,12 @@ import { NTabs, NTab, NButton } from "naive-ui";
import { ref } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
+import { PROJECT_V1_ROUTE_PLAN_DETAIL_SPEC_DETAIL } from "@/router/dashboard/projectV1";
import type { Plan_Spec } from "@/types/proto-es/v1/plan_service_pb";
import { Plan_ChangeDatabaseConfig_Type } from "@/types/proto-es/v1/plan_service_pb";
import { usePlanContext } from "../../logic/context";
import AddSpecDrawer from "../AddSpecDrawer.vue";
import { useSpecsValidation } from "../common";
-import { gotoSpec } from "../common/utils";
import { useSelectedSpec } from "./context";
const { t } = useI18n();
@@ -93,14 +93,26 @@ const getSpecTitle = (spec: Plan_Spec) => {
};
const handleTabChange = (specId: string) => {
- if (selectedSpec.value?.id !== specId) {
- gotoSpec(router, specId);
+ if (selectedSpec.value.id !== specId) {
+ gotoSpec(specId);
}
};
const handleSpecCreated = async (spec: Plan_Spec) => {
- // Add the new spec to the plan
+ // Add the new spec to the plan.
plan.value.specs.push(spec);
- gotoSpec(router, spec.id);
+ gotoSpec(spec.id);
+};
+
+const gotoSpec = (specId: string) => {
+ const currentRoute = router.currentRoute.value;
+ router.push({
+ name: PROJECT_V1_ROUTE_PLAN_DETAIL_SPEC_DETAIL,
+ params: {
+ ...(currentRoute.params || {}),
+ specId,
+ },
+ query: currentRoute.query || {},
+ });
};
</script>
diff --git a/frontend/src/components/Plan/components/common/utils.ts b/frontend/src/components/Plan/components/common/utils.ts
deleted file mode 100644
index a3abf1b661..0000000000
--- a/frontend/src/components/Plan/components/common/utils.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-import { type Router } from "vue-router";
-import { PROJECT_V1_ROUTE_PLAN_DETAIL_SPEC_DETAIL } from "@/router/dashboard/projectV1";
-
-export const gotoSpec = (router: Router, specId: string) => {
- // Defensive check for router and currentRoute
- if (!router || !router.currentRoute?.value) {
- console.error("Router or currentRoute is not available in gotoSpec");
- return;
- }
-
- const currentRoute = router.currentRoute.value;
- router.push({
- name: PROJECT_V1_ROUTE_PLAN_DETAIL_SPEC_DETAIL,
- params: {
- ...(currentRoute.params || {}),
- specId,
- },
- query: currentRoute.query || {},
- });
-};
diff --git a/frontend/src/components/SchemaEditorLite/Aside/Tree.vue b/frontend/src/components/SchemaEditorLite/Aside/Tree.vue
index 644ed87dbf..3c4c24bdd9 100644
--- a/frontend/src/components/SchemaEditorLite/Aside/Tree.vue
+++ b/frontend/src/components/SchemaEditorLite/Aside/Tree.vue
@@ -2,9 +2,10 @@
<div
class="w-full h-full pl-1 pr-2 flex flex-col gap-y-2 relative overflow-y-hidden"
>
- <div class="w-full sticky top-0 pt-2 h-12 bg-white z-10">
+ <div class="w-full sticky top-0 pt-2">
<NInput
v-model:value="searchPattern"
+ :size="'small'"
:placeholder="$t('schema-editor.search-database-and-table')"
>
<template #prefix>
diff --git a/frontend/src/components/SchemaEditorLite/Editor.vue b/frontend/src/components/SchemaEditorLite/Editor.vue
index c2ec706f90..670a6408d6 100644
--- a/frontend/src/components/SchemaEditorLite/Editor.vue
+++ b/frontend/src/components/SchemaEditorLite/Editor.vue
@@ -1,11 +1,7 @@
<template>
<main class="w-full h-full flex flex-col overflow-y-hidden">
<template v-if="currentTab">
- <TabsContainer
- class="px-2 pt-2"
- @update:table-search-pattern="handleTableSearchPattern"
- @update:column-search-pattern="handleColumnSearchPattern"
- />
+ <TabsContainer class="px-2 pt-2" />
<div
class="w-full flex-1 relative overflow-y-hidden"
:data-key="currentTab.id"
@@ -16,7 +12,6 @@
v-model:selected-schema-name="currentTab.selectedSchema"
:db="currentTab.database"
:database="currentTab.metadata.database"
- :search-pattern="state.tableSearchPattern"
class="px-2 pb-2"
/>
<TableEditor
@@ -26,7 +21,6 @@
:database="currentTab.metadata.database"
:schema="currentTab.metadata.schema"
:table="currentTab.metadata.table"
- :search-pattern="state.columnSearchPattern"
/>
<ProcedureEditor
v-if="currentTab.type === 'procedure'"
@@ -61,7 +55,6 @@
</template>
<script lang="ts" setup>
-import { reactive, watch } from "vue";
import EmptyTips from "./EmptyTips.vue";
import DatabaseEditor from "./Panels/DatabaseEditor.vue";
import FunctionEditor from "./Panels/FunctionEditor.vue";
@@ -71,28 +64,5 @@ import ViewEditor from "./Panels/ViewEditor.vue";
import TabsContainer from "./TabsContainer.vue";
import { useSchemaEditorContext } from "./context";
-interface LocalState {
- tableSearchPattern: string;
- columnSearchPattern: string;
-}
-
const { currentTab } = useSchemaEditorContext();
-
-const state = reactive<LocalState>({
- tableSearchPattern: "",
- columnSearchPattern: "",
-});
-
-const handleTableSearchPattern = (tableSearchPattern: string) => {
- state.tableSearchPattern = tableSearchPattern;
-};
-
-const handleColumnSearchPattern = (columnSearchPattern: string) => {
- state.columnSearchPattern = columnSearchPattern;
-};
-
-watch([() => currentTab.value?.id], () => {
- state.tableSearchPattern = "";
- state.columnSearchPattern = "";
-});
</script>
diff --git a/frontend/src/components/SchemaEditorLite/Panels/DatabaseEditor.vue b/frontend/src/components/SchemaEditorLite/Panels/DatabaseEditor.vue
index 03afd51e07..553e5b23d1 100644
--- a/frontend/src/components/SchemaEditorLite/Panels/DatabaseEditor.vue
+++ b/frontend/src/components/SchemaEditorLite/Panels/DatabaseEditor.vue
@@ -6,12 +6,12 @@
v-if="state.selectedSubTab === 'table-list'"
class="w-full flex justify-between items-center space-x-2"
>
- <div class="flex flex-row justify-start items-center gap-x-3">
+ <div class="flex flex-row justify-start items-center gap-x-2">
<div
v-if="shouldShowSchemaSelector"
- class="pl-1 flex flex-row justify-start items-center text-sm gap-x-2"
+ class="pl-1 flex flex-row justify-start items-center text-sm gap-x-2 overflow-auto"
>
- <span>Schema:</span>
+ <span class="shrink-0">Schema:</span>
<NSelect
:value="selectedSchemaName"
:options="schemaSelectorOptionList"
@@ -181,7 +181,7 @@ const props = withDefaults(
db: ComposedDatabase;
database: DatabaseMetadata;
selectedSchemaName: string | undefined;
- searchPattern: string;
+ searchPattern?: string;
}>(),
{
searchPattern: "",
diff --git a/frontend/src/components/SchemaEditorLite/TabsContainer.vue b/frontend/src/components/SchemaEditorLite/TabsContainer.vue
index de46d0ae00..a573f61acb 100644
--- a/frontend/src/components/SchemaEditorLite/TabsContainer.vue
+++ b/frontend/src/components/SchemaEditorLite/TabsContainer.vue
@@ -56,27 +56,14 @@
</div>
</div>
</div>
- <div v-if="currentTab" class="pl-2">
- <NInput
- v-model:value="searchPattern"
- class="!w-40"
- :placeholder="searchBoxPlaceholder"
- @input="handleSearchBoxInput"
- >
- <template #prefix>
- <heroicons-outline:search class="w-4 h-auto text-gray-300" />
- </template>
- </NInput>
- </div>
</div>
</template>
<script lang="ts" setup>
import { XIcon } from "lucide-vue-next";
-import { NEllipsis, NInput } from "naive-ui";
+import { NEllipsis } from "naive-ui";
import scrollIntoView from "scroll-into-view-if-needed";
-import { computed, nextTick, ref, watch } from "vue";
-import { useI18n } from "vue-i18n";
+import { nextTick, ref, watch } from "vue";
import {
DatabaseIcon,
FunctionIcon,
@@ -87,34 +74,12 @@ import {
import { useSchemaEditorContext } from "./context";
import type { TabContext } from "./types";
-const emit = defineEmits<{
- (event: "update:table-search-pattern", pattern: string): void;
- (event: "update:column-search-pattern", pattern: string): void;
-}>();
-
-const { t } = useI18n();
const { tabList, currentTab, setCurrentTab, closeTab, getTableStatus } =
useSchemaEditorContext();
const tabsContainerRef = ref();
const searchPattern = ref("");
const originalTabContext = ref<TabContext | undefined>(undefined);
-const searchBoxPlaceholder = computed(() => {
- return currentTab.value?.type === "database"
- ? t("schema-editor.search-table")
- : currentTab.value?.type === "table"
- ? t("schema-editor.search-column")
- : "";
-});
-
-const handleSearchBoxInput = (value: string) => {
- if (currentTab.value?.type === "database") {
- emit("update:table-search-pattern", value);
- } else if (currentTab.value?.type === "table") {
- emit("update:column-search-pattern", value);
- }
-};
-
watch(
() => currentTab.value,
() => {
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index eaf5cc2f54..898c6e1133 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -2040,8 +2040,6 @@
"sync-sql-from-schema-editor": "Sync SQL from Schema Editor",
"raw-sql": "Raw SQL",
"search-database-and-table": "Search database and table",
- "search-table": "Search table",
- "search-column": "Search column",
"nothing-changed-for-database": "Nothing changed for database {database}",
"actions": {
"create-schema": "Create schema",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 8769ccc626..3ee2fc5961 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -2040,8 +2040,6 @@
"sync-sql-from-schema-editor": "Sincronizar SQL desde el Editor de esquema",
"raw-sql": "SQL sin procesar",
"search-database-and-table": "Buscar base de datos y tabla",
- "search-table": "Buscar tabla",
- "search-column": "Buscar columna",
"nothing-changed-for-database": "Nada cambió para la base de datos {database}",
"actions": {
"create-schema": "Crear esquema",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 47922210c5..3451740605 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -2040,8 +2040,6 @@
"sync-sql-from-schema-editor": "スキーマエディタからSQLを同期する",
"raw-sql": "SQL文",
"search-database-and-table": "データベースとテーブルを検索する",
- "search-table": "検索テーブル",
- "search-column": "検索欄",
"nothing-changed-for-database": "データベース {database} には何も変更されていません",
"actions": {
"create-schema": "新しいスキーマ",
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 4691a18401..731f5fc9a2 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -2040,8 +2040,6 @@
"sync-sql-from-schema-editor": "Đồng bộ SQL từ Trình soạn thảo lược đồ",
"raw-sql": "SQL thô",
"search-database-and-table": "Tìm kiếm cơ sở dữ liệu và bảng",
- "search-table": "Tìm kiếm bảng",
- "search-column": "Tìm kiếm cột",
"nothing-changed-for-database": "Không có gì thay đổi cho cơ sở dữ liệu {database}",
"actions": {
"create-schema": "Tạo lược đồ",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 9801398494..eca4ed19ec 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -2040,8 +2040,6 @@
"sync-sql-from-schema-editor": "从 Schema 编辑器中同步 SQL",
"raw-sql": "SQL 语句",
"search-database-and-table": "搜索数据库和表",
- "search-table": "搜索表",
- "search-column": "搜索列",
"nothing-changed-for-database": "数据库 {database} 未发生任何变化",
"actions": {
"create-schema": "新建 Schema",
diff --git a/frontend/src/views/InstanceDashboard.vue b/frontend/src/views/InstanceDashboard.vue
index fb12ed3816..a3db378706 100644
--- a/frontend/src/views/InstanceDashboard.vue
+++ b/frontend/src/views/InstanceDashboard.vue
@@ -38,7 +38,7 @@
:on-click="onRowClick"
:selected-instance-names="Array.from(state.selectedInstance)"
@update:selected-instance-names="
- (list) => (state.selectedInstance = new Set(list))
+ (list: string[]) => (state.selectedInstance = new Set(list))
"
/>
</div>
diff --git a/frontend/src/views/project/ProjectPlanDashboard.vue b/frontend/src/views/project/ProjectPlanDashboard.vue
index 3712e883de..c42172ed4c 100644
--- a/frontend/src/views/project/ProjectPlanDashboard.vue
+++ b/frontend/src/views/project/ProjectPlanDashboard.vue
@@ -3,7 +3,7 @@
<div
class="w-full flex flex-col lg:flex-row items-start lg:items-center justify-between gap-2"
>
- <div class="flex flex-1 max-w-full items-center gap-x-2">
+ <div class="w-full flex flex-1 items-center justify-between gap-x-2">
<AdvancedSearch
v-model:params="state.params"
class="flex-1"
@@ -46,18 +46,19 @@
import { head } from "lodash-es";
import { PlusIcon } from "lucide-vue-next";
import { NButton } from "naive-ui";
+import { v4 as uuidv4 } from "uuid";
import { computed, reactive, watch, ref } from "vue";
import type { ComponentExposed } from "vue-component-type-helpers";
import { useRouter, type LocationQuery } from "vue-router";
import AdvancedSearch from "@/components/AdvancedSearch";
import { useCommonSearchScopeOptions } from "@/components/AdvancedSearch/useCommonSearchScopeOptions";
-import { targetsForSpec } from "@/components/Plan";
+import { targetsForSpec, getLocalSheetByName } from "@/components/Plan";
import AddSpecDrawer from "@/components/Plan/components/AddSpecDrawer.vue";
import PlanDataTable from "@/components/Plan/components/PlanDataTable";
import PagedTable from "@/components/v2/Model/PagedTable.vue";
import { useIssueLayoutVersion } from "@/composables/useIssueLayoutVersion";
import { PROJECT_V1_ROUTE_PLAN_DETAIL_SPEC_DETAIL } from "@/router/dashboard/projectV1";
-import { useCurrentProjectV1 } from "@/store";
+import { useCurrentProjectV1, useStorageStore } from "@/store";
import { usePlanStore } from "@/store/modules/v1/plan";
import { buildPlanFindBySearchParams } from "@/store/modules/v1/plan";
import { isValidDatabaseGroupName } from "@/types";
@@ -193,6 +194,33 @@ const handleSpecCreated = async (spec: Plan_Spec) => {
const query: LocationQuery = {
template,
};
+
+ // Check if the spec has a sheet with content
+ if (spec.config?.case === "changeDatabaseConfig" && spec.config.value.sheet) {
+ const sheet = getLocalSheetByName(spec.config.value.sheet);
+ if (sheet.content && sheet.content.length > 0) {
+ // Convert Uint8Array to string
+ const statement = new TextDecoder().decode(sheet.content);
+ if (statement) {
+ // For single database, use sqlStorageKey
+ if (!isDatabaseGroup && targets.length === 1) {
+ const sqlStorageKey = `bb.plans.sql.${uuidv4()}`;
+ useStorageStore().put(sqlStorageKey, statement);
+ query.sqlStorageKey = sqlStorageKey;
+ } else {
+ // For multiple databases or database groups, use sqlMapStorageKey
+ const sqlMap: Record<string, string> = {};
+ targets.forEach((target) => {
+ sqlMap[target] = statement;
+ });
+ const sqlMapStorageKey = `bb.plans.sql-map.${uuidv4()}`;
+ useStorageStore().put(sqlMapStorageKey, sqlMap);
+ query.sqlMapStorageKey = sqlMapStorageKey;
+ }
+ }
+ }
+ }
+
if (isDatabaseGroup) {
const databaseGroupName = head(targets);
if (!databaseGroupName) {