Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: allow editing migration type for draft plan specs (#17739)
boojackc53ee1f7fc92
diff --git a/frontend/src/components/Plan/components/SpecDetailView/EditMigrationTypeModal.vue b/frontend/src/components/Plan/components/SpecDetailView/EditMigrationTypeModal.vuenew file mode 100644index 0000000000..8128b407cd--- /dev/null+++ b/frontend/src/components/Plan/components/SpecDetailView/EditMigrationTypeModal.vue@@ -0,0 +1,86 @@+<template>+ <NModal+ v-model:show="showModal"+ :title="$t('plan.change-type')"+ preset="dialog"+ :positive-text="$t('common.save')"+ :negative-text="$t('common.cancel')"+ @positive-click="handleSave"+ @negative-click="handleClose"+ >+ <NRadioGroup v-model:value="selectedType" class="space-y-4">+ <NRadio :value="MigrationType.DDL" class="w-full">+ <div class="flex items-start space-x-2 w-full ml-2">+ <FileDiffIcon class="w-6 h-6 flex-shrink-0" :stroke-width="1.5" />+ <div class="flex-1">+ <div class="flex items-center space-x-2">+ <span class="text-base text-gray-900">+ <span>{{ $t("plan.schema-migration") }}</span>+ </span>+ </div>+ <p class="text-sm text-gray-600 mt-1">+ {{ $t("plan.schema-migration-description") }}+ </p>+ </div>+ </div>+ </NRadio>+ <NRadio :value="MigrationType.DML" class="w-full">+ <div class="flex items-start space-x-2 w-full ml-2">+ <EditIcon class="w-6 h-6 flex-shrink-0" :stroke-width="1.5" />+ <div class="flex-1">+ <div class="flex items-center space-x-2">+ <span class="text-base text-gray-900">+ <span>{{ $t("plan.data-change") }}</span>+ </span>+ </div>+ <p class="text-sm text-gray-600 mt-1">+ {{ $t("plan.data-change-description") }}+ </p>+ </div>+ </div>+ </NRadio>+ </NRadioGroup>+ </NModal>+</template>++<script setup lang="ts">+import { FileDiffIcon, EditIcon } from "lucide-vue-next";+import { NModal, NRadioGroup, NRadio } from "naive-ui";+import { ref, watch } from "vue";+import { MigrationType } from "@/types/proto-es/v1/common_pb";++const props = defineProps<{+ show: boolean;+ migrationType: MigrationType;+}>();++const emit = defineEmits<{+ (event: "update:show", value: boolean): void;+ (event: "save", type: MigrationType): void;+}>();++const showModal = ref(props.show);+const selectedType = ref(props.migrationType);++watch(+ () => props.show,+ (newVal) => {+ showModal.value = newVal;+ if (newVal) {+ selectedType.value = props.migrationType;+ }+ }+);++watch(showModal, (newVal) => {+ emit("update:show", newVal);+});++const handleSave = () => {+ emit("save", selectedType.value);+};++const handleClose = () => {+ emit("update:show", false);+};+</script>diff --git a/frontend/src/components/Plan/components/SpecDetailView/SpecListSection.vue b/frontend/src/components/Plan/components/SpecDetailView/SpecListSection.vueindex aea810d489..6ada7e639c 100644--- a/frontend/src/components/Plan/components/SpecDetailView/SpecListSection.vue+++ b/frontend/src/components/Plan/components/SpecDetailView/SpecListSection.vue@@ -27,17 +27,23 @@</template>{{ $t("plan.navigator.statement-empty") }}</NTooltip>- <NButton- v-if="canModifySpecs && plan.specs.length > 1"- text- size="tiny"- :title="$t('common.delete')"- @click.stop="handleDeleteSpec(spec)"+ <NDropdown+ v-if="+ canModifySpecs &&+ (canEditMigrationType(spec) || plan.specs.length > 1)+ "+ :options="getDropdownOptions(spec)"+ trigger="click"+ placement="bottom-end"+ :size="'small'"+ @select="(key) => handleDropdownSelect(key, spec)">- <template #icon>- <XIcon :size="14" class="text-control-light" />- </template>- </NButton>+ <NButton @click.stop text size="tiny">+ <template #icon>+ <MoreVerticalIcon :size="14" class="text-control-light" />+ </template>+ </NButton>+ </NDropdown></div></NTab>@@ -60,13 +66,26 @@v-model:show="showAddSpecDrawer"@created="handleSpecCreated"/>++ <EditMigrationTypeModal+ v-if="editingSpec"+ :show="showEditModal"+ :migration-type="+ editingSpec.config.case === 'changeDatabaseConfig'+ ? editingSpec.config.value.migrationType+ : MigrationType.DDL+ "+ @update:show="showEditModal = $event"+ @save="handleSaveMigrationType"+ /></template><script setup lang="ts">import { create } from "@bufbuild/protobuf";-import { XIcon } from "lucide-vue-next";-import { NTabs, NTab, NButton, useDialog, NTooltip } from "naive-ui";-import { ref, computed, nextTick } from "vue";+import { PencilIcon, MoreVerticalIcon, TrashIcon } from "lucide-vue-next";+import { NTabs, NTab, NButton, useDialog, NTooltip, NDropdown } from "naive-ui";+import type { DropdownOption } from "naive-ui";+import { ref, computed, nextTick, h } from "vue";import { useI18n } from "vue-i18n";import { useRouter } from "vue-router";import { planServiceClientConnect } from "@/grpcweb";@@ -76,6 +95,7 @@ import {useCurrentProjectV1,useSheetV1Store,} from "@/store";+import { MigrationType } from "@/types/proto-es/v1/common_pb";import type { Plan_Spec } from "@/types/proto-es/v1/plan_service_pb";import { UpdatePlanRequestSchema } from "@/types/proto-es/v1/plan_service_pb";import { extractSheetUID } from "@/utils";@@ -85,6 +105,7 @@ import { useEditorState } from "../../logic/useEditorState";import { getSpecTitle } from "../../logic/utils";import AddSpecDrawer from "../AddSpecDrawer.vue";import { useSpecsValidation } from "../common";+import EditMigrationTypeModal from "./EditMigrationTypeModal.vue";import { useSelectedSpec } from "./context";const router = useRouter();@@ -98,6 +119,8 @@ const { isSpecEmpty } = useSpecsValidation(computed(() => plan.value.specs));const { setEditingState } = useEditorState();const showAddSpecDrawer = ref(false);+const editingSpec = ref<Plan_Spec | null>(null);+const showEditModal = ref(false);// Allow adding/removing specs when:// 1. Plan is being created (isCreating = true), OR@@ -194,6 +217,112 @@ const gotoSpec = (specId: string, enableEditing = false) => {});};+const canEditMigrationType = (spec: Plan_Spec) => {+ return spec.config.case === "changeDatabaseConfig";+};++const getDropdownOptions = (spec: Plan_Spec): DropdownOption[] => {+ const options: DropdownOption[] = [];+ if (canEditMigrationType(spec)) {+ options.push({+ key: "edit",+ label: t("common.edit"),+ icon: () => h(PencilIcon, { size: 16 }),+ });+ }+ if (plan.value.specs.length > 1) {+ options.push({+ key: "delete",+ label: t("common.delete"),+ icon: () => h(TrashIcon, { size: 16 }),+ });+ }+ return options;+};++const handleDropdownSelect = (key: string, spec: Plan_Spec) => {+ if (key === "edit") {+ handleOpenEditModal(spec);+ } else if (key === "delete") {+ handleDeleteSpec(spec);+ }+};++const handleOpenEditModal = (spec: Plan_Spec) => {+ if (spec.config.case === "changeDatabaseConfig") {+ editingSpec.value = spec;+ showEditModal.value = true;+ }+};++const handleSaveMigrationType = async (newType: MigrationType) => {+ const spec = editingSpec.value;+ if (!spec || spec.config.case !== "changeDatabaseConfig") {+ showEditModal.value = false;+ editingSpec.value = null;+ return;+ }++ const oldType = spec.config.value.migrationType;++ if (oldType === newType) {+ showEditModal.value = false;+ editingSpec.value = null;+ return;+ }++ // Find the spec in the plan's specs array+ const specIndex = plan.value.specs.findIndex((s) => s.id === spec.id);+ if (specIndex < 0) {+ showEditModal.value = false;+ editingSpec.value = null;+ return;+ }++ // Update the spec in the plan+ const targetSpec = plan.value.specs[specIndex];+ if (targetSpec.config.case !== "changeDatabaseConfig") {+ showEditModal.value = false;+ editingSpec.value = null;+ return;+ }++ // Update local state+ targetSpec.config.value.migrationType = newType;++ // If the plan is not being created (already exists), call UpdatePlan API+ if (!isCreating.value) {+ try {+ const request = create(UpdatePlanRequestSchema, {+ plan: plan.value,+ updateMask: { paths: ["specs"] },+ });+ const response = await planServiceClientConnect.updatePlan(request);+ Object.assign(plan.value, response);+ pushNotification({+ module: "bytebase",+ style: "SUCCESS",+ title: t("common.updated"),+ });+ } catch (error) {+ // If the API call fails, restore the old migration type+ targetSpec.config.value.migrationType = oldType;+ pushNotification({+ module: "bytebase",+ style: "CRITICAL",+ title: t("common.error"),+ description: `Failed to update migration type: ${error}`,+ });+ showEditModal.value = false;+ editingSpec.value = null;+ return;+ }+ }++ showEditModal.value = false;+ editingSpec.value = null;+};+const handleDeleteSpec = (spec: Plan_Spec) => {dialog.warning({title: t("plan.spec.delete-change.title"),