Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
refactor: pre-backup setting section (#16129)
boojack1db694611ed4
diff --git a/frontend/src/components/IssueV1/DataExportIssueDetailPage.vue b/frontend/src/components/IssueV1/DataExportIssueDetailPage.vueindex 3956956aca..436f2e9b56 100644--- a/frontend/src/components/IssueV1/DataExportIssueDetailPage.vue+++ b/frontend/src/components/IssueV1/DataExportIssueDetailPage.vue@@ -69,6 +69,7 @@import { ref } from "vue";import { FeatureAttention } from "@/components/FeatureGuard";import type { Task } from "@/types/proto/v1/rollout_service";+import { provideSidebarContext } from "../Plan/logic";import { Drawer } from "../v2";import {BannerSection,@@ -92,11 +93,7 @@ import type {IssueStatusAction,TaskRolloutAction,} from "./logic";-import {- provideIssueSidebarContext,- useIssueContext,- usePollIssue,-} from "./logic";+import { useIssueContext, usePollIssue } from "./logic";const containerRef = ref<HTMLElement>();const { isCreating, events } = useIssueContext();@@ -139,7 +136,7 @@ const {mode: sidebarMode,desktopSidebarWidth,mobileSidebarOpen,-} = provideIssueSidebarContext(containerRef);+} = provideSidebarContext(containerRef);const { existedDeactivatedInstance } = provideIssueIntanceContext();</script>diff --git a/frontend/src/components/IssueV1/GrantRequestIssueDetailPage.vue b/frontend/src/components/IssueV1/GrantRequestIssueDetailPage.vueindex a114458e7b..e3fd77a3f2 100644--- a/frontend/src/components/IssueV1/GrantRequestIssueDetailPage.vue+++ b/frontend/src/components/IssueV1/GrantRequestIssueDetailPage.vue@@ -71,6 +71,7 @@ import { computed, ref } from "vue";import { FeatureAttention } from "@/components/FeatureGuard";import { useEmitteryEventListener } from "@/composables/useEmitteryEventListener";import { PresetRoleType } from "@/types";+import { provideSidebarContext } from "../Plan/logic";import { Drawer } from "../v2";import {BannerSection,@@ -85,11 +86,7 @@ import {} from "./components";import { provideIssueIntanceContext } from "./components/Sidebar/ReviewSection/utils";import type { IssueReviewAction, IssueStatusAction } from "./logic";-import {- provideIssueSidebarContext,- useIssueContext,- usePollIssue,-} from "./logic";+import { useIssueContext, usePollIssue } from "./logic";const containerRef = ref<HTMLElement>();const { isCreating, issue, events } = useIssueContext();@@ -131,7 +128,7 @@ const {mode: sidebarMode,desktopSidebarWidth,mobileSidebarOpen,-} = provideIssueSidebarContext(containerRef);+} = provideSidebarContext(containerRef);const { existedDeactivatedInstance } = provideIssueIntanceContext();</script>diff --git a/frontend/src/components/IssueV1/IssueDetailPage.vue b/frontend/src/components/IssueV1/IssueDetailPage.vueindex a5232137e9..1076f62a99 100644--- a/frontend/src/components/IssueV1/IssueDetailPage.vue+++ b/frontend/src/components/IssueV1/IssueDetailPage.vue@@ -77,6 +77,7 @@import { ref } from "vue";import { FeatureAttention } from "@/components/FeatureGuard";import { type Task } from "@/types/proto/v1/rollout_service";+import { provideSidebarContext } from "../Plan/logic";import { Drawer } from "../v2";import {BannerSection,@@ -101,11 +102,7 @@ import type {IssueStatusAction,TaskRolloutAction,} from "./logic";-import {- provideIssueSidebarContext,- useIssueContext,- usePollIssue,-} from "./logic";+import { useIssueContext, usePollIssue } from "./logic";const containerRef = ref<HTMLElement>();const { isCreating, events } = useIssueContext();@@ -148,7 +145,7 @@ const {mode: sidebarMode,desktopSidebarWidth,mobileSidebarOpen,-} = provideIssueSidebarContext(containerRef);+} = provideSidebarContext(containerRef);const { existedDeactivatedInstance } = provideIssueIntanceContext();</script>diff --git a/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vue b/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vueindex a84b2c7c4f..623507efc2 100644--- a/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vue+++ b/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vue@@ -55,11 +55,11 @@ import {databaseEngineForSpec,databaseForTask,getLocalSheetByName,- isValidSpec,isValidStage,useIssueContext,} from "@/components/IssueV1/logic";import formatSQL from "@/components/MonacoEditor/sqlFormatter";+import { isValidSpec } from "@/components/Plan";import { SQLCheckPanel } from "@/components/SQLCheck";import { STATEMENT_SKIP_CHECK_THRESHOLD } from "@/components/SQLCheck/common";import {diff --git a/frontend/src/components/IssueV1/components/HeaderSection/HeaderSection.vue b/frontend/src/components/IssueV1/components/HeaderSection/HeaderSection.vueindex 39b1561bf9..75bd01281c 100644--- a/frontend/src/components/IssueV1/components/HeaderSection/HeaderSection.vue+++ b/frontend/src/components/IssueV1/components/HeaderSection/HeaderSection.vue@@ -34,9 +34,10 @@import { MenuIcon } from "lucide-vue-next";import { NButton } from "naive-ui";import { computed } from "vue";+import { useSidebarContext } from "@/components/Plan";import { Task_Status } from "@/types/proto/v1/rollout_service";import { activeTaskInRollout, isDatabaseChangeRelatedIssue } from "@/utils";-import { useIssueContext, useIssueSidebarContext } from "../../logic";+import { useIssueContext } from "../../logic";import IssueStatusIcon from "../IssueStatusIcon.vue";import Actions from "./Actions";import Title from "./Title.vue";@@ -52,5 +53,5 @@ const issueTaskStatus = computed(() => {return activeTaskInRollout(issue.value.rolloutEntity).status;});-const { mode: sidebarMode, mobileSidebarOpen } = useIssueSidebarContext();+const { mode: sidebarMode, mobileSidebarOpen } = useSidebarContext();</script>diff --git a/frontend/src/components/IssueV1/components/Sidebar/PreBackupSection/PreBackupSection.vue b/frontend/src/components/IssueV1/components/Sidebar/PreBackupSection/PreBackupSection.vueindex 37a7d9477c..99eaf8e638 100644--- a/frontend/src/components/IssueV1/components/Sidebar/PreBackupSection/PreBackupSection.vue+++ b/frontend/src/components/IssueV1/components/Sidebar/PreBackupSection/PreBackupSection.vue@@ -1,38 +1,72 @@<template>- <div- v-if="showPreBackupSection"- class="w-full flex items-center justify-between gap-x-2 gap-y-1 flex-wrap min-h-[34px] whitespace-nowrap"- >- <NTooltip>- <template #trigger>- <div class="textlabel flex items-center">- <span>{{ $t("task.prior-backup") }}</span>- <span- v-if="showRollbackSection"- class="ml-1 px-1 py-0.5 rounded-lg text-xs bg-green-100 text-green-800"- >- {{ $t("common.on") }}- </span>- </div>- </template>- <template #default>- <div class="max-w-[20rem]">- {{ $t("task.prior-backup-tips") }}- </div>- </template>- </NTooltip>- <div class="flex items-center">- <TaskRollbackButton v-if="showRollbackSection" />- <PreBackupSwitch v-else />- </div>- </div>+ <TaskRollbackSection v-if="shouldShowTaskRollbackSection" />+ <PreBackupSection v-else-if="shouldShowPreBackupSection" /></template><script lang="ts" setup>-import { NTooltip } from "naive-ui";-import PreBackupSwitch from "./PreBackupSwitch.vue";-import TaskRollbackButton from "./TaskRollbackButton.vue";-import { usePreBackupContext } from "./common";+import { computed } from "vue";+import {+ databaseForTask,+ latestTaskRunForTask,+ specForTask,+ useIssueContext,+} from "@/components/IssueV1/logic";+import { PreBackupSection } from "@/components/Plan/components/Sidebar";+import { providePreBackupSettingContext } from "@/components/Plan/components/Sidebar/PreBackupSection/context";+import type { Plan, Plan_Spec } from "@/types/proto/v1/plan_service";+import { TaskRun_Status } from "@/types/proto/v1/rollout_service";+import TaskRollbackSection from "./TaskRollbackSection.vue";+import { ROLLBACK_AVAILABLE_ENGINES } from "./common";-const { showPreBackupSection, showRollbackSection } = usePreBackupContext();+const { isCreating, issue, selectedTask, events } = useIssueContext();+const {+ shouldShow: shouldShowPreBackupSection,+ enabled: preBackupEnabled,+ events: preBackupEvents,+} = providePreBackupSettingContext({+ project: computed(() => issue.value.projectEntity),+ plan: computed(() => issue.value.planEntity as Plan),+ selectedSpec: computed(+ () => specForTask(issue.value.planEntity, selectedTask.value) as Plan_Spec+ ),+ isCreating,+});++const database = computed(() =>+ databaseForTask(issue.value, selectedTask.value)+);++const latestTaskRun = computed(() =>+ latestTaskRunForTask(issue.value, selectedTask.value)+);++const shouldShowTaskRollbackSection = computed((): boolean => {+ if (!shouldShowPreBackupSection.value) {+ return false;+ }+ if (!preBackupEnabled.value) {+ return false;+ }+ if (+ !ROLLBACK_AVAILABLE_ENGINES.includes(database.value.instanceResource.engine)+ ) {+ return false;+ }+ if (!latestTaskRun.value) {+ return false;+ }+ if (latestTaskRun.value.status !== TaskRun_Status.DONE) {+ return false;+ }+ if (latestTaskRun.value.priorBackupDetail?.items.length === 0) {+ return false;+ }+ return true;+});++preBackupEvents.on("update", () => {+ events.emit("status-changed", {+ eager: true,+ });+});</script>diff --git a/frontend/src/components/IssueV1/components/Sidebar/PreBackupSection/PreBackupSwitch.vue b/frontend/src/components/IssueV1/components/Sidebar/PreBackupSection/PreBackupSwitch.vuedeleted file mode 100644index e8927ebe04..0000000000--- a/frontend/src/components/IssueV1/components/Sidebar/PreBackupSection/PreBackupSwitch.vue+++ /dev/null@@ -1,86 +0,0 @@-<template>- <div class="flex items-center">- <NTooltip :disabled="!disallowPreBackupMessage">- <template #trigger>- <NSwitch- :value="preBackupEnabled"- class="bb-pre-backup-switch"- :disabled="!allowPreBackup"- @update:value="togglePreBackup"- >- <template #checked>- <span style="font-size: 10px">{{ $t("common.on") }}</span>- </template>- <template #unchecked>- <span style="font-size: 10px">{{ $t("common.off") }}</span>- </template>- </NSwitch>- </template>- <template #default>- {{ disallowPreBackupMessage }}- <LearnMoreLink- v-if="disallowPreBackupLink"- :url="disallowPreBackupLink"- color="light"- class="ml-1 text-sm"- />- </template>- </NTooltip>- </div>-</template>--<script lang="ts" setup>-import { NSwitch, NTooltip } from "naive-ui";-import { computed } from "vue";-import { useI18n } from "vue-i18n";-import { databaseForTask, useIssueContext } from "@/components/IssueV1/logic";-import LearnMoreLink from "@/components/LearnMoreLink.vue";-import { usePreBackupContext } from "./common";--const { t } = useI18n();-const { issue, selectedTask } = useIssueContext();-const { preBackupEnabled, allowPreBackup, togglePreBackup } =- usePreBackupContext();--const database = computed(() =>- databaseForTask(issue.value, selectedTask.value)-);--const disallowPreBackupMessage = computed(() => {- if (allowPreBackup.value) {- return undefined;- }- if (!database.value.backupAvailable) {- return t("database.create-target-database-or-schema-for-backup");- }- return undefined;-});--const disallowPreBackupLink = computed(() => {- if (allowPreBackup.value) {- return undefined;- }- if (!database.value.backupAvailable) {- return "https://www.bytebase.com/docs/change-database/rollback-data-changes?source=console";- }- return undefined;-});-</script>--<style>-.bb-pre-backup-switch {- --n-width: max(- var(--n-rail-width),- calc(var(--n-rail-width) + var(--n-button-width) - var(--n-rail-height))- ) !important;-}-.bb-pre-backup-switch .n-switch__checked {- padding-right: calc(var(--n-rail-height) - var(--n-offset) + 1px) !important;-}-.bb-pre-backup-switch .n-switch__unchecked {- padding-left: calc(var(--n-rail-height) - var(--n-offset) + 1px) !important;-}-.bb-pre-backup-switch .n-switch__button-placeholder {- width: calc(1.25 * var(--n-rail-height)) !important;-}-</style>diff --git a/frontend/src/components/IssueV1/components/Sidebar/PreBackupSection/TaskRollbackButton.vue b/frontend/src/components/IssueV1/components/Sidebar/PreBackupSection/TaskRollbackButton.vueindex 2baa5a1c7f..3fb71ce366 100644--- a/frontend/src/components/IssueV1/components/Sidebar/PreBackupSection/TaskRollbackButton.vue+++ b/frontend/src/components/IssueV1/components/Sidebar/PreBackupSection/TaskRollbackButton.vue@@ -23,16 +23,19 @@ import { pushNotification, useSheetV1Store, useStorageStore } from "@/store";import {extractIssueUID,extractProjectResourceName,+ hasProjectPermissionV2,sheetNameOfTaskV1,} from "@/utils";-import { usePreBackupContext } from "./common";const router = useRouter();const { issue, selectedTask } = useIssueContext();-const { allowRollback } = usePreBackupContext();const isLoading = ref(false);+const allowRollback = computed((): boolean => {+ return hasProjectPermissionV2(issue.value.projectEntity, "bb.issues.create");+});+const latestTaskRun = computed(() =>latestTaskRunForTask(issue.value, selectedTask.value));diff --git a/frontend/src/components/IssueV1/components/Sidebar/PreBackupSection/TaskRollbackSection.vue b/frontend/src/components/IssueV1/components/Sidebar/PreBackupSection/TaskRollbackSection.vuenew file mode 100644index 0000000000..6cea1325f0--- /dev/null+++ b/frontend/src/components/IssueV1/components/Sidebar/PreBackupSection/TaskRollbackSection.vue@@ -0,0 +1,31 @@+<template>+ <div+ class="w-full flex items-center justify-between gap-x-2 gap-y-1 flex-wrap min-h-[34px] whitespace-nowrap"+ >+ <NTooltip>+ <template #trigger>+ <div class="textlabel flex items-center">+ <span>{{ $t("task.prior-backup") }}</span>+ <span+ class="ml-1 px-1 py-0.5 rounded-lg text-xs bg-green-100 text-green-800"+ >+ {{ $t("common.on") }}+ </span>+ </div>+ </template>+ <template #default>+ <div class="max-w-[20rem]">+ {{ $t("task.prior-backup-tips") }}+ </div>+ </template>+ </NTooltip>+ <div class="flex items-center">+ <TaskRollbackButton />+ </div>+ </div>+</template>++<script lang="ts" setup>+import { NTooltip } from "naive-ui";+import TaskRollbackButton from "./TaskRollbackButton.vue";+</script>diff --git a/frontend/src/components/IssueV1/components/Sidebar/PreBackupSection/common.ts b/frontend/src/components/IssueV1/components/Sidebar/PreBackupSection/common.tsindex e5ba382294..9e86235fbc 100644--- a/frontend/src/components/IssueV1/components/Sidebar/PreBackupSection/common.ts+++ b/frontend/src/components/IssueV1/components/Sidebar/PreBackupSection/common.ts@@ -1,218 +1,8 @@-import { cloneDeep } from "lodash-es";-import { computed } from "vue";-import { useI18n } from "vue-i18n";-import {- databaseForTask,- latestTaskRunForTask,- notifyNotEditableLegacyIssue,- specForTask,- useIssueContext,-} from "@/components/IssueV1/logic";-import { planServiceClient } from "@/grpcweb";-import {- pushNotification,- useCurrentUserV1,- useIssueCommentStore,- extractUserId,-} from "@/store";import { Engine } from "@/types/proto/v1/common";-import {- Task_Status,- Task_Type,- TaskRun_Status,-} from "@/types/proto/v1/rollout_service";-import { hasProjectPermissionV2, isDatabaseChangeRelatedIssue } from "@/utils";-const PRE_BACKUP_AVAILABLE_ENGINES = [- Engine.MYSQL,- Engine.TIDB,- Engine.MSSQL,- Engine.ORACLE,- Engine.POSTGRES,-];--const ROLLBACK_AVAILABLE_ENGINES = [+export const ROLLBACK_AVAILABLE_ENGINES = [Engine.MYSQL,Engine.POSTGRES,Engine.MSSQL,Engine.ORACLE,];--export const usePreBackupContext = () => {- const { t } = useI18n();- const currentUserV1 = useCurrentUserV1();- const { isCreating, issue, selectedTask, events } = useIssueContext();-- const project = computed(() => issue.value.projectEntity);-- const database = computed(() =>- databaseForTask(issue.value, selectedTask.value)- );-- const latestTaskRun = computed(() =>- latestTaskRunForTask(issue.value, selectedTask.value)- );-- const showPreBackupSection = computed((): boolean => {- if (!isDatabaseChangeRelatedIssue(issue.value)) {- return false;- }- if (selectedTask.value.type !== Task_Type.DATABASE_DATA_UPDATE) {- return false;- }- const { engine } = database.value.instanceResource;- if (!PRE_BACKUP_AVAILABLE_ENGINES.includes(engine)) {- return false;- }- return true;- });-- const allowPreBackup = computed((): boolean => {- // Disallow pre-backup if no backup available for the target database.- if (!database.value.backupAvailable) {- return false;- }-- // Allow toggle pre-backup when creating.- if (isCreating.value) {- return true;- }-- // Only allow pre-backup for non-done and non-running tasks.- if (- [Task_Status.DONE, Task_Status.RUNNING].includes(- selectedTask.value.status- )- ) {- return false;- }-- // Allowed to the issue creator.- if (currentUserV1.value.email === extractUserId(issue.value.creator)) {- return true;- }-- if (hasProjectPermissionV2(project.value, "bb.plans.update")) {- return true;- }-- return false;- });-- const preBackupEnabled = computed((): boolean => {- const spec = specForTask(issue.value.planEntity, selectedTask.value);- const database =- spec?.changeDatabaseConfig?.preUpdateBackupDetail?.database;- return database !== undefined && database !== "";- });-- const archiveDatabase = computed((): string => {- const { engine } = database.value.instanceResource;- return getArchiveDatabase(engine);- });-- const togglePreBackup = async (on: boolean) => {- if (isCreating.value) {- const spec = specForTask(issue.value.planEntity, selectedTask.value);- if (spec && spec.changeDatabaseConfig) {- if (on) {- spec.changeDatabaseConfig.preUpdateBackupDetail = {- database:- database.value.instance + "/databases/" + archiveDatabase.value,- };- } else {- spec.changeDatabaseConfig.preUpdateBackupDetail = undefined;- }- }- } else {- // patch plan to reconcile rollout/stages/tasks- const planPatch = cloneDeep(issue.value.planEntity);- const spec = specForTask(planPatch, selectedTask.value);- if (!planPatch || !spec || !spec.changeDatabaseConfig) {- notifyNotEditableLegacyIssue();- return;- }-- if (on) {- spec.changeDatabaseConfig.preUpdateBackupDetail = {- database:- database.value.instance + "/databases/" + archiveDatabase.value,- };- } else {- spec.changeDatabaseConfig.preUpdateBackupDetail = undefined;- }-- const updatedPlan = await planServiceClient.updatePlan({- plan: planPatch,- updateMask: ["steps"],- });- issue.value.planEntity = updatedPlan;-- events.emit("status-changed", { eager: true });- pushNotification({- module: "bytebase",- style: "SUCCESS",- title: t("common.updated"),- });-- const action = on ? "Enable" : "Disable";- try {- await useIssueCommentStore().createIssueComment({- issueName: issue.value.name,- comment: `${action} prior backup for task [${selectedTask.value.target}].`,- });- } catch {- // fail to comment won't be too bad- }- }- };-- const showRollbackSection = computed((): boolean => {- if (!showPreBackupSection.value) {- return false;- }- if (!preBackupEnabled.value) {- return false;- }- if (- !ROLLBACK_AVAILABLE_ENGINES.includes(- database.value.instanceResource.engine- )- ) {- return false;- }- if (!latestTaskRun.value) {- return false;- }- if (latestTaskRun.value.status !== TaskRun_Status.DONE) {- return false;- }- if (latestTaskRun.value.priorBackupDetail?.items.length === 0) {- return false;- }- return true;- });-- const allowRollback = computed((): boolean => {- return hasProjectPermissionV2(project.value, "bb.issues.create");- });-- return {- // Pre-backup related.- showPreBackupSection,- preBackupEnabled,- allowPreBackup,- togglePreBackup,-- // Rollback related.- showRollbackSection,- allowRollback,- };-};--export const getArchiveDatabase = (engine: Engine): string => {- if (engine === Engine.ORACLE) {- return "BBDATAARCHIVE";- }- return "bbdataarchive";-};diff --git a/frontend/src/components/IssueV1/logic/index.ts b/frontend/src/components/IssueV1/logic/index.tsindex 42ba755ed8..b539171d55 100644--- a/frontend/src/components/IssueV1/logic/index.ts+++ b/frontend/src/components/IssueV1/logic/index.ts@@ -12,4 +12,3 @@ export * from "./plan-check";export * from "./task-run";export * from "./poll";export * from "./subscriber";-export * from "./sidebar";diff --git a/frontend/src/components/IssueV1/logic/initialize/create.ts b/frontend/src/components/IssueV1/logic/initialize/create.tsindex 42a1acff1b..47c1b2986e 100644--- a/frontend/src/components/IssueV1/logic/initialize/create.ts+++ b/frontend/src/components/IssueV1/logic/initialize/create.ts@@ -2,6 +2,8 @@ import { cloneDeep, groupBy, orderBy } from "lodash-es";import { v4 as uuidv4 } from "uuid";import { reactive } from "vue";import { useRoute } from "vue-router";+import { extractInitialSQLFromQuery } from "@/components/Plan";+import { getArchiveDatabase } from "@/components/Plan/components/Sidebar/PreBackupSection/utils";import { rolloutServiceClient } from "@/grpcweb";import {useChangelistStore,@@ -10,7 +12,6 @@ import {useEnvironmentV1Store,useProjectV1Store,useSheetV1Store,- useStorageStore,batchGetOrFetchDatabases,} from "@/store";import {@@ -43,7 +44,6 @@ import {setSheetStatement,sheetNameOfTaskV1,} from "@/utils";-import { getArchiveDatabase } from "../../components/Sidebar/PreBackupSection/common";import { nextUID } from "../base";import { databaseEngineForSpec, sheetNameForSpec } from "../plan";import { getLocalSheetByName } from "../sheet";@@ -401,32 +401,6 @@ const maybeSetInitialSQLForSpec = (}};-const extractInitialSQLFromQuery = async (- query: Record<string, string>-): Promise<InitialSQL> => {- const storageStore = useStorageStore();- const sql = query.sql;- if (sql && typeof sql === "string") {- return {- sql,- };- }- const sqlStorageKey = query.sqlStorageKey;- if (sqlStorageKey && typeof sqlStorageKey === "string") {- const sql = (await storageStore.get(sqlStorageKey)) || "";- return {- sql,- };- }- const sqlMapStorageKey = query.sqlMapStorageKey;- if (sqlMapStorageKey && typeof sqlMapStorageKey === "string") {- const sqlMap =- (await storageStore.get<Record<string, string>>(sqlMapStorageKey)) || {};- return { sqlMap };- }- return {};-};-const hasInitialSQL = (initialSQL?: InitialSQL) => {if (!initialSQL) {return false;@@ -467,28 +441,3 @@ export const isValidStage = (stage: Stage): boolean => {}return true;};--export const isValidSpec = (spec: Plan_Spec): boolean => {- if (spec.changeDatabaseConfig || spec.exportDataConfig) {- const sheetName = sheetNameForSpec(spec);- if (!sheetName) {- return false;- }- const uid = extractSheetUID(sheetName);- if (uid.startsWith("-")) {- const sheet = getLocalSheetByName(sheetName);- if (getSheetStatement(sheet).length === 0) {- return false;- }- } else {- const sheet = useSheetV1Store().getSheetByName(sheetName);- if (!sheet) {- return false;- }- if (getSheetStatement(sheet).length === 0) {- return false;- }- }- }- return true;-};diff --git a/frontend/src/components/IssueV1/logic/plan.ts b/frontend/src/components/IssueV1/logic/plan.tsindex 16257c8091..0ddfcee676 100644--- a/frontend/src/components/IssueV1/logic/plan.ts+++ b/frontend/src/components/IssueV1/logic/plan.ts@@ -1,61 +1,10 @@import { head } from "lodash-es";-import { mockDatabase } from "@/components/IssueV1/logic/utils";-import {- useDatabaseV1Store,- useDBGroupStore,- useEnvironmentV1Store,- useInstanceResourceByName,-} from "@/store";-import {- UNKNOWN_ID,- type ComposedIssue,- unknownDatabase,- type ComposedDatabase,- isValidDatabaseName,-} from "@/types";+import { useDatabaseV1Store, useDBGroupStore } from "@/store";+import { UNKNOWN_ID, isValidDatabaseName } from "@/types";import { Engine } from "@/types/proto/v1/common";import type { Plan_Spec } from "@/types/proto/v1/plan_service";import { extractDatabaseResourceName, extractDatabaseGroupName } from "@/utils";-export const databaseForSpec = (- issue: ComposedIssue,- spec: Plan_Spec-): ComposedDatabase => {- const environmentStore = useEnvironmentV1Store();- const { createDatabaseConfig, changeDatabaseConfig, exportDataConfig } = spec;- if (createDatabaseConfig !== undefined) {- const instanceName = createDatabaseConfig.target;- const databaseName = createDatabaseConfig.database;- const { instance } = useInstanceResourceByName(instanceName);- return {- ...unknownDatabase(),- name: `${instanceName}/databases/${databaseName}`,- databaseName,- instance: instanceName,- project: issue.project,- projectEntity: issue.projectEntity,- effectiveEnvironment: instance.value.environment,- effectiveEnvironmentEntity: environmentStore.getEnvironmentByName(- instance.value.environment- ),- instanceResource: instance.value,- };- } else if (- changeDatabaseConfig !== undefined ||- exportDataConfig !== undefined- ) {- // TODO(steven): handle db group and deployment config.- const target = (changeDatabaseConfig?.target ??- exportDataConfig?.target) as string;- const db = useDatabaseV1Store().getDatabaseByName(target);- if (!isValidDatabaseName(db.name)) {- return mockDatabase(issue.projectEntity, target);- }- return db;- }- return unknownDatabase();-};-/**** @returns empty string if no sheet founddiff --git a/frontend/src/components/Plan/PlanDetailPage.vue b/frontend/src/components/Plan/PlanDetailPage.vueindex 0b4cddb108..6812f01096 100644--- a/frontend/src/components/Plan/PlanDetailPage.vue+++ b/frontend/src/components/Plan/PlanDetailPage.vue@@ -1,5 +1,5 @@<template>- <div class="h-full flex flex-col">+ <div ref="containerRef" class="h-full flex flex-col"><div class="border-b"><HeaderSection /></div>@@ -13,11 +13,38 @@<StatementSection /><DescriptionSection /></div>+ <div+ v-if="sidebarMode == 'DESKTOP'"+ class="hide-scrollbar border-l"+ :style="{+ width: `${desktopSidebarWidth}px`,+ }"+ >+ <Sidebar />+ </div></div></div>++ <template v-if="sidebarMode === 'MOBILE'">+ <!-- mobile sidebar -->+ <Drawer :show="mobileSidebarOpen" @close="mobileSidebarOpen = false">+ <div+ style="+ min-width: 240px;+ width: 80vw;+ max-width: 320px;+ padding: 0.5rem 0;+ "+ >+ <Sidebar v-if="sidebarMode === 'MOBILE'" />+ </div>+ </Drawer>+ </template></template><script setup lang="ts">+import { ref } from "vue";+import { Drawer } from "@/components/v2";import {HeaderSection,PlanCheckSection,@@ -27,11 +54,20 @@ import {SpecListSection,} from "./components";import { providePlanSQLCheckContext } from "./components/SQLCheckSectionV1/context";+import Sidebar from "./components/Sidebar";import { usePlanContext, usePollPlan } from "./logic";+import { provideSidebarContext } from "./logic";+const containerRef = ref<HTMLElement>();const { isCreating } = usePlanContext();usePollPlan();providePlanSQLCheckContext();++const {+ mode: sidebarMode,+ desktopSidebarWidth,+ mobileSidebarOpen,+} = provideSidebarContext(containerRef);</script>diff --git a/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckSection.vue b/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckSection.vueindex 2348b08657..92fb158582 100644--- a/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckSection.vue+++ b/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckSection.vue@@ -34,7 +34,7 @@ const show = computed(() => {});const database = computed(() =>- databaseForSpec(plan.value, selectedSpec.value)+ databaseForSpec(plan.value.projectEntity, selectedSpec.value));const allowRunChecks = computed(() => {diff --git a/frontend/src/components/Plan/components/SQLCheckSectionV1/SQLCheckBadge.vue b/frontend/src/components/Plan/components/SQLCheckSectionV1/SQLCheckBadge.vueindex 40ac3eb75c..a627c42ac8 100644--- a/frontend/src/components/Plan/components/SQLCheckSectionV1/SQLCheckBadge.vue+++ b/frontend/src/components/Plan/components/SQLCheckSectionV1/SQLCheckBadge.vue@@ -54,7 +54,7 @@ const { plan, selectedSpec } = usePlanContext();const showDetailPanel = ref(false);const database = computed(() => {- return databaseForSpec(plan.value, selectedSpec.value);+ return databaseForSpec(plan.value.projectEntity, selectedSpec.value);});const status = computed(() => {diff --git a/frontend/src/components/Plan/components/SQLCheckSectionV1/SQLCheckButton.vue b/frontend/src/components/Plan/components/SQLCheckSectionV1/SQLCheckButton.vueindex 7904b8007a..83cb30ee49 100644--- a/frontend/src/components/Plan/components/SQLCheckSectionV1/SQLCheckButton.vue+++ b/frontend/src/components/Plan/components/SQLCheckSectionV1/SQLCheckButton.vue@@ -97,7 +97,7 @@ const advices = computed(() => {});const database = computed(() =>- databaseForSpec(plan.value, selectedSpec.value)+ databaseForSpec(plan.value.projectEntity, selectedSpec.value));const statement = computed(() => sheetStatement.value);diff --git a/frontend/src/components/Plan/components/SQLCheckSectionV1/SQLCheckSection.vue b/frontend/src/components/Plan/components/SQLCheckSectionV1/SQLCheckSection.vueindex 716a3dd6a9..ca8c50a076 100644--- a/frontend/src/components/Plan/components/SQLCheckSectionV1/SQLCheckSection.vue+++ b/frontend/src/components/Plan/components/SQLCheckSectionV1/SQLCheckSection.vue@@ -48,7 +48,7 @@ const { plan, selectedSpec } = usePlanContext();const { resultMap } = usePlanSQLCheckContext();const database = computed(() => {- return databaseForSpec(plan.value, selectedSpec.value);+ return databaseForSpec(plan.value.projectEntity, selectedSpec.value);});const checkResult = computed(() => {diff --git a/frontend/src/components/Plan/components/Sidebar/PreBackupSection/PreBackupSection.vue b/frontend/src/components/Plan/components/Sidebar/PreBackupSection/PreBackupSection.vuenew file mode 100644index 0000000000..835e5a0741--- /dev/null+++ b/frontend/src/components/Plan/components/Sidebar/PreBackupSection/PreBackupSection.vue@@ -0,0 +1,26 @@+<template>+ <div+ class="w-full flex items-center justify-between gap-x-2 gap-y-1 flex-wrap min-h-[34px] whitespace-nowrap"+ >+ <NTooltip>+ <template #trigger>+ <div class="textlabel flex items-center">+ <span>{{ $t("task.prior-backup") }}</span>+ </div>+ </template>+ <template #default>+ <div class="max-w-[20rem]">+ {{ $t("task.prior-backup-tips") }}+ </div>+ </template>+ </NTooltip>+ <div class="flex items-center">+ <PreBackupSwitch />+ </div>+ </div>+</template>++<script lang="ts" setup>+import { NTooltip } from "naive-ui";+import PreBackupSwitch from "./PreBackupSwitch.vue";+</script>diff --git a/frontend/src/components/Plan/components/Sidebar/PreBackupSection/PreBackupSwitch.vue b/frontend/src/components/Plan/components/Sidebar/PreBackupSection/PreBackupSwitch.vuenew file mode 100644index 0000000000..8a1335210c--- /dev/null+++ b/frontend/src/components/Plan/components/Sidebar/PreBackupSection/PreBackupSwitch.vue@@ -0,0 +1,53 @@+<template>+ <div class="flex items-center">+ <NTooltip :disabled="!disallowPreBackupMessage">+ <template #trigger>+ <NSwitch+ :value="enabled"+ :disabled="!allowChange"+ @update:value="toggle"+ />+ </template>+ <template #default>+ {{ disallowPreBackupMessage }}+ <LearnMoreLink+ v-if="disallowPreBackupLink"+ :url="disallowPreBackupLink"+ color="light"+ class="ml-1 text-sm"+ />+ </template>+ </NTooltip>+ </div>+</template>++<script lang="ts" setup>+import { NSwitch, NTooltip } from "naive-ui";+import { computed } from "vue";+import { useI18n } from "vue-i18n";+import LearnMoreLink from "@/components/LearnMoreLink.vue";+import { usePreBackupSettingContext } from "./context";++const { t } = useI18n();+const { enabled, allowChange, database, toggle } = usePreBackupSettingContext();++const disallowPreBackupMessage = computed(() => {+ if (allowChange.value) {+ return undefined;+ }+ if (!database.value.backupAvailable) {+ return t("database.create-target-database-or-schema-for-backup");+ }+ return undefined;+});++const disallowPreBackupLink = computed(() => {+ if (allowChange.value) {+ return undefined;+ }+ if (!database.value.backupAvailable) {+ return "https://www.bytebase.com/docs/change-database/rollback-data-changes?source=console";+ }+ return undefined;+});+</script>diff --git a/frontend/src/components/Plan/components/Sidebar/PreBackupSection/context.ts b/frontend/src/components/Plan/components/Sidebar/PreBackupSection/context.tsnew file mode 100644index 0000000000..fe23fb1477--- /dev/null+++ b/frontend/src/components/Plan/components/Sidebar/PreBackupSection/context.ts@@ -0,0 +1,181 @@+import Emittery from "emittery";+import { cloneDeep } from "lodash-es";+import {+ computed,+ inject,+ provide,+ unref,+ type InjectionKey,+ type Ref,+} from "vue";+import { useI18n } from "vue-i18n";+import { databaseForSpec, isDatabaseChangeSpec } from "@/components/Plan/logic";+import { planServiceClient } from "@/grpcweb";+import { pushNotification, useCurrentUserV1, extractUserId } from "@/store";+import type { ComposedProject } from "@/types";+import { Engine } from "@/types/proto/v1/common";+import type { Issue } from "@/types/proto/v1/issue_service";+import {+ Plan_ChangeDatabaseConfig_Type,+ type Plan,+ type Plan_Spec,+} from "@/types/proto/v1/plan_service";+import {+ flattenSpecList,+ hasProjectPermissionV2,+ isNullOrUndefined,+} from "@/utils";+import { getArchiveDatabase } from "./utils";++const PRE_BACKUP_AVAILABLE_ENGINES = [+ Engine.MYSQL,+ Engine.TIDB,+ Engine.MSSQL,+ Engine.ORACLE,+ Engine.POSTGRES,+];++const KEY = Symbol(+ "bb.changelist.dashboard"+) as InjectionKey<PreBackupSettingContext>;++export const usePreBackupSettingContext = () => {+ return inject(KEY)!;+};++export const providePreBackupSettingContext = (refs: {+ project: Ref<ComposedProject>;+ plan: Ref<Plan>;+ selectedSpec: Ref<Plan_Spec>;+ isCreating: Ref<boolean>;+ issue?: Ref<Issue>;+}) => {+ const { t } = useI18n();+ const currentUserV1 = useCurrentUserV1();+ const { project, plan, selectedSpec, isCreating } = refs;++ const events = new Emittery<{+ update: boolean;+ }>();++ const database = computed(() =>+ databaseForSpec(project.value, selectedSpec.value)+ );++ const shouldShow = computed((): boolean => {+ if (!isDatabaseChangeSpec(selectedSpec.value)) {+ return false;+ }+ if (+ selectedSpec.value.changeDatabaseConfig?.type !==+ Plan_ChangeDatabaseConfig_Type.DATA+ ) {+ return false;+ }+ const { engine } = database.value.instanceResource;+ if (!PRE_BACKUP_AVAILABLE_ENGINES.includes(engine)) {+ return false;+ }+ return true;+ });++ const allowChange = computed((): boolean => {+ // Disallow pre-backup if no backup available for the target database.+ if (!database.value.backupAvailable) {+ return false;+ }++ // Allow toggle pre-backup when creating.+ if (isCreating.value) {+ return true;+ }++ // Allowed to the plan/issue creator.+ if (currentUserV1.value.email === extractUserId(unref(plan).creator)) {+ return true;+ }++ // Allowed to the permission holder.+ if (hasProjectPermissionV2(project.value, "bb.plans.update")) {+ return true;+ }++ return false;+ });++ const enabled = computed((): boolean => {+ const preBackupDatabase =+ selectedSpec.value.changeDatabaseConfig?.preUpdateBackupDetail?.database;+ return !isNullOrUndefined(preBackupDatabase) && preBackupDatabase !== "";+ });++ const archiveDatabase = computed((): string =>+ getArchiveDatabase(database.value.instanceResource.engine)+ );++ const toggle = async (on: boolean) => {+ if (isCreating.value) {+ if (selectedSpec.value && selectedSpec.value.changeDatabaseConfig) {+ if (on) {+ selectedSpec.value.changeDatabaseConfig.preUpdateBackupDetail = {+ database:+ database.value.instance + "/databases/" + archiveDatabase.value,+ };+ } else {+ selectedSpec.value.changeDatabaseConfig.preUpdateBackupDetail =+ undefined;+ }+ }+ } else {+ const planPatch = cloneDeep(unref(plan));+ const spec = flattenSpecList(planPatch).find((s) => {+ return s.id === selectedSpec.value.id;+ });+ if (!planPatch || !spec || !spec.changeDatabaseConfig) {+ // Should not reach here.+ throw new Error(+ "Plan or spec is not defined. Cannot update pre-backup setting."+ );+ }+ if (on) {+ spec.changeDatabaseConfig.preUpdateBackupDetail = {+ database:+ database.value.instance + "/databases/" + archiveDatabase.value,+ };+ } else {+ spec.changeDatabaseConfig.preUpdateBackupDetail = undefined;+ }++ await planServiceClient.updatePlan({+ plan: planPatch,+ updateMask: ["steps"],+ });++ pushNotification({+ module: "bytebase",+ style: "SUCCESS",+ title: t("common.updated"),+ });+ }++ // Emit the update event.+ events.emit("update", on);+ };++ const context = {+ shouldShow,+ enabled,+ allowChange,+ database,+ events,+ toggle,+ };++ provide(KEY, context);++ return context;+};++type PreBackupSettingContext = ReturnType<+ typeof providePreBackupSettingContext+>;diff --git a/frontend/src/components/Plan/components/Sidebar/PreBackupSection/index.ts b/frontend/src/components/Plan/components/Sidebar/PreBackupSection/index.tsnew file mode 100644index 0000000000..9ded4d6044--- /dev/null+++ b/frontend/src/components/Plan/components/Sidebar/PreBackupSection/index.ts@@ -0,0 +1,3 @@+import PreBackupSection from "./PreBackupSection.vue";++export default PreBackupSection;diff --git a/frontend/src/components/Plan/components/Sidebar/PreBackupSection/utils.ts b/frontend/src/components/Plan/components/Sidebar/PreBackupSection/utils.tsnew file mode 100644index 0000000000..cd9f2f3bfe--- /dev/null+++ b/frontend/src/components/Plan/components/Sidebar/PreBackupSection/utils.ts@@ -0,0 +1,8 @@+import { Engine } from "@/types/proto/v1/common";++export const getArchiveDatabase = (engine: Engine): string => {+ if (engine === Engine.ORACLE) {+ return "BBDATAARCHIVE";+ }+ return "bbdataarchive";+};diff --git a/frontend/src/components/Plan/components/Sidebar/Sidebar.vue b/frontend/src/components/Plan/components/Sidebar/Sidebar.vuenew file mode 100644index 0000000000..3774e4a271--- /dev/null+++ b/frontend/src/components/Plan/components/Sidebar/Sidebar.vue@@ -0,0 +1,33 @@+<template>+ <div v-if="shouldShow" class="flex flex-col gap-y-3 py-2 px-3">+ <p class="textinfolabel -mb-2">{{ $t("common.options") }}</p>+ <PreBackupSection v-if="shouldShowPreBackupSection" />+ </div>+</template>++<script lang="ts" setup>+import { computed } from "vue";+import { usePlanContext } from "../../logic";+import PreBackupSection from "./PreBackupSection";+import { providePreBackupSettingContext } from "./PreBackupSection/context";++const { isCreating, plan, selectedSpec, events } = usePlanContext();++const { shouldShow: shouldShowPreBackupSection, events: preBackupEvents } =+ providePreBackupSettingContext({+ project: computed(() => plan.value.projectEntity),+ plan: plan,+ selectedSpec: selectedSpec,+ isCreating,+ });++const shouldShow = computed(() => {+ return shouldShowPreBackupSection.value;+});++preBackupEvents.on("update", () => {+ events.emit("status-changed", {+ eager: true,+ });+});+</script>diff --git a/frontend/src/components/Plan/components/Sidebar/index.ts b/frontend/src/components/Plan/components/Sidebar/index.tsnew file mode 100644index 0000000000..9343c6934b--- /dev/null+++ b/frontend/src/components/Plan/components/Sidebar/index.ts@@ -0,0 +1,6 @@+import PreBackupSection from "./PreBackupSection";+import Sidebar from "./Sidebar.vue";++export default Sidebar;++export { PreBackupSection };diff --git a/frontend/src/components/Plan/components/SpecListSection/CurrentSpecSection.vue b/frontend/src/components/Plan/components/SpecListSection/CurrentSpecSection.vueindex 5e7c1a494d..ff0efba3c7 100644--- a/frontend/src/components/Plan/components/SpecListSection/CurrentSpecSection.vue+++ b/frontend/src/components/Plan/components/SpecListSection/CurrentSpecSection.vue@@ -88,7 +88,7 @@ withDefaults(const { plan, selectedSpec } = usePlanContext();const coreDatabaseInfo = computed(() => {- return databaseForSpec(plan.value, selectedSpec.value);+ return databaseForSpec(plan.value.projectEntity, selectedSpec.value);});const isCreatingDatabaseSpec = computed(diff --git a/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue b/frontend/src/components/Plan/components/SpecListSection/SpecCard.vueindex cc12b026c7..c9b5373dd4 100644--- a/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue+++ b/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue@@ -35,12 +35,12 @@class="flex items-center gap-1 truncate"><InstanceV1Name- :instance="databaseForSpec(plan, spec).instanceResource"+ :instance="databaseForSpec(plan.projectEntity, spec).instanceResource":link="false"class="text-gray-500 text-sm"/><span class="truncate text-sm">{{- databaseForSpec(plan, spec).databaseName+ databaseForSpec(plan.projectEntity, spec).databaseName}}</span></div><divdiff --git a/frontend/src/components/Plan/components/SpecListSection/SpecListSection.vue b/frontend/src/components/Plan/components/SpecListSection/SpecListSection.vueindex a07e81960c..9bbdb5885b 100644--- a/frontend/src/components/Plan/components/SpecListSection/SpecListSection.vue+++ b/frontend/src/components/Plan/components/SpecListSection/SpecListSection.vue@@ -158,7 +158,7 @@ const loadMore = useDebounceFn(async () => {const toIndex = fromIndex + SPEC_PER_PAGE;const databaseNames = filteredSpecList.value.slice(fromIndex, toIndex)- .map((spec) => databaseForSpec(plan.value, spec).name);+ .map((spec) => databaseForSpec(plan.value.projectEntity, spec).name);state.isRequesting = true;try {diff --git a/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue b/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vueindex 566c3f417c..e1e06093a6 100644--- a/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue+++ b/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue@@ -256,7 +256,7 @@ const state = reactive<LocalState>({});const database = computed(() => {- return databaseForSpec(plan.value, selectedSpec.value);+ return databaseForSpec(plan.value.projectEntity, selectedSpec.value);});const language = useInstanceV1EditorLanguage(@@ -275,7 +275,10 @@ const statementTitle = computed(() => {return language.value === "sql" ? t("common.sql") : t("common.statement");});const advices = computed(() => {- const database = databaseForSpec(plan.value, selectedSpec.value);+ const database = databaseForSpec(+ plan.value.projectEntity,+ selectedSpec.value+ );return resultMap.value[database.name]?.advices || [];});const { markers } = useSQLAdviceMarkers(context, advices);diff --git a/frontend/src/components/Plan/logic/index.ts b/frontend/src/components/Plan/logic/index.tsindex 3cd9982525..06df74229d 100644--- a/frontend/src/components/Plan/logic/index.ts+++ b/frontend/src/components/Plan/logic/index.ts@@ -6,3 +6,4 @@ export * from "./sheet";export * from "./plan-check";export * from "./poll";export * from "./utils";+export * from "./sidebar";diff --git a/frontend/src/components/Plan/logic/initialize/create.ts b/frontend/src/components/Plan/logic/initialize/create.tsindex 5eaa1325ad..f7c495a616 100644--- a/frontend/src/components/Plan/logic/initialize/create.ts+++ b/frontend/src/components/Plan/logic/initialize/create.ts@@ -7,7 +7,6 @@ import {useEnvironmentV1Store,useProjectV1Store,useSheetV1Store,- useStorageStore,batchGetOrFetchDatabases,} from "@/store";import { projectNamePrefix } from "@/store/modules/v1/common";@@ -29,6 +28,7 @@ import {} from "@/utils";import { databaseEngineForSpec, sheetNameForSpec } from "../plan";import { createEmptyLocalSheet, getLocalSheetByName } from "../sheet";+import { extractInitialSQLFromQuery } from "./util";export type InitialSQL = {sqlMap?: Record<string, string>;@@ -319,32 +319,6 @@ const maybeSetInitialSQLForSpec = (}};-const extractInitialSQLFromQuery = async (- query: Record<string, string>-): Promise<InitialSQL> => {- const storageStore = useStorageStore();- const sql = query.sql;- if (sql && typeof sql === "string") {- return {- sql,- };- }- const sqlStorageKey = query.sqlStorageKey;- if (sqlStorageKey && typeof sqlStorageKey === "string") {- const sql = (await storageStore.get(sqlStorageKey)) || "";- return {- sql,- };- }- const sqlMapStorageKey = query.sqlMapStorageKey;- if (sqlMapStorageKey && typeof sqlMapStorageKey === "string") {- const sqlMap =- (await storageStore.get<Record<string, string>>(sqlMapStorageKey)) || {};- return { sqlMap };- }- return {};-};-const hasInitialSQL = (initialSQL?: InitialSQL) => {if (!initialSQL) {return false;@@ -357,28 +331,3 @@ const hasInitialSQL = (initialSQL?: InitialSQL) => {}return false;};--export const isValidSpec = (spec: Plan_Spec): boolean => {- if (spec.changeDatabaseConfig) {- const sheetName = sheetNameForSpec(spec);- if (!sheetName) {- return false;- }- const uid = extractSheetUID(sheetName);- if (uid.startsWith("-")) {- const sheet = getLocalSheetByName(sheetName);- if (getSheetStatement(sheet).length === 0) {- return false;- }- } else {- const sheet = useSheetV1Store().getSheetByName(sheetName);- if (!sheet) {- return false;- }- if (getSheetStatement(sheet).length === 0) {- return false;- }- }- }- return true;-};diff --git a/frontend/src/components/Plan/logic/initialize/index.ts b/frontend/src/components/Plan/logic/initialize/index.tsindex 4fcdcff04c..653ccdcd44 100644--- a/frontend/src/components/Plan/logic/initialize/index.ts+++ b/frontend/src/components/Plan/logic/initialize/index.ts@@ -10,6 +10,8 @@ import { createPlanSkeleton } from "./create";export * from "./create";+export * from "./util";+export function useInitializePlan(planSlug: MaybeRef<string>,project: MaybeRef<string> = "-",diff --git a/frontend/src/components/Plan/logic/initialize/util.ts b/frontend/src/components/Plan/logic/initialize/util.tsnew file mode 100644index 0000000000..a3633067ef--- /dev/null+++ b/frontend/src/components/Plan/logic/initialize/util.ts@@ -0,0 +1,57 @@+import { useSheetV1Store, useStorageStore } from "@/store";+import type { Plan_Spec } from "@/types/proto/v1/plan_service";+import { extractSheetUID, getSheetStatement } from "@/utils";+import { sheetNameForSpec } from "../plan";+import { getLocalSheetByName } from "../sheet";+import type { InitialSQL } from "./create";++export const extractInitialSQLFromQuery = async (+ query: Record<string, string>+): Promise<InitialSQL> => {+ const storageStore = useStorageStore();+ const sql = query.sql;+ if (sql && typeof sql === "string") {+ return {+ sql,+ };+ }+ const sqlStorageKey = query.sqlStorageKey;+ if (sqlStorageKey && typeof sqlStorageKey === "string") {+ const sql = (await storageStore.get(sqlStorageKey)) || "";+ return {+ sql,+ };+ }+ const sqlMapStorageKey = query.sqlMapStorageKey;+ if (sqlMapStorageKey && typeof sqlMapStorageKey === "string") {+ const sqlMap =+ (await storageStore.get<Record<string, string>>(sqlMapStorageKey)) || {};+ return { sqlMap };+ }+ return {};+};++export const isValidSpec = (spec: Plan_Spec): boolean => {+ if (spec.changeDatabaseConfig) {+ const sheetName = sheetNameForSpec(spec);+ if (!sheetName) {+ return false;+ }+ const uid = extractSheetUID(sheetName);+ if (uid.startsWith("-")) {+ const sheet = getLocalSheetByName(sheetName);+ if (getSheetStatement(sheet).length === 0) {+ return false;+ }+ } else {+ const sheet = useSheetV1Store().getSheetByName(sheetName);+ if (!sheet) {+ return false;+ }+ if (getSheetStatement(sheet).length === 0) {+ return false;+ }+ }+ }+ return true;+};diff --git a/frontend/src/components/Plan/logic/plan-check.ts b/frontend/src/components/Plan/logic/plan-check.tsindex 9d87ad5f24..9b4541eb65 100644--- a/frontend/src/components/Plan/logic/plan-check.ts+++ b/frontend/src/components/Plan/logic/plan-check.ts@@ -13,7 +13,7 @@ export const planCheckRunListForSpec = (plan: ComposedPlan,spec: Plan_Spec) => {- const target = databaseForSpec(plan, spec).name;+ const target = databaseForSpec(plan.projectEntity, spec).name;const sheet = spec ? sheetNameForSpec(spec) : "";return plan.planCheckRunList.filter((check) => {if (sheet && check.sheet) {diff --git a/frontend/src/components/Plan/logic/plan.ts b/frontend/src/components/Plan/logic/plan.tsindex 2e7812c581..4814ca099c 100644--- a/frontend/src/components/Plan/logic/plan.ts+++ b/frontend/src/components/Plan/logic/plan.ts@@ -1,19 +1,22 @@import { mockDatabase } from "@/components/IssueV1/logic/utils";import { useDatabaseV1Store } from "@/store";-import { isValidDatabaseName, unknownDatabase } from "@/types";+import {+ isValidDatabaseName,+ unknownDatabase,+ type ComposedProject,+} from "@/types";import { Engine } from "@/types/proto/v1/common";import type { Plan_Spec } from "@/types/proto/v1/plan_service";-import type { ComposedPlan } from "@/types/v1/issue/plan";import { extractDatabaseGroupName } from "@/utils";-export const databaseForSpec = (plan: ComposedPlan, spec: Plan_Spec) => {+export const databaseForSpec = (project: ComposedProject, spec: Plan_Spec) => {// Now we only handle changeDatabaseConfig specs.const { changeDatabaseConfig } = spec;if (changeDatabaseConfig !== undefined) {const target = changeDatabaseConfig.target;const db = useDatabaseV1Store().getDatabaseByName(target);if (!isValidDatabaseName(db.name)) {- return mockDatabase(plan.projectEntity, target);+ return mockDatabase(project, target);}return db;}diff --git a/frontend/src/components/IssueV1/logic/sidebar.ts b/frontend/src/components/Plan/logic/sidebar.tssimilarity index 86%rename from frontend/src/components/IssueV1/logic/sidebar.tsrename to frontend/src/components/Plan/logic/sidebar.tsindex 219acb44ea..a19379831c 100644--- a/frontend/src/components/IssueV1/logic/sidebar.ts+++ b/frontend/src/components/Plan/logic/sidebar.ts@@ -10,13 +10,13 @@ export type SidebarContext = {mobileSidebarOpen: Ref<boolean>;};-const KEY = Symbol("bb.issue.detail.sidebar") as InjectionKey<SidebarContext>;+const KEY = Symbol("bb.plan.detail.sidebar") as InjectionKey<SidebarContext>;-export const useIssueSidebarContext = () => {+export const useSidebarContext = () => {return inject(KEY)!;};-export const provideIssueSidebarContext = (+export const provideSidebarContext = (containerRef: Ref<HTMLElement | undefined>) => {const { width: containerWidth } = useElementSize(containerRef);diff --git a/frontend/src/components/SchemaEditorLite/common.ts b/frontend/src/components/SchemaEditorLite/common.tsindex 536ae21117..34e4cc75ee 100644--- a/frontend/src/components/SchemaEditorLite/common.ts+++ b/frontend/src/components/SchemaEditorLite/common.ts@@ -5,14 +5,9 @@ import { useSettingV1Store } from "@/store";import type { ComposedDatabase } from "@/types";import type { DatabaseCatalog } from "@/types/proto/v1/database_catalog_service";import type { DatabaseMetadata } from "@/types/proto/v1/database_service";-import { TinyTimer } from "@/utils";import { extractGrpcErrorMessage } from "@/utils/grpcweb";import { validateDatabaseMetadata } from "./utils";-export const _generateDiffDDLTimer = new TinyTimer<"generateDiffDDL">(- "GenerateDiffDDL"-);-export type GenerateDiffDDLResult = {statement: string;errors: string[];@@ -34,7 +29,6 @@ export const generateDiffDDL = async ({allowEmptyDiffDDLWithConfigChange?: boolean;}): Promise<GenerateDiffDDLResult> => {const finish = (statement: string, errors: string[]) => {- _generateDiffDDLTimer.end("generateDiffDDL");return {statement,errors,diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 705c1f9aae..c93721876d 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -224,7 +224,8 @@"catalog": "Catalog","summary": "Summary","errors": "Errors",- "removed": "Removed"+ "removed": "Removed",+ "options": "Options"},"error-page": {"go-back-home": "Go back home"diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex 0c9632de92..98ebe46c43 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -224,7 +224,8 @@"catalog": "Catálogo","summary": "Resumen","errors": "Errores",- "removed": "Remoto"+ "removed": "Remoto",+ "options": "Opciones"},"error-page": {"go-back-home": "Volver al inicio"diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex 2a26288a65..7df09e77a2 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -224,7 +224,8 @@"catalog": "カタログ","summary": "まとめ","errors": "エラー",- "removed": "削除されました"+ "removed": "削除されました",+ "options": "オプション"},"error-page": {"go-back-home": "ホームページに戻る"diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.jsonindex dc4d835a78..6c5009d7ca 100644--- a/frontend/src/locales/vi-VN.json+++ b/frontend/src/locales/vi-VN.json@@ -224,7 +224,8 @@"catalog": "Danh mục","summary": "Tóm tắt","errors": "Lỗi",- "removed": "LOẠI BỎ"+ "removed": "LOẠI BỎ",+ "options": "Tùy chọn"},"error-page": {"go-back-home": "Về trang chủ"diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 81dfd5f7b9..501516c4dd 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -224,7 +224,8 @@"catalog": "Catalog","summary": "总结","errors": "错误",- "removed": "已移除"+ "removed": "已移除",+ "options": "配置项"},"error-page": {"go-back-home": "回到主页"@@ -2612,4 +2613,4 @@"last-visit": "上次访问","changelog-for-version": "{version} 的更新日志"}-}\ No newline at end of file+}diff --git a/frontend/src/plugins/ai/logic/useDynamicSuggestions.ts b/frontend/src/plugins/ai/logic/useDynamicSuggestions.tsindex 072a58f3e5..a60c89aef9 100644--- a/frontend/src/plugins/ai/logic/useDynamicSuggestions.ts+++ b/frontend/src/plugins/ai/logic/useDynamicSuggestions.ts@@ -21,13 +21,13 @@ export type SuggestionContext = {};const cache = ref(new Map<string, SuggestionContext>());-const storage = new WebStorageHelper("bb.plugin.open-ai.suggestions");const MAX_STORED_SUGGESTIONS = 10;const keyOf = (metadata: string) => String(hashCode(metadata));export const useDynamicSuggestions = () => {const context = useAIContext();+ const storage = new WebStorageHelper("bb.plugin.open-ai.suggestions");const metadata = computed(() => {const meta = context.databaseMetadata.value;diff --git a/frontend/src/utils/web-storage.ts b/frontend/src/utils/web-storage.tsindex 4e43f54358..8ec13e7489 100644--- a/frontend/src/utils/web-storage.ts+++ b/frontend/src/utils/web-storage.ts@@ -231,7 +231,7 @@ export const useDynamicLocalStorage = <return data;};-export function guessSerializerType<+function guessSerializerType<T extends string | number | boolean | object | null,>(rawInit: T) {return rawInit == nulldiff --git a/frontend/src/views/ReviewCenter/SQLReviewIssueDataTable/SQLReviewIssueDataTable.vue b/frontend/src/views/ReviewCenter/SQLReviewIssueDataTable/SQLReviewIssueDataTable.vueindex 3c5d157e46..f38732ab03 100644--- a/frontend/src/views/ReviewCenter/SQLReviewIssueDataTable/SQLReviewIssueDataTable.vue+++ b/frontend/src/views/ReviewCenter/SQLReviewIssueDataTable/SQLReviewIssueDataTable.vue@@ -22,11 +22,11 @@ import { computed, watch, ref } from "vue";import { useI18n } from "vue-i18n";import { useRouter } from "vue-router";import DatabaseInfo from "@/components/DatabaseInfo.vue";-import { databaseForSpec } from "@/components/IssueV1";import IssueLabelSelector, {getValidIssueLabels,} from "@/components/IssueV1/components/IssueLabelSelector.vue";import IssueStatusIconWithTaskSummary from "@/components/IssueV1/components/IssueStatusIconWithTaskSummary.vue";+import { databaseForSpec } from "@/components/Plan";import { ProjectNameCell } from "@/components/v2/Model/DatabaseV1Table/cells";import { emitWindowEvent } from "@/plugins";import { useSheetV1Store } from "@/store";@@ -180,7 +180,7 @@ const issueRelatedDatabase = (issue: ComposedIssue) => {if (!spec) {return;}- return databaseForSpec(issue, spec);+ return databaseForSpec(issue.projectEntity, spec);};const issueRelatedStatement = (issue: ComposedIssue) => {