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: unify database edit drawer with plan creation flow (#18028)
Danny Xub8fc9856b8a6
diff --git a/frontend/src/components/Plan/components/AddSpecDrawer.vue b/frontend/src/components/Plan/components/AddSpecDrawer.vueindex 46f35b5331..d5fa3d21d1 100644--- a/frontend/src/components/Plan/components/AddSpecDrawer.vue+++ b/frontend/src/components/Plan/components/AddSpecDrawer.vue@@ -11,8 +11,8 @@class="max-w-[100vw]"><div class="flex flex-col gap-y-4">- <!-- Steps indicator -->- <NSteps :current="currentStep">+ <!-- Steps indicator (hide when databases are pre-selected) -->+ <NSteps v-if="!hasPreSelectedDatabases" :current="currentStep"><NStep :title="changeTypeTitle" /><NStep :title="$t('plan.select-targets')" /></NSteps>@@ -135,20 +135,32 @@<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 {+ NButton,+ NRadio,+ NRadioGroup,+ NSteps,+ NStep,+ useDialog,+} 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 { useRouter } from "vue-router";+import type { LocationQueryRaw } from "vue-router";import DatabaseAndGroupSelector from "@/components/DatabaseAndGroupSelector";import type { DatabaseSelectState } from "@/components/DatabaseAndGroupSelector";import { getLocalSheetByName, getNextLocalSheetUID } from "@/components/Plan";import { Drawer, DrawerContent } from "@/components/v2";+import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";import {useCurrentProjectV1,batchGetOrFetchDatabases,pushNotification,+ useDatabaseV1Store,} from "@/store";+import type { ComposedDatabase } from "@/types";import {DatabaseChangeType,MigrationType,@@ -158,9 +170,13 @@ import {Plan_SpecSchema,type Plan_Spec,} from "@/types/proto-es/v1/plan_service_pb";+import { extractProjectResourceName, generateIssueTitle } from "@/utils";-defineProps<{+const props = defineProps<{title?: string;+ preSelectedDatabases?: ComposedDatabase[];+ projectName?: string;+ useLegacyIssueFlow?: boolean;}>();const emit = defineEmits<{@@ -174,6 +190,9 @@ enum Step {const { project } = useCurrentProjectV1();const { t } = useI18n();+const router = useRouter();+const dialog = useDialog();+const databaseStore = useDatabaseV1Store();const show = defineModel<boolean>("show", { default: false });const selectedMigrationType: Ref<MigrationType> = ref(MigrationType.DDL);@@ -185,7 +204,14 @@ const databaseSelectState = reactive<DatabaseSelectState>({selectedDatabaseNameList: [],});+const hasPreSelectedDatabases = computed(() => {+ return (props.preSelectedDatabases?.length ?? 0) > 0;+});+const hasSelection = computed(() => {+ if (hasPreSelectedDatabases.value) {+ return true;+ }if (databaseSelectState.changeSource === "DATABASE") {return databaseSelectState.selectedDatabaseNameList.length > 0;} else {@@ -208,6 +234,9 @@ const canProceedToNextStep = computed(() => {});const isLastStep = computed(() => {+ if (hasPreSelectedDatabases.value) {+ return currentStep.value === Step.SELECT_CHANGE_TYPE;+ }return currentStep.value === Step.SELECT_TARGETS;});@@ -242,6 +271,25 @@ watch(show, (newVal) => {}});+const showDatabaseDriftedWarningDialog = () => {+ return new Promise((resolve) => {+ dialog.create({+ type: "warning",+ positiveText: t("common.confirm"),+ negativeText: t("common.cancel"),+ title: t("issue.schema-drift-detected.self"),+ content: t("issue.schema-drift-detected.description"),+ autoFocus: false,+ onNegativeClick: () => {+ resolve(false);+ },+ onPositiveClick: () => {+ resolve(true);+ },+ });+ });+};+const handleUpdateSelection = async (newState: DatabaseSelectState) => {Object.assign(databaseSelectState, newState);@@ -280,12 +328,64 @@ const handleConfirm = async () => {try {// Get targetsconst targets: string[] = [];- if (databaseSelectState.changeSource === "DATABASE") {+ if (hasPreSelectedDatabases.value) {+ targets.push(...(props.preSelectedDatabases?.map((db) => db.name) ?? []));+ } else if (databaseSelectState.changeSource === "DATABASE") {targets.push(...databaseSelectState.selectedDatabaseNameList);} else if (databaseSelectState.selectedDatabaseGroup) {targets.push(databaseSelectState.selectedDatabaseGroup);}+ // Check for database drift if using legacy issue flow+ if (props.useLegacyIssueFlow && hasPreSelectedDatabases.value) {+ if (props.preSelectedDatabases?.some((d) => d.drifted)) {+ const confirmed = await showDatabaseDriftedWarningDialog();+ if (!confirmed) {+ isCreating.value = false;+ return;+ }+ }+ }++ // If using legacy issue flow (from database dashboard), navigate to issue creation+ if (props.useLegacyIssueFlow) {+ const type =+ selectedMigrationType.value === MigrationType.DDL+ ? "bb.issue.database.schema.update"+ : "bb.issue.database.data.update";++ const databaseNames = hasPreSelectedDatabases.value+ ? (props.preSelectedDatabases?.map((db) => db.databaseName) ?? [])+ : await Promise.all(+ targets.map(async (target) => {+ const db = await databaseStore.getOrFetchDatabaseByName(target);+ return db.databaseName;+ })+ );++ const query: LocationQueryRaw = {+ template: type,+ name: generateIssueTitle(type, databaseNames),+ databaseList: targets.join(","),+ };++ router.push({+ name: PROJECT_V1_ROUTE_ISSUE_DETAIL,+ params: {+ projectId: extractProjectResourceName(+ props.projectName ?? project.value.name+ ),+ issueSlug: "create",+ },+ query,+ });++ show.value = false;+ isCreating.value = false;+ return;+ }++ // Otherwise, create spec for plan flowconst sheetUID = getNextLocalSheetUID();const localSheet = getLocalSheetByName(`${project.value.name}/sheets/${sheetUID}`diff --git a/frontend/src/components/Plan/index.ts b/frontend/src/components/Plan/index.tsindex f1104893b6..7f78438747 100644--- a/frontend/src/components/Plan/index.ts+++ b/frontend/src/components/Plan/index.ts@@ -1 +1,2 @@export * from "./logic";+export { default as AddSpecDrawer } from "./components/AddSpecDrawer.vue";diff --git a/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseOperations.vue b/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseOperations.vueindex f63d1158ae..85db092162 100644--- a/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseOperations.vue+++ b/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseOperations.vue@@ -90,6 +90,14 @@"@cancel="state.showUnassignAlert = false"/>++ <AddSpecDrawer+ v-model:show="state.showChangeDatabaseDrawer"+ :title="$t('database.edit-database')"+ :pre-selected-databases="databases"+ :project-name="selectedProjectName"+ :use-legacy-issue-flow="true"+ /></template><script lang="ts" setup>@@ -101,7 +109,6 @@ import {ChevronsDownIcon,DownloadIcon,PencilIcon,- PenSquareIcon,RefreshCcwIcon,SquareStackIcon,TagIcon,@@ -116,6 +123,7 @@ import type { LocationQueryRaw } from "vue-router";import { BBAlert } from "@/bbkit";import EditEnvironmentDrawer from "@/components/EditEnvironmentDrawer.vue";import LabelEditorDrawer from "@/components/LabelEditorDrawer.vue";+import { AddSpecDrawer } from "@/components/Plan";import { TransferDatabaseForm } from "@/components/TransferDatabaseForm";import TransferOutDatabaseForm from "@/components/TransferOutDatabaseForm";import { Drawer } from "@/components/v2";@@ -143,7 +151,6 @@ import {hasPermissionToCreateChangeDatabaseIssue,hasPermissionToCreateDataExportIssue,hasProjectPermissionV2,- instanceV1HasAlterSchema,} from "@/utils";interface DatabaseAction {@@ -159,6 +166,7 @@ interface LocalState {showUnassignAlert: boolean;showLabelEditorDrawer: boolean;showEditEnvironmentDrawer: boolean;+ showChangeDatabaseDrawer: boolean;transferOutDatabaseType?: "TRANSFER-IN" | "TRANSFER-OUT";}@@ -175,6 +183,7 @@ const state = reactive<LocalState>({showUnassignAlert: false,showLabelEditorDrawer: false,showEditEnvironmentDrawer: false,+ showChangeDatabaseDrawer: false,transferOutDatabaseType: undefined,});@@ -222,24 +231,6 @@ const selectedProjectName = computed(() => {return [...selectedProjectNames.value][0];});-const databaseSupportAlterSchema = computed(() => {- return props.databases.every((db) => {- return instanceV1HasAlterSchema(db.instanceResource);- });-});--const allowEditSchema = computed(() => {- return props.databases.every((db) => {- return hasPermissionToCreateChangeDatabaseIssue(db);- });-});--const allowChangeData = computed(() => {- return props.databases.every((db) =>- hasPermissionToCreateChangeDatabaseIssue(db)- );-});-const allowTransferOutProject = computed(() => {return props.databases.every((db) =>hasProjectPermissionV2(db.projectEntity, "bb.projects.update")@@ -277,8 +268,7 @@ const selectedDatabaseNameList = computed(() => {const operations = computed(() => {return [- "EDIT-SCHEMA",- "CHANGE-DATA",+ "CHANGE-DATABASE","EXPORT-DATA","SYNC-SCHEMA","EDIT-LABELS",@@ -427,10 +417,36 @@ const isInDefaultProject = computed(() => props.projectName === DEFAULT_PROJECT_NAME);+const allowChangeDatabase = computed(() => {+ return props.databases.every((db) =>+ hasPermissionToCreateChangeDatabaseIssue(db)+ );+});+const actions = computed((): DatabaseAction[] => {const resp: DatabaseAction[] = [];for (const operation of operations.value) {switch (operation) {+ case "CHANGE-DATABASE":+ resp.push({+ icon: h(PencilIcon),+ text: t("database.edit-database"),+ disabled:+ !allowChangeDatabase.value ||+ !selectedProjectName.value ||+ props.databases.length < 1 ||+ selectedProjectNames.value.has(DEFAULT_PROJECT_NAME),+ click: () => (state.showChangeDatabaseDrawer = true),+ tooltip: (action) => {+ if (!allowChangeDatabase.value) {+ return t("database.batch-action-permission-denied", {+ action,+ });+ }+ return getDisabledTooltip(action);+ },+ });+ break;case "EXPORT-DATA":resp.push({icon: h(DownloadIcon),@@ -546,50 +562,6 @@ const actions = computed((): DatabaseAction[] => {});}break;- case "CHANGE-DATA":- resp.push({- icon: h(PencilIcon),- text: t("database.change-data"),- disabled:- !allowChangeData.value ||- !selectedProjectName.value ||- props.databases.length < 1 ||- selectedProjectNames.value.has(DEFAULT_PROJECT_NAME),- click: () => generateMultiDb("bb.issue.database.data.update"),- tooltip: (action) => {- if (!allowChangeData.value) {- return t("database.batch-action-permission-denied", {- action,- });- }- return getDisabledTooltip(action);- },- });- break;- case "EDIT-SCHEMA":- resp.push({- icon: h(PenSquareIcon),- text: t("database.edit-schema"),- disabled:- !databaseSupportAlterSchema.value ||- !allowEditSchema.value ||- !selectedProjectName.value ||- props.databases.length < 1 ||- selectedProjectNames.value.has(DEFAULT_PROJECT_NAME),- click: () => generateMultiDb("bb.issue.database.schema.update"),- tooltip: (action) => {- if (!databaseSupportAlterSchema.value) {- return t("database.batch-action-not-support-alter-schema");- }- if (!allowEditSchema.value) {- return t("database.batch-action-permission-denied", {- action,- });- }- return getDisabledTooltip(action);- },- });- break;}}diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex ca04de7693..6f584d2405 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -1612,6 +1612,7 @@"unassign": "Unassign","unassign-alert-title": "Unassign databases","unassign-alert-description": "The selected databases will be removed from the project",+ "edit-database": "Edit Database","edit-schema": "Edit Schema","edit-labels": "Edit Labels","edit-environment": "Edit Environment",@@ -1619,7 +1620,6 @@"mixed-label-values-warning": "Some of the selected resources have mixed values for the same key","change-data": "Change Data","table-detail": "Table detail",- "batch-action-not-support-alter-schema": "Some databases don't support altering schema","batch-action-permission-denied": "Don't have permission to {action} for databases","batch-action-disabled": "Can not {action} for the databases from different projects","batch-action-disabled-for-unassigned": "Can not {action} for unassigned database",diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex bb092d0275..4cf7f1ce94 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -1612,6 +1612,7 @@"unassign": "Desasignar","unassign-alert-title": "Desasignar bases de datos","unassign-alert-description": "Las bases de datos seleccionadas serán eliminadas del proyecto",+ "edit-database": "Editar base de datos","edit-schema": "Modificar esquema","edit-labels": "Editar etiquetas","edit-environment": "Editar entorno",@@ -1619,7 +1620,6 @@"mixed-label-values-warning": "Algunos de los recursos seleccionados tienen valores mixtos para la misma clave","change-data": "Cambiar datos","table-detail": "Detalle de la tabla",- "batch-action-not-support-alter-schema": "Algunas bases de datos no admiten la modificación del esquema","batch-action-permission-denied": "No tengo permiso para {action} para bases de datos","batch-action-disabled": "No se puede {action} para las bases de datos de diferentes proyectos","batch-action-disabled-for-unassigned": "No se puede {action} para una base de datos no asignada",diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex 966bb2a157..2a0e2bcd73 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -1612,6 +1612,7 @@"unassign": "割り当てを解除する","unassign-alert-title": "データベースの割り当てを解除する","unassign-alert-description": "選択したデータベースがプロジェクトから削除されます",+ "edit-database": "データベースの編集","edit-schema": "スキーマの変更","edit-labels": "タグを編集する","edit-environment": "環境の編集",@@ -1619,7 +1620,6 @@"mixed-label-values-warning": "一部のタグには異なる値があり、タグの編集はバッチで適用されます","change-data": "データ変更","table-detail": "テーブルの詳細",- "batch-action-not-support-alter-schema": "一部のデータベースはテーブル構造の変更をサポートしていません","batch-action-permission-denied": "データベース {action} に対する権限がありません","batch-action-disabled": "異なるプロジェクトのデータベース {action} を比較できません","batch-action-disabled-for-unassigned": "未割り当てのデータベース {action} にアクセスできません",diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.jsonindex 1e327ec342..cffa2df5f6 100644--- a/frontend/src/locales/vi-VN.json+++ b/frontend/src/locales/vi-VN.json@@ -1612,6 +1612,7 @@"unassign": "Hủy gán","unassign-alert-title": "Hủy gán cơ sở dữ liệu","unassign-alert-description": "Các cơ sở dữ liệu đã chọn sẽ bị xóa khỏi dự án",+ "edit-database": "Chỉnh sửa cơ sở dữ liệu","edit-schema": "Chỉnh sửa lược đồ","edit-labels": "Chỉnh sửa nhãn","edit-environment": "Chỉnh sửa Môi trường",@@ -1619,7 +1620,6 @@"mixed-label-values-warning": "Một số tài nguyên đã chọn có các giá trị hỗn hợp cho cùng một khóa","change-data": "Thay đổi dữ liệu","table-detail": "Chi tiết bảng",- "batch-action-not-support-alter-schema": "Một số cơ sở dữ liệu không hỗ trợ thay đổi lược đồ","batch-action-permission-denied": "Không có quyền {action} đối với cơ sở dữ liệu","batch-action-disabled": "Không thể {action} đối với các cơ sở dữ liệu từ các dự án khác nhau","batch-action-disabled-for-unassigned": "Không thể {action} đối với cơ sở dữ liệu chưa được gán",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 5a993690ec..f2ac4b5ebd 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -1612,6 +1612,7 @@"unassign": "取消分配","unassign-alert-title": "取消分配数据库","unassign-alert-description": "选定的数据库将从项目中移除",+ "edit-database": "编辑数据库","edit-schema": "变更 Schema","edit-labels": "编辑标签","edit-environment": "编辑环境",@@ -1619,7 +1620,6 @@"mixed-label-values-warning": "部分标签拥有不同的值,编辑标签将会批量应用","change-data": "变更数据","table-detail": "表详情",- "batch-action-not-support-alter-schema": "一些数据库不支持修改表结构","batch-action-permission-denied": "没有权限对数据库{action}","batch-action-disabled": "无法对来自不同项目的数据库{action}","batch-action-disabled-for-unassigned": "无法对未分配的数据库{action}",