Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore(frontend): use `targets` instead of `target` (part I) (#16302)
boojack182fdc5c0147
diff --git a/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vue b/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vueindex 631f837c91..39cf34a9b7 100644--- a/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vue+++ b/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vue@@ -53,13 +53,16 @@ import { useRouter } from "vue-router";import { getValidIssueLabels } from "@/components/IssueV1/components/IssueLabelSelector.vue";import { ErrorList } from "@/components/IssueV1/components/common";import {- databaseEngineForSpec,isValidStage,specForTask,useIssueContext,} from "@/components/IssueV1/logic";import formatSQL from "@/components/MonacoEditor/sqlFormatter";-import { getLocalSheetByName, isValidSpec } from "@/components/Plan";+import {+ databaseEngineForSpec,+ getLocalSheetByName,+ isValidSpec,+} from "@/components/Plan";import { getSpecChangeType } from "@/components/Plan/components/SQLCheckSection/common";import { usePlanSQLCheckContext } from "@/components/Plan/components/SQLCheckSection/context";import { databaseForTask } from "@/components/Rollout/RolloutDetail";@@ -73,12 +76,9 @@ import {} from "@/grpcweb";import { emitWindowEvent } from "@/plugins";import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";-import {- useDatabaseV1Store,- useSheetV1Store,- useCurrentProjectV1,-} from "@/store";+import { useSheetV1Store, useCurrentProjectV1 } from "@/store";import { dialectOfEngineV1, languageOfEngineV1 } from "@/types";+import type { Engine } from "@/types/proto/v1/common";import { Issue, Issue_Type } from "@/types/proto/v1/issue_service";import type { Plan_ExportDataConfig } from "@/types/proto/v1/plan_service";import { type Plan_ChangeDatabaseConfig } from "@/types/proto/v1/plan_service";@@ -212,8 +212,7 @@ const createSheets = async () => {const engine = await databaseEngineForSpec(spec);sheet.engine = engine;pendingCreateSheetMap.set(sheet.name, sheet);-- await maybeFormatSQL(sheet, config.target);+ await maybeFormatSQL(sheet, engine);}}const pendingCreateSheetList = Array.from(pendingCreateSheetMap.values());@@ -245,19 +244,15 @@ const createPlan = async () => {return createdPlan;};-const maybeFormatSQL = async (sheet: Sheet, target: string) => {+const maybeFormatSQL = async (sheet: Sheet, engine: Engine) => {if (!formatOnSave.value) {return;}- const db = await useDatabaseV1Store().getOrFetchDatabaseByName(target);- if (!db) {- return;- }- const language = languageOfEngineV1(db.instanceResource.engine);+ const language = languageOfEngineV1(engine);if (language !== "sql") {return;}- const dialect = dialectOfEngineV1(db.instanceResource.engine);+ const dialect = dialectOfEngineV1(engine);const statement = getSheetStatement(sheet);if (statement.length > MAX_FORMATTABLE_STATEMENT_SIZE) {diff --git a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vueindex 5bc5366368..3f95bbcd60 100644--- a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue+++ b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue@@ -19,9 +19,7 @@</div></div>- <div- class="flex items-center justify-end gap-x-2"- >+ <div class="flex items-center justify-end gap-x-2"><template v-if="isCreating"><template v-if="allowEditStatementWhenCreating"><EditorActionPopover />@@ -206,11 +204,13 @@ import {isTaskEditable,specForTask,isGroupingChangeTaskV1,- databaseEngineForSpec,} from "@/components/IssueV1/logic";import { MonacoEditor } from "@/components/MonacoEditor";import { extensionNameOfLanguage } from "@/components/MonacoEditor/utils";-import { createEmptyLocalSheet } from "@/components/Plan";+import {+ createEmptyLocalSheet,+ databaseEngineForSpec,+} from "@/components/Plan";import { databaseForTask } from "@/components/Rollout/RolloutDetail";import DownloadSheetButton from "@/components/Sheet/DownloadSheetButton.vue";import SQLUploadButton from "@/components/misc/SQLUploadButton.vue";@@ -304,7 +304,13 @@ const allowEditStatementWhenCreating = computed(() => {return false;}// Do not allow to edit statement for the plan with release source.- if ((issue.value.planEntity?.specs?.filter(spec => spec.changeDatabaseConfig?.release)??[]).length > 0) {+ if (+ (+ issue.value.planEntity?.specs?.filter(+ (spec) => spec.changeDatabaseConfig?.release+ ) ?? []+ ).length > 0+ ) {return false;}return true;@@ -360,7 +366,13 @@ const shouldShowEditButton = computed(() => {return false;}// Do not allow to edit statement for the plan with release source.- if ((issue.value.planEntity?.specs?.filter(spec => spec.changeDatabaseConfig?.release)??[]).length > 0) {+ if (+ (+ issue.value.planEntity?.specs?.filter(+ (spec) => spec.changeDatabaseConfig?.release+ ) ?? []+ ).length > 0+ ) {return false;}// Will show another button group as [Upload][Cancel][Save]@@ -627,8 +639,9 @@ const updateStatement = async (statement: string) => {throw new Error("No valid specs found for the selected task(s).");}- const specsToPatch = (planPatch.specs || [])- .filter((spec) => distinctSpecsIds.has(spec.id));+ const specsToPatch = (planPatch.specs || []).filter((spec) =>+ distinctSpecsIds.has(spec.id)+ );const sheet = Sheet.fromPartial({...createEmptyLocalSheet(),title: issue.value.title,diff --git a/frontend/src/components/IssueV1/logic/index.ts b/frontend/src/components/IssueV1/logic/index.tsindex 418aec00fe..8f0aecbe22 100644--- a/frontend/src/components/IssueV1/logic/index.ts+++ b/frontend/src/components/IssueV1/logic/index.ts@@ -1,7 +1,6 @@export * from "./context";export * from "./base";export * from "./releaser";-export * from "./plan";export * from "./review";export * from "./rollout";export * from "./utils";diff --git a/frontend/src/components/IssueV1/logic/initialize/create.ts b/frontend/src/components/IssueV1/logic/initialize/create.tsindex d0a9ecf2c4..e4d27cf647 100644--- a/frontend/src/components/IssueV1/logic/initialize/create.ts+++ b/frontend/src/components/IssueV1/logic/initialize/create.ts@@ -32,14 +32,20 @@ export const createIssueSkeleton = async (const project = await useProjectV1Store().getOrFetchProjectByName(`${projectNamePrefix}${projectName}`);+ const template = query.template as IssueType | undefined;+ if (!template) {+ throw new Error(+ "Template is required to create a plan skeleton. Please provide a valid template."+ );+ }const params: CreatePlanParams = {project,+ template,query,initialSQL: await extractInitialSQLFromQuery(query),};const issue = await buildIssue(params);-const plan = await buildPlan(params);issue.plan = plan.name;issue.planEntity = plan;diff --git a/frontend/src/components/IssueV1/logic/plan-check.ts b/frontend/src/components/IssueV1/logic/plan-check.tsindex 7afab991e6..da505f1627 100644--- a/frontend/src/components/IssueV1/logic/plan-check.ts+++ b/frontend/src/components/IssueV1/logic/plan-check.ts@@ -1,3 +1,4 @@+import { sheetNameForSpec } from "@/components/Plan";import { planCheckRunSummaryForCheckRunList } from "@/components/PlanCheckRun/common";import { databaseForTask } from "@/components/Rollout/RolloutDetail";import type { ComposedIssue } from "@/types";@@ -7,12 +8,7 @@ import {} from "@/types/proto/v1/plan_service";import type { Task } from "@/types/proto/v1/rollout_service";import { Task_Status } from "@/types/proto/v1/rollout_service";-import {- sheetNameForSpec,- specForTask,- useIssueContext,- projectOfIssue,-} from ".";+import { specForTask, useIssueContext, projectOfIssue } from ".";export const planSpecHasPlanChecks = (spec: Plan_Spec) => {if (spec.createDatabaseConfig) {diff --git a/frontend/src/components/IssueV1/logic/plan.ts b/frontend/src/components/IssueV1/logic/plan.tsdeleted file mode 100644index 0ddfcee676..0000000000--- a/frontend/src/components/IssueV1/logic/plan.ts+++ /dev/null@@ -1,59 +0,0 @@-import { head } from "lodash-es";-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";--/**- *- * @returns empty string if no sheet found- */-export const sheetNameForSpec = (spec: Plan_Spec): string => {- return spec.changeDatabaseConfig?.sheet ?? spec.exportDataConfig?.sheet ?? "";-};--export const databaseEngineForSpec = async (- specOrTarget?: Plan_Spec | string-) => {- if (!specOrTarget) return Engine.ENGINE_UNSPECIFIED;-- const getTarget = (specOrTarget: Plan_Spec | string) => {- if (typeof specOrTarget === "string") {- return specOrTarget;- }- const config =- specOrTarget.changeDatabaseConfig || specOrTarget.exportDataConfig;- if (!config) {- return Engine.ENGINE_UNSPECIFIED;- }- return config.target;- };- const target = getTarget(specOrTarget);-- if (extractDatabaseResourceName(target).databaseName !== String(UNKNOWN_ID)) {- const db = await useDatabaseV1Store().getOrFetchDatabaseByName(- target,- /* silent */ true- );- if (isValidDatabaseName(db.name)) {- return db.instanceResource.engine;- }- }- if (extractDatabaseGroupName(target)) {- const dbGroupStore = useDBGroupStore();- const dbGroup = await dbGroupStore.getOrFetchDBGroupByName(target);- // Might be flaky: use the first database in the db group- const dbName = head(dbGroup.matchedDatabases)?.name;- if (dbName) {- const db = await useDatabaseV1Store().getOrFetchDatabaseByName(- dbName,- /* silent */ true- );- if (isValidDatabaseName(db.name)) {- return db.instanceResource.engine;- }- }- }- return Engine.ENGINE_UNSPECIFIED;-};diff --git a/frontend/src/components/IssueV1/logic/rollout.ts b/frontend/src/components/IssueV1/logic/rollout.tsindex 4b41fe5c66..735ecc53c0 100644--- a/frontend/src/components/IssueV1/logic/rollout.ts+++ b/frontend/src/components/IssueV1/logic/rollout.ts@@ -1,3 +1,4 @@+import { head } from "lodash-es";import { planCheckRunSummaryForCheckRunList } from "@/components/PlanCheckRun/common";import { t } from "@/plugins/i18n";import { useCurrentUserV1, extractUserId } from "@/store";@@ -18,9 +19,8 @@ export const isGroupingChangeTaskV1 = (issue: ComposedIssue, task: Task) => {if (!spec) {return false;}- const databaseGroup = extractDatabaseGroupName(- spec.changeDatabaseConfig?.target ?? ""- );+ const target = head(spec.changeDatabaseConfig?.targets);+ const databaseGroup = extractDatabaseGroupName(target ?? "");return databaseGroup !== "";};diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateButton.vue b/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateButton.vueindex a79edcddbd..e3b3f272dd 100644--- a/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateButton.vue+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateButton.vue@@ -43,12 +43,9 @@ import {import { usePlanContext } from "@/components/Plan/logic";import { planServiceClient } from "@/grpcweb";import { PROJECT_V1_ROUTE_REVIEW_CENTER_DETAIL } from "@/router/dashboard/projectV1";-import {- useCurrentProjectV1,- useDatabaseV1Store,- useSheetV1Store,-} from "@/store";+import { useCurrentProjectV1, useSheetV1Store } from "@/store";import { dialectOfEngineV1, languageOfEngineV1 } from "@/types";+import type { Engine } from "@/types/proto/v1/common";import { type Plan_ChangeDatabaseConfig } from "@/types/proto/v1/plan_service";import type { Sheet } from "@/types/proto/v1/sheet_service";import type { ComposedPlan } from "@/types/v1/issue/plan";@@ -136,8 +133,7 @@ const createSheets = async () => {const engine = await databaseEngineForSpec(spec);sheet.engine = engine;pendingCreateSheetMap.set(sheet.name, sheet);-- await maybeFormatSQL(sheet, config.target);+ await maybeFormatSQL(sheet, engine);}}const pendingCreateSheetList = Array.from(pendingCreateSheetMap.values());@@ -159,20 +155,15 @@ const createSheets = async () => {});};-const maybeFormatSQL = async (sheet: Sheet, target: string) => {+const maybeFormatSQL = async (sheet: Sheet, engine: Engine) => {if (!formatOnSave.value) {return;}- const db = await useDatabaseV1Store().getOrFetchDatabaseByName(target);- if (!db) {- return;- }- const language = languageOfEngineV1(db.instanceResource.engine);+ const language = languageOfEngineV1(engine);if (language !== "sql") {return;}-- const dialect = dialectOfEngineV1(db.instanceResource.engine);+ const dialect = dialectOfEngineV1(engine);const statement = getSheetStatement(sheet);if (statement.length > MAX_FORMATTABLE_STATEMENT_SIZE) {return;diff --git a/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue b/frontend/src/components/Plan/components/SpecListSection/SpecCard.vueindex d2017bbb83..2ce85194f7 100644--- a/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue+++ b/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue@@ -61,7 +61,7 @@</template><script setup lang="ts">-import { isEqual } from "lodash-es";+import { head, isEqual } from "lodash-es";import { AlertCircleIcon } from "lucide-vue-next";import { NTooltip } from "naive-ui";import { computed } from "vue";@@ -79,6 +79,7 @@ import {usePlanContext,isGroupingChangeSpec,planCheckRunListForSpec,+ targetsForSpec,} from "../../logic";const props = defineProps<{@@ -113,7 +114,12 @@ const relatedDatabaseGroup = computed(() => {if (!isGroupingChangeSpec(props.spec)) {return undefined;}- return dbGroupStore.getDBGroupByName(props.spec.changeDatabaseConfig!.target);+ const targets = targetsForSpec(props.spec);+ const maybeDBGroupName = head(targets);+ if (!maybeDBGroupName) {+ return undefined;+ }+ return dbGroupStore.getDBGroupByName(maybeDBGroupName);});const planCheckStatus = computed((): PlanCheckRun_Result_Status => {diff --git a/frontend/src/components/Plan/logic/initialize/create.ts b/frontend/src/components/Plan/logic/initialize/create.tsindex b979ba0754..2d8b6c26a3 100644--- a/frontend/src/components/Plan/logic/initialize/create.ts+++ b/frontend/src/components/Plan/logic/initialize/create.ts@@ -1,4 +1,4 @@-import { cloneDeep } from "lodash-es";+import { cloneDeep, includes } from "lodash-es";import { v4 as uuidv4 } from "uuid";import { useRoute } from "vue-router";import {@@ -33,6 +33,7 @@ export type InitialSQL = {export type CreatePlanParams = {project: ComposedProject;+ template: IssueType;query: Record<string, string>;initialSQL: InitialSQL;};@@ -52,8 +53,15 @@ export const createPlanSkeleton = async (const project = await useProjectV1Store().getOrFetchProjectByName(`${projectNamePrefix}${projectName}`);+ const template = query.template as IssueType | undefined;+ if (!template) {+ throw new Error(+ "Template is required to create a plan skeleton. Please provide a valid template."+ );+ }const params: CreatePlanParams = {project,+ template,query,initialSQL: await extractInitialSQLFromQuery(query),};@@ -90,62 +98,70 @@ const buildSpecs = async (params: CreatePlanParams,sheetUID?: string // if specified, all specs will share the same sheet) => {- const specs: Plan_Spec[] = [];- for (const target of targets) {- const spec = await buildSpecForTarget(target, params, sheetUID);- specs.push(spec);- maybeSetInitialSQLForSpec(spec, target, params);+ if (+ !includes(+ [+ "bb.issue.database.data.update",+ "bb.issue.database.schema.update",+ "bb.issue.database.data.export",+ ],+ params.template+ )+ ) {+ throw new Error(+ "Unsupported template for plan creation: " + params.template+ );}- return specs;+ const spec = await buildSpecForTargetsV1(targets, params, sheetUID);+ maybeSetInitialSQLForSpec(spec, params);+ return [spec];};-const buildSpecForTarget = async (- target: string,- { project, query }: CreatePlanParams,+const buildSpecForTargetsV1 = async (+ targets: string[],+ { project, template, query }: CreatePlanParams,sheetUID?: string) => {- const sheet = `${project.name}/sheets/${sheetUID ?? nextUID()}`;- const template = query.template as IssueType | undefined;+ let sheet = `${project.name}/sheets/${sheetUID ?? nextUID()}`;+ if (query.sheetId) {+ const remoteSheet = await useSheetV1Store().getOrFetchSheetByUID(+ query.sheetId,+ "FULL"+ );+ if (remoteSheet) {+ // make a local copy for remote sheet for further editing+ console.debug(+ "copy remote sheet to local for further editing",+ remoteSheet+ );+ const localSheet = getLocalSheetByName(sheet);+ localSheet.payload = cloneDeep(remoteSheet.payload);+ const statement = getSheetStatement(remoteSheet);+ setSheetStatement(localSheet, statement);+ sheet = remoteSheet.name;+ }+ }+const spec = Plan_Spec.fromPartial({id: uuidv4(),});-switch (template) {case "bb.issue.database.data.update":case "bb.issue.database.schema.update": {- const specType =- template === "bb.issue.database.data.update"- ? Plan_ChangeDatabaseConfig_Type.DATA- : Plan_ChangeDatabaseConfig_Type.MIGRATE;spec.changeDatabaseConfig = Plan_ChangeDatabaseConfig.fromPartial({- target,+ targets,sheet,- type: specType,+ type:+ template === "bb.issue.database.data.update"+ ? Plan_ChangeDatabaseConfig_Type.DATA+ : Plan_ChangeDatabaseConfig_Type.MIGRATE,});- if (query.sheetId) {- const remoteSheet = await useSheetV1Store().getOrFetchSheetByUID(- query.sheetId,- "FULL"- );- if (remoteSheet) {- // make a local copy for remote sheet for further editing- console.debug(- "copy remote sheet to local for further editing",- remoteSheet- );- const localSheet = getLocalSheetByName(sheet);- localSheet.payload = cloneDeep(remoteSheet.payload);- const statement = getSheetStatement(remoteSheet);- setSheetStatement(localSheet, statement);- spec.changeDatabaseConfig.sheet = remoteSheet.name;- }- }break;}case "bb.issue.database.data.export": {spec.exportDataConfig = Plan_ExportDataConfig.fromPartial({+ targets,sheet,- target,});break;}@@ -170,7 +186,7 @@ const buildSpecsViaChangelist = async (const sheetName = `${params.project.name}/sheets/${sheetUID}`;const sheet = getLocalSheetByName(sheetName);setSheetStatement(sheet, statement);- const spec = await buildSpecForTarget(db, params, sheetUID);+ const spec = await buildSpecForTargetsV1([db], params, sheetUID);specs.push(spec);}}@@ -179,7 +195,6 @@ const buildSpecsViaChangelist = async (const maybeSetInitialSQLForSpec = (spec: Plan_Spec,- key: string,params: CreatePlanParams) => {const sheet = sheetNameForSpec(spec);@@ -190,7 +205,8 @@ const maybeSetInitialSQLForSpec = (return;}// Priority: sqlMap[key] -> sql -> nothing- const sql = params.initialSQL.sqlMap?.[key] ?? params.initialSQL.sql ?? "";+ const sql =+ params.initialSQL.sqlMap?.[spec.id] ?? params.initialSQL.sql ?? "";if (sql) {const sheetEntity = getLocalSheetByName(sheet);setSheetStatement(sheetEntity, sql);diff --git a/frontend/src/components/Plan/logic/plan.ts b/frontend/src/components/Plan/logic/plan.tsindex 4814ca099c..de788b7ae2 100644--- a/frontend/src/components/Plan/logic/plan.ts+++ b/frontend/src/components/Plan/logic/plan.ts@@ -1,22 +1,26 @@+import { head } from "lodash-es";import { mockDatabase } from "@/components/IssueV1/logic/utils";-import { useDatabaseV1Store } from "@/store";+import { useDatabaseV1Store, useDBGroupStore } from "@/store";import {+ isValidDatabaseGroupName,isValidDatabaseName,unknownDatabase,type ComposedProject,} from "@/types";import { Engine } from "@/types/proto/v1/common";import type { Plan_Spec } from "@/types/proto/v1/plan_service";-import { extractDatabaseGroupName } from "@/utils";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);+ const targets = targetsForSpec(spec);+ if (targets.length === 0) {+ return unknownDatabase();+ }+ const db = useDatabaseV1Store().getDatabaseByName(targets[0]);if (!isValidDatabaseName(db.name)) {- return mockDatabase(project, target);+ return mockDatabase(project, targets[0]);}return db;}@@ -28,7 +32,7 @@ export const databaseForSpec = (project: ComposedProject, spec: Plan_Spec) => {* @returns empty string if no sheet found*/export const sheetNameForSpec = (spec: Plan_Spec): string => {- return spec.changeDatabaseConfig?.sheet ?? "";+ return spec.changeDatabaseConfig?.sheet ?? spec.exportDataConfig?.sheet ?? "";};export const databaseEngineForSpec = async (@@ -40,36 +44,62 @@ export const databaseEngineForSpec = async (if (typeof specOrTarget === "string") {return specOrTarget;}- const config = specOrTarget.changeDatabaseConfig;- if (!config) {- return Engine.ENGINE_UNSPECIFIED;- }- return config.target;+ const targets = targetsForSpec(specOrTarget);+ return head(targets);};- const target = getTarget(specOrTarget);+ const target = getTarget(specOrTarget);+ if (!target) return Engine.ENGINE_UNSPECIFIED;if (isValidDatabaseName(target)) {const db = await useDatabaseV1Store().getOrFetchDatabaseByName(target,true /* silent */);- if (isValidDatabaseName(db.name)) {- return db.instanceResource.engine;+ return db.instanceResource.engine;+ }+ if (isValidDatabaseGroupName(target)) {+ const dbGroupStore = useDBGroupStore();+ const dbGroup = await dbGroupStore.getOrFetchDBGroupByName(target);+ // Might be flaky: use the first database in the db group+ const dbName = head(dbGroup.matchedDatabases)?.name;+ if (dbName) {+ const db = await useDatabaseV1Store().getOrFetchDatabaseByName(+ dbName,+ /* silent */ true+ );+ if (isValidDatabaseName(db.name)) {+ return db.instanceResource.engine;+ }}}-return Engine.ENGINE_UNSPECIFIED;};export const isDatabaseChangeSpec = (spec?: Plan_Spec) => {if (!spec) return false;- return isValidDatabaseName(spec.changeDatabaseConfig?.target);+ const config = spec.changeDatabaseConfig || spec.exportDataConfig;+ if (config) {+ return targetsForSpec(spec).every(isValidDatabaseName);+ }+ return false;};export const isGroupingChangeSpec = (spec?: Plan_Spec) => {if (!spec) return false;- const databaseGroup = extractDatabaseGroupName(- spec.changeDatabaseConfig?.target ?? ""- );- return databaseGroup !== "";+ const config = spec.changeDatabaseConfig || spec.exportDataConfig;+ if (config) {+ return targetsForSpec(spec).every(isValidDatabaseGroupName);+ }+ return false;+};++export const targetsForSpec = (spec: Plan_Spec): string[] => {+ const config = spec.changeDatabaseConfig || spec.exportDataConfig;+ if (config) {+ if (config.targets && config.targets.length > 0) {+ return config.targets;+ }+ return [config.target];+ }+ return [];};diff --git a/frontend/src/components/Plan/logic/utils.ts b/frontend/src/components/Plan/logic/utils.tsindex f41362b37e..f604b35b00 100644--- a/frontend/src/components/Plan/logic/utils.ts+++ b/frontend/src/components/Plan/logic/utils.ts@@ -1,20 +1,18 @@+import { head } from "lodash-es";import { mockDatabase } from "@/components/IssueV1";import { useDatabaseV1Store, useProjectV1Store } from "@/store";import { isValidDatabaseName, unknownDatabase } from "@/types";import type { ComposedProject } from "@/types";import type { Plan_Spec } from "@/types/proto/v1/plan_service";import type { ComposedPlan } from "@/types/v1/issue/plan";+import { targetsForSpec } from "./plan";export const projectOfPlan = (plan: ComposedPlan): ComposedProject =>useProjectV1Store().getProjectByName(plan.project);export const targetOfSpec = (spec: Plan_Spec) => {- if (spec.changeDatabaseConfig) {- return spec.changeDatabaseConfig.target;- } else if (spec.exportDataConfig) {- return spec.exportDataConfig.target;- }- return undefined;+ const targets = targetsForSpec(spec);+ return head(targets);};export const databaseOfSpec = (project: ComposedProject, spec: Plan_Spec) => {diff --git a/frontend/src/types/dbGroup.ts b/frontend/src/types/dbGroup.tsindex be05868dd1..7550c3e696 100644--- a/frontend/src/types/dbGroup.ts+++ b/frontend/src/types/dbGroup.ts@@ -1,5 +1,6 @@import type { ConditionGroupExpr } from "@/plugins/cel";-import type { ComposedProject } from "@/types";+import { UNKNOWN_ID, type ComposedProject } from "@/types";+import { extractDatabaseGroupName } from "@/utils";import type { DatabaseGroup } from "./proto/v1/database_group_service";export interface ComposedDatabaseGroup extends DatabaseGroup {@@ -7,3 +8,9 @@ export interface ComposedDatabaseGroup extends DatabaseGroup {projectEntity: ComposedProject;simpleExpr: ConditionGroupExpr;}++export const isValidDatabaseGroupName = (name: string): boolean => {+ if (typeof name !== "string") return false;+ const dbGroupName = extractDatabaseGroupName(name);+ return Boolean(dbGroupName) && dbGroupName !== String(UNKNOWN_ID);+};diff --git a/frontend/src/types/proto/v1/plan_service.ts b/frontend/src/types/proto/v1/plan_service.tsindex 767d739fd4..35bca2725a 100644--- a/frontend/src/types/proto/v1/plan_service.ts+++ b/frontend/src/types/proto/v1/plan_service.ts@@ -215,6 +215,7 @@ export interface Plan_ChangeDatabaseConfig {* The resource name of the target.* Format: instances/{instance-id}/databases/{database-name}.* Format: projects/{project}/databaseGroups/{databaseGroup}.+ * Deprecated: use targets instead.*/target: string;/**@@ -330,6 +331,7 @@ export interface Plan_ExportDataConfig {/*** The resource name of the target.* Format: instances/{instance-id}/databases/{database-name}+ * Deprecated: use targets instead.*/target: string;/**diff --git a/proto/gen/grpc-doc/openapi.yaml b/proto/gen/grpc-doc/openapi.yamlindex 288ea53ca1..2038b012ef 100644--- a/proto/gen/grpc-doc/openapi.yaml+++ b/proto/gen/grpc-doc/openapi.yaml@@ -11196,6 +11196,7 @@ components:The resource name of the target.Format: instances/{instance-id}/databases/{database-name}.Format: projects/{project}/databaseGroups/{databaseGroup}.+ Deprecated: use targets instead.targets:type: arrayitems:@@ -11288,6 +11289,7 @@ components:description: |-The resource name of the target.Format: instances/{instance-id}/databases/{database-name}+ Deprecated: use targets instead.targets:type: arrayitems:diff --git a/proto/gen/grpc-doc/store/README.md b/proto/gen/grpc-doc/store/README.mdindex 0957e84f70..3f82916405 100644--- a/proto/gen/grpc-doc/store/README.md+++ b/proto/gen/grpc-doc/store/README.md@@ -3071,7 +3071,7 @@ InstanceRole is the API message for instance role.| Field | Type | Label | Description || ----- | ---- | ----- | ----------- |-| target | [string](#string) | | The resource name of the target. Format: instances/{instance-id}/databases/{database-name} |+| target | [string](#string) | | The resource name of the target. Format: instances/{instance-id}/databases/{database-name} Deprecated: Use `targets` instead. || targets | [string](#string) | repeated | The list of targets. Multi-database format: [instances/{instance-id}/databases/{database-name}]. Single database group format: [projects/{project}/databaseGroups/{databaseGroup}]. || sheet | [string](#string) | | The resource name of the sheet. Format: projects/{project}/sheets/{sheet} || format | [ExportFormat](#bytebase-store-ExportFormat) | | The format of the exported file. |diff --git a/proto/gen/grpc-doc/store/index.html b/proto/gen/grpc-doc/store/index.htmlindex 59ba7e4480..7bc8f66c4c 100644--- a/proto/gen/grpc-doc/store/index.html+++ b/proto/gen/grpc-doc/store/index.html@@ -8562,7 +8562,8 @@ Format: environments/prod where prod is the environment resource ID. </p></td><td><a href="#string">string</a></td><td></td><td><p>The resource name of the target.-Format: instances/{instance-id}/databases/{database-name} </p></td>+Format: instances/{instance-id}/databases/{database-name}+Deprecated: Use `targets` instead. </p></td></tr><tr>diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.mdindex f61c0be768..278229ecaa 100644--- a/proto/gen/grpc-doc/v1/README.md+++ b/proto/gen/grpc-doc/v1/README.md@@ -7328,7 +7328,7 @@ When paginating, all other parameters provided to `ListPlans` must match the cal| Field | Type | Label | Description || ----- | ---- | ----- | ----------- |-| target | [string](#string) | | The resource name of the target. Format: instances/{instance-id}/databases/{database-name}. Format: projects/{project}/databaseGroups/{databaseGroup}. |+| target | [string](#string) | | The resource name of the target. Format: instances/{instance-id}/databases/{database-name}. Format: projects/{project}/databaseGroups/{databaseGroup}. Deprecated: use targets instead. || targets | [string](#string) | repeated | The list of targets. Multi-database format: [instances/{instance-id}/databases/{database-name}]. Single database group format: [projects/{project}/databaseGroups/{databaseGroup}]. || sheet | [string](#string) | | The resource name of the sheet. Format: projects/{project}/sheets/{sheet} || release | [string](#string) | | The resource name of the release. Format: projects/{project}/releases/{release} |@@ -7434,7 +7434,7 @@ When paginating, all other parameters provided to `ListPlans` must match the cal| Field | Type | Label | Description || ----- | ---- | ----- | ----------- |-| target | [string](#string) | | The resource name of the target. Format: instances/{instance-id}/databases/{database-name} |+| target | [string](#string) | | The resource name of the target. Format: instances/{instance-id}/databases/{database-name} Deprecated: use targets instead. || targets | [string](#string) | repeated | The list of targets. Multi-database format: [instances/{instance-id}/databases/{database-name}]. Single database group format: [projects/{project}/databaseGroups/{databaseGroup}]. || sheet | [string](#string) | | The resource name of the sheet. Format: projects/{project}/sheets/{sheet} || format | [ExportFormat](#bytebase-v1-ExportFormat) | | The format of the exported file. |diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.htmlindex 6af4c9dbf1..54fcc83b9d 100644--- a/proto/gen/grpc-doc/v1/index.html+++ b/proto/gen/grpc-doc/v1/index.html@@ -20456,7 +20456,8 @@ Keys are:<td></td><td><p>The resource name of the target.Format: instances/{instance-id}/databases/{database-name}.-Format: projects/{project}/databaseGroups/{databaseGroup}. </p></td>+Format: projects/{project}/databaseGroups/{databaseGroup}.+Deprecated: use targets instead. </p></td></tr><tr>@@ -20721,7 +20722,8 @@ Format: environments/prod where prod is the environment resource ID. </p></td><td><a href="#string">string</a></td><td></td><td><p>The resource name of the target.-Format: instances/{instance-id}/databases/{database-name} </p></td>+Format: instances/{instance-id}/databases/{database-name}+Deprecated: use targets instead. </p></td></tr><tr>diff --git a/proto/generated-go/store/plan.pb.go b/proto/generated-go/store/plan.pb.goindex e04306a65d..a7f2e8a911 100644--- a/proto/generated-go/store/plan.pb.go+++ b/proto/generated-go/store/plan.pb.go@@ -448,6 +448,7 @@ type PlanConfig_ExportDataConfig struct {state protoimpl.MessageState `protogen:"open.v1"`// The resource name of the target.// Format: instances/{instance-id}/databases/{database-name}+ // Deprecated: Use `targets` instead.Target string `protobuf:"bytes,1,opt,name=target,proto3" json:"target,omitempty"`// The list of targets.// Multi-database format: [instances/{instance-id}/databases/{database-name}].diff --git a/proto/generated-go/v1/plan_service.pb.go b/proto/generated-go/v1/plan_service.pb.goindex 41aeaaa01c..a0ee799a07 100644--- a/proto/generated-go/v1/plan_service.pb.go+++ b/proto/generated-go/v1/plan_service.pb.go@@ -1509,6 +1509,7 @@ type Plan_ChangeDatabaseConfig struct {// The resource name of the target.// Format: instances/{instance-id}/databases/{database-name}.// Format: projects/{project}/databaseGroups/{databaseGroup}.+ // Deprecated: use targets instead.Target string `protobuf:"bytes,1,opt,name=target,proto3" json:"target,omitempty"`// The list of targets.// Multi-database format: [instances/{instance-id}/databases/{database-name}].@@ -1611,6 +1612,7 @@ type Plan_ExportDataConfig struct {state protoimpl.MessageState `protogen:"open.v1"`// The resource name of the target.// Format: instances/{instance-id}/databases/{database-name}+ // Deprecated: use targets instead.Target string `protobuf:"bytes,1,opt,name=target,proto3" json:"target,omitempty"`// The list of targets.// Multi-database format: [instances/{instance-id}/databases/{database-name}].diff --git a/proto/store/store/plan.proto b/proto/store/store/plan.protoindex ea5bc90f00..e54eb496cc 100644--- a/proto/store/store/plan.proto+++ b/proto/store/store/plan.proto@@ -80,6 +80,7 @@ message PlanConfig {message ExportDataConfig {// The resource name of the target.// Format: instances/{instance-id}/databases/{database-name}+ // Deprecated: Use `targets` instead.string target = 1;// The list of targets.// Multi-database format: [instances/{instance-id}/databases/{database-name}].diff --git a/proto/v1/v1/plan_service.proto b/proto/v1/v1/plan_service.protoindex 4675fd74f6..d4925a9f80 100644--- a/proto/v1/v1/plan_service.proto+++ b/proto/v1/v1/plan_service.proto@@ -285,6 +285,7 @@ message Plan {// The resource name of the target.// Format: instances/{instance-id}/databases/{database-name}.// Format: projects/{project}/databaseGroups/{databaseGroup}.+ // Deprecated: use targets instead.string target = 1;// The list of targets.// Multi-database format: [instances/{instance-id}/databases/{database-name}].@@ -326,6 +327,7 @@ message Plan {message ExportDataConfig {// The resource name of the target.// Format: instances/{instance-id}/databases/{database-name}+ // Deprecated: use targets instead.string target = 1;// The list of targets.// Multi-database format: [instances/{instance-id}/databases/{database-name}].