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: preview plan before creating issue (#14159)
boojack30fb27ebf8ad
diff --git a/backend/api/v1/plan_service.go b/backend/api/v1/plan_service.goindex f15ec4bff8..6745cec16e 100644--- a/backend/api/v1/plan_service.go+++ b/backend/api/v1/plan_service.go@@ -1117,11 +1117,15 @@ func (s *PlanService) PreviewPlan(ctx context.Context, request *v1pb.PreviewPlancontinue}specs, ooo, abm, err := s.getSpecsForDatabase(ctx, db, release, request.Release, request.AllowOutOfOrder)- response.OutOfOrderFiles = append(response.OutOfOrderFiles, ooo)- response.AppliedButModifiedFiles = append(response.AppliedButModifiedFiles, abm)if err != nil {return nil, status.Errorf(codes.Internal, "failed to get specs for database, err: %v", err)}+ if len(ooo.Files) > 0 {+ response.OutOfOrderFiles = append(response.OutOfOrderFiles, ooo)+ }+ if len(abm.Files) > 0 {+ response.AppliedButModifiedFiles = append(response.AppliedButModifiedFiles, abm)+ }allSpecs = append(allSpecs, specs...)}diff --git a/frontend/src/components/DatabaseAndGroupSelector/DatabaseAndGroupSelector.vue b/frontend/src/components/DatabaseAndGroupSelector/DatabaseAndGroupSelector.vueindex 53b9fce836..1e8468deab 100644--- a/frontend/src/components/DatabaseAndGroupSelector/DatabaseAndGroupSelector.vue+++ b/frontend/src/components/DatabaseAndGroupSelector/DatabaseAndGroupSelector.vue@@ -42,6 +42,7 @@ import type { DatabaseSelectState } from "./types";const props = defineProps<{project: ComposedProject;+ databaseSelectState?: DatabaseSelectState;}>();const emit = defineEmits<{@@ -51,10 +52,12 @@ const emit = defineEmits<{const databaseStore = useDatabaseV1Store();-const state = reactive<DatabaseSelectState>({- changeSource: "DATABASE",- selectedDatabaseNameList: [],-});+const state = reactive<DatabaseSelectState>(+ props.databaseSelectState || {+ changeSource: "DATABASE",+ selectedDatabaseNameList: [],+ }+);useDatabaseV1List(props.project.name);const { dbGroupList } = useDBGroupListByProject(props.project.name);diff --git a/frontend/src/components/Release/ReleaseDetail/NavBar/ApplyToDatabasePanel.vue b/frontend/src/components/Release/ReleaseDetail/NavBar/ApplyToDatabasePanel.vueindex 26ad6b0b58..7bfa562c5a 100644--- a/frontend/src/components/Release/ReleaseDetail/NavBar/ApplyToDatabasePanel.vue+++ b/frontend/src/components/Release/ReleaseDetail/NavBar/ApplyToDatabasePanel.vue@@ -2,20 +2,27 @@<Drawer v-bind="$attrs" @close="emit('close')"><DrawerContent :title="$t('changelist.apply-to-database')"><template #default>- <div- class="w-[calc(100vw-8rem)] lg:w-[60rem] max-w-[calc(100vw-8rem)] overflow-x-auto"- >- <DatabaseAndGroupSelector- :project="project"- @update="handleTargetChange"- />- <div- v-if="state.isGenerating"- v-zindexable="{ enabled: true }"- class="absolute inset-0 flex flex-col items-center justify-center bg-white/50"+ <div class="w-[calc(100vw-8rem)] lg:w-[60rem] max-w-[calc(100vw-8rem)]">+ <StepTab+ :step-list="stepList"+ :current-index="state.currentStep"+ :show-footer="false">- <BBSpin />- </div>+ <template #0>+ <DatabaseAndGroupSelector+ :project="project"+ :database-select-state="state.targetSelectState"+ @update="handleTargetChange"+ />+ </template>+ <template #1>+ <div v-if="state.previewPlanResult" class="space-y-4">+ <PreviewPlanDetail+ :preview-plan-result="state.previewPlanResult"+ />+ </div>+ </template>+ </StepTab></div></template>@@ -24,6 +31,7 @@<div><divv-if="+ state.currentStep === 0 &&state.targetSelectState?.changeSource === 'DATABASE' &&state.targetSelectState?.selectedDatabaseNameList.length > 0"@@ -38,8 +46,15 @@</div><div class="flex items-center justify-end gap-x-3">- <NButton @click.prevent="emit('close')">- {{ $t("common.cancel") }}+ <NButton @click.prevent="handleCancelClick">+ <template v-if="state.currentStep === 1" #icon>+ <Undo2Icon class="w-4 h-auto" />+ </template>+ {{+ state.currentStep === 0+ ? $t("common.cancel")+ : $t("common.back")+ }}</NButton><ErrorTipsButton@@ -60,49 +75,85 @@</template><script lang="ts" setup>+import { Undo2Icon } from "lucide-vue-next";import { NButton } from "naive-ui";-import { zindexable as vZindexable } from "vdirs";import { computed, reactive } from "vue";+import { useI18n } from "vue-i18n";import { useRouter } from "vue-router";-import { BBSpin } from "@/bbkit";import DatabaseAndGroupSelector, {type DatabaseSelectState,} from "@/components/DatabaseAndGroupSelector/";import { Drawer, DrawerContent, ErrorTipsButton } from "@/components/v2";+import { StepTab } from "@/components/v2";+import { planServiceClient } from "@/grpcweb";import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";import { useDatabaseV1Store, useDBGroupStore } from "@/store";import { DatabaseGroup } from "@/types/proto/v1/database_group_service";-import { extractProjectResourceName, generateIssueTitle } from "@/utils";+import {+ PreviewPlanResponse,+ type Plan_Spec,+} from "@/types/proto/v1/plan_service";+import {+ extractProjectResourceName,+ generateIssueTitle,+ issueV1Slug,+} from "@/utils";import { useReleaseDetailContext } from "../context";+import PreviewPlanDetail from "./PreviewPlanDetail.vue";+import { createIssueFromPlan } from "./utils";const emit = defineEmits<{(event: "close"): void;}>();type LocalState = {- isGenerating: boolean;+ currentStep: number;targetSelectState?: DatabaseSelectState;+ previewPlanResult?: PreviewPlanResponse;};+const { t } = useI18n();const router = useRouter();const databaseStore = useDatabaseV1Store();const dbGroupStore = useDBGroupStore();const { release, project } = useReleaseDetailContext();const state = reactive<LocalState>({- isGenerating: false,+ currentStep: 0,+});++const stepList = computed(() => [+ { title: t("database.sync-schema.select-target-databases") },+ { title: t("common.preview") },+]);++const flattenSpecList = computed((): Plan_Spec[] => {+ return (+ state.previewPlanResult?.plan?.steps.flatMap((step) => {+ return step.specs;+ }) || []+ );});const nextButtonErrors = computed(() => {const errors: string[] = [];- if (- !state.targetSelectState ||- (state.targetSelectState.changeSource === "DATABASE" &&- state.targetSelectState.selectedDatabaseNameList.length === 0) ||- (state.targetSelectState.changeSource === "GROUP" &&- !state.targetSelectState.selectedDatabaseGroup)- ) {- errors.push("Please select at least one database");+ if (state.currentStep === 0) {+ if (+ !state.targetSelectState ||+ (state.targetSelectState.changeSource === "DATABASE" &&+ state.targetSelectState.selectedDatabaseNameList.length === 0) ||+ (state.targetSelectState.changeSource === "GROUP" &&+ !state.targetSelectState.selectedDatabaseGroup)+ ) {+ errors.push("Please select at least one database");+ }+ } else if (state.currentStep === 1) {+ if (!state.previewPlanResult) {+ errors.push("Failed to preview plan");+ }+ if (flattenSpecList.value.length === 0) {+ errors.push("No plan to apply");+ }}return errors;});@@ -111,13 +162,36 @@ const handleTargetChange = (databaseSelectState: DatabaseSelectState) => {state.targetSelectState = databaseSelectState;};-const handleClickNext = async () => {- if (!state.targetSelectState) {- return;+const handleCancelClick = () => {+ if (state.currentStep === 0) {+ emit("close");+ } else {+ state.currentStep = 0;+ state.previewPlanResult = undefined;}+};- state.isGenerating = true;- try {+const handleClickNext = async () => {+ if (state.currentStep === 0) {+ if (!state.targetSelectState) {+ return;+ }++ const resp = await planServiceClient.previewPlan({+ project: project.value.name,+ release: release.value.name,+ targets:+ state.targetSelectState.changeSource === "DATABASE"+ ? state.targetSelectState.selectedDatabaseNameList+ : [state.targetSelectState.selectedDatabaseGroup!],+ allowOutOfOrder: true,+ });+ state.previewPlanResult = resp;+ state.currentStep = 1;+ } else if (state.currentStep === 1) {+ if (!state.targetSelectState || !state.previewPlanResult) {+ return;+ }const databaseList = state.targetSelectState.selectedDatabaseNameList.map((name) => databaseStore.getDatabaseByName(name));@@ -126,34 +200,28 @@ const handleClickNext = async () => {state.targetSelectState.selectedDatabaseGroup || ""),});- const changeType = "bb.issue.database.schema.update";- const query: Record<string, any> = {- template: changeType,- name: generateIssueTitle(- changeType,+ const createdPlan = await planServiceClient.createPlan({+ parent: project.value.name,+ plan: state.previewPlanResult.plan,+ });+ const createdIssue = await createIssueFromPlan(project.value.name, {+ ...createdPlan,+ // Override title and description.+ title: generateIssueTitle(+ "bb.issue.database.schema.update",state.targetSelectState.changeSource === "DATABASE"? databaseList.map((db) => db.databaseName): [databaseGroup?.databasePlaceholder]),- release: release.value.name,description: `Apply release "${release.value.title}"`,- };- if (state.targetSelectState.changeSource === "DATABASE") {- query.databaseList = databaseList.map((db) => db.name).join(",");- } else {- query.databaseGroupName = state.targetSelectState.selectedDatabaseGroup;- }-+ });router.push({name: PROJECT_V1_ROUTE_ISSUE_DETAIL,params: {- projectId: extractProjectResourceName(project.value.name),- issueSlug: "create",+ projectId: extractProjectResourceName(release.value.project),+ issueSlug: issueV1Slug(createdIssue),},- query,});- } catch {- state.isGenerating = false;}};</script>diff --git a/frontend/src/components/Release/ReleaseDetail/NavBar/PreviewPlanDetail.vue b/frontend/src/components/Release/ReleaseDetail/NavBar/PreviewPlanDetail.vuenew file mode 100644index 0000000000..e4b087241a--- /dev/null+++ b/frontend/src/components/Release/ReleaseDetail/NavBar/PreviewPlanDetail.vue@@ -0,0 +1,148 @@+<template>+ <div class="w-full flex flex-row flex-wrap gap-2">+ <p class="w-full">+ {{ $t("release.tasks-to-apply") }}+ </p>+ <div+ v-for="spec in flattenSpecList"+ :key="spec.id"+ class="max-w-52 flex flex-row items-center flex-wrap gap-1 border px-2 py-1 rounded-md"+ >+ <div class="w-full truncate space-x-1">+ <NTag round :size="'small'">+ {{ specReleaseVersion(spec) }}+ </NTag>+ <span class="text-sm">+ {{ extractFilename(spec.specReleaseSource?.file || "") }}+ </span>+ </div>+ <DatabaseView+ class="text-sm"+ :database="databaseForPlanSpec(spec)"+ :link="false"+ :show-not-found="true"+ />+ </div>+ <p v-if="flattenSpecList.length === 0" class="text-gray-400 italic">+ {{ $t("release.no-tasks-to-apply.self") }}+ </p>+ </div>+ <div v-if="previewPlanResult.outOfOrderFiles.length > 0">+ <p>+ {{ $t("release.out-of-order-files") }}+ </p>+ <NTable class="mt-2" size="small">+ <thead>+ <tr>+ <th class="w-64">+ {{ $t("common.database") }}+ </th>+ <th>{{ $t("release.files") }}</th>+ </tr>+ </thead>+ <tbody>+ <tr+ v-for="temp in previewPlanResult.outOfOrderFiles"+ :key="temp.database"+ >+ <td>+ <DatabaseView+ class="text-sm"+ :database="databaseStore.getDatabaseByName(temp.database)"+ :link="false"+ :show-not-found="true"+ />+ </td>+ <td>+ <div class="flex flex-row items-center gap-2">+ <span v-for="file in temp.files" :key="file">+ {{ extractFilename(file) }}+ </span>+ </div>+ </td>+ </tr>+ </tbody>+ </NTable>+ </div>+ <div v-if="previewPlanResult.appliedButModifiedFiles.length > 0">+ <p>+ {{ $t("release.applied-but-modifed-files") }}+ </p>+ <NTable class="mt-2" size="small">+ <thead>+ <tr>+ <th class="w-64">+ {{ $t("common.database") }}+ </th>+ <th>Files</th>+ </tr>+ </thead>+ <tbody>+ <tr+ v-for="temp in previewPlanResult.appliedButModifiedFiles"+ :key="temp.database"+ >+ <td>+ <DatabaseView+ class="text-sm"+ :database="databaseStore.getDatabaseByName(temp.database)"+ :link="false"+ :show-not-found="true"+ />+ </td>+ <td>+ <div class="flex flex-row items-center gap-2">+ <span v-for="file in temp.files" :key="file">+ {{ extractFilename(file) }}+ </span>+ </div>+ </td>+ </tr>+ </tbody>+ </NTable>+ </div>+</template>++<script lang="ts" setup>+import { unescape } from "lodash-es";+import { NTag, NTable } from "naive-ui";+import { computed } from "vue";+import DatabaseView from "@/components/v2/Model/DatabaseView.vue";+import { useDatabaseV1Store } from "@/store";+import type { ComposedDatabase } from "@/types";+import type {+ Plan_Spec,+ PreviewPlanResponse,+} from "@/types/proto/v1/plan_service";++const props = defineProps<{+ previewPlanResult: PreviewPlanResponse;+}>();++const databaseStore = useDatabaseV1Store();++const flattenSpecList = computed((): Plan_Spec[] => {+ return (+ props.previewPlanResult.plan?.steps.flatMap((step) => {+ return step.specs;+ }) || []+ );+});++const databaseForPlanSpec = (spec: Plan_Spec): ComposedDatabase => {+ return databaseStore.getDatabaseByName(spec.changeDatabaseConfig!.target);+};++const specReleaseVersion = (spec: Plan_Spec): string => {+ return spec.changeDatabaseConfig!.schemaVersion;+};++const extractFilename = (file: string): string => {+ const pattern = /(?:^|\/)files\/(.+)(?:$|\/)/;+ const matches = file.match(pattern);+ if (!matches) {+ return "";+ }+ return unescape(matches[1]);+};+</script>diff --git a/frontend/src/components/Release/ReleaseDetail/NavBar/utils.ts b/frontend/src/components/Release/ReleaseDetail/NavBar/utils.tsnew file mode 100644index 0000000000..bd59e11255--- /dev/null+++ b/frontend/src/components/Release/ReleaseDetail/NavBar/utils.ts@@ -0,0 +1,34 @@+import { issueServiceClient, rolloutServiceClient } from "@/grpcweb";+import { useCurrentUserV1 } from "@/store";+import { emptyIssue, type ComposedIssue } from "@/types";+import { Issue, Issue_Type, IssueStatus } from "@/types/proto/v1/issue_service";+import type { Plan } from "@/types/proto/v1/plan_service";++export const createIssueFromPlan = async (project: string, plan: Plan) => {+ const me = useCurrentUserV1();+ const createdIssue = await issueServiceClient.createIssue({+ parent: project,+ issue: Issue.fromPartial({+ plan: plan.name,+ creator: `users/${me.value.email}`,+ title: plan.title,+ description: plan.description,+ status: IssueStatus.OPEN,+ type: Issue_Type.DATABASE_CHANGE,+ }),+ });+ const createdRollout = await rolloutServiceClient.createRollout({+ parent: project,+ rollout: {+ plan: plan.name,+ },+ });+ const composedIssue: ComposedIssue = {+ ...emptyIssue(),+ ...createdIssue,+ planEntity: plan,+ rollout: createdRollout.name,+ rolloutEntity: createdRollout,+ };+ return composedIssue;+};diff --git a/frontend/src/components/Release/ReleaseDetail/ReleaseFileTable/ReleaseFileDetailPanel.vue b/frontend/src/components/Release/ReleaseDetail/ReleaseFileTable/ReleaseFileDetailPanel.vueindex 460532fba0..40b351ce25 100644--- a/frontend/src/components/Release/ReleaseDetail/ReleaseFileTable/ReleaseFileDetailPanel.vue+++ b/frontend/src/components/Release/ReleaseDetail/ReleaseFileTable/ReleaseFileDetailPanel.vue@@ -1,14 +1,20 @@<template>- <div class="w-full border-b pb-4 mb-4">- <h1 class="text-xl font-bold text-main truncate">- {{ releaseFile.name }}- </h1>- <p class="mt-2 text-control text-base space-x-4">- <span>{{ $t("common.version") }}: {{ releaseFile.version }}</span>+ <div class="w-full">+ <div class="flex flex-row items-center gap-2">+ <NTag round>+ {{ releaseFile.version }}+ </NTag>+ <h2 class="text-xl font-bold text-main truncate">+ {{ releaseFile.name }}+ </h2>+ </div>+ <p class="mt-3 text-control text-base space-x-4"><span>{{ "Hash" }}: {{ releaseFile.sheetSha256.slice(0, 8) }}</span></p></div>+ <NDivider />+<div class="flex flex-col gap-y-2"><aid="statement"@@ -35,6 +41,7 @@<script lang="ts" setup>import { ClipboardIcon } from "lucide-vue-next";+import { NDivider, NTag } from "naive-ui";import { MonacoEditor } from "@/components/MonacoEditor";import { pushNotification } from "@/store";import { type ComposedRelease } from "@/types";diff --git a/frontend/src/components/v2/Form/StepTab.vue b/frontend/src/components/v2/Form/StepTab.vueindex 8ea6f727de..7b4997b856 100644--- a/frontend/src/components/v2/Form/StepTab.vue+++ b/frontend/src/components/v2/Form/StepTab.vue@@ -32,6 +32,7 @@</div><div+ v-if="showFooter"class="pt-4 border-t border-block-border flex items-center space-x-2 justify-between":class="[sticky && 'pb-4 bg-white sticky bottom-0 z-10', footerClass]">@@ -85,6 +86,7 @@ withDefaults(currentIndex: number;showCancel?: boolean;allowNext?: boolean;+ showFooter?: boolean;sticky?: boolean;finishTitle?: string;paneClass?: VueClass;@@ -98,6 +100,7 @@ withDefaults({showCancel: true,allowNext: true,+ showFooter: true,sticky: false,finishTitle: "bbkit.common.finish",paneClass: undefined,diff --git a/frontend/src/components/v2/Model/DatabaseView.vue b/frontend/src/components/v2/Model/DatabaseView.vueindex 2e9e360a69..74d8418f05 100644--- a/frontend/src/components/v2/Model/DatabaseView.vue+++ b/frontend/src/components/v2/Model/DatabaseView.vue@@ -1,21 +1,32 @@<template>- <div v-if="database" class="flex flex-row justify-start items-center">+ <div class="flex flex-row justify-start items-center gap-x-1" v-bind="$attrs"><FeatureBadgefeature="bb.feature.database-grouping"custom-class="mr-2":instance="database.instanceResource"/><InstanceV1EngineIcon :instance="database.instanceResource" />- <span class="text-sm ml-0.5 text-gray-500">{{- database.databaseName- }}</span>+ <EnvironmentV1Name+ text-class="text-control-light"+ :environment="database.effectiveEnvironmentEntity"+ :plain="true"+ :show-icon="false"+ :link="false"+ />+ <DatabaseV1Name+ :database="database"+ :plain="true"+ :show-icon="false"+ :link="false"+ /></div></template><script lang="ts" setup>+import { FeatureBadge } from "@/components/FeatureGuard";+import { DatabaseV1Name, EnvironmentV1Name } from "@/components/v2";import type { ComposedDatabase } from "@/types";import { InstanceV1EngineIcon } from "./Instance";-import { FeatureBadge } from "@/components/FeatureGuard";defineProps<{database: ComposedDatabase;diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex b3e9a5b8e4..e0aa29c3ce 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -3724,7 +3724,13 @@"release": {"self": "Release","releases": "Releases",- "files": "Files"+ "files": "Files",+ "tasks-to-apply": "Tasks to apply",+ "out-of-order-files": "Out of order files",+ "applied-but-modifed-files": "Applied but modified files",+ "no-tasks-to-apply": {+ "self": "No tasks to apply"+ }},"export-data": {"export-rows": "Export rows",diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex 2257dbf9ff..991431389f 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -3724,7 +3724,13 @@"release": {"self": "Liberar","releases": "Lanzamientos",- "files": "Archivos"+ "files": "Archivos",+ "tasks-to-apply": "Tareas a aplicar",+ "out-of-order-files": "Archivos fuera de servicio",+ "applied-but-modifed-files": "Archivos aplicados pero modificados",+ "no-tasks-to-apply": {+ "self": "No hay tareas para aplicar"+ }},"export-data": {"export-rows": "Exportar filas",diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex a476e0ae7d..ddaf45efff 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -3724,7 +3724,13 @@"release": {"self": "リリース","releases": "リリース",- "files": "ファイル"+ "files": "ファイル",+ "tasks-to-apply": "適用するタスク",+ "out-of-order-files": "順序が間違っているファイル",+ "applied-but-modifed-files": "適用済みだが変更されたファイル",+ "no-tasks-to-apply": {+ "self": "適用するタスクはありません"+ }},"export-data": {"export-rows": "エクスポート行数",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 05a65219e5..1705f4ecc6 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -3724,7 +3724,13 @@"release": {"self": "发布","releases": "发布",- "files": "文件"+ "files": "文件",+ "tasks-to-apply": "待应用的任务",+ "out-of-order-files": "无序文件",+ "applied-but-modifed-files": "已应用但已修改的文件",+ "no-tasks-to-apply": {+ "self": "没有可应用的任务"+ }},"export-data": {"export-rows": "导出行数",@@ -3811,4 +3817,4 @@"setup": {"self": "设置"}-}\ No newline at end of file+}