Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat: multi database selector in tenant mode (#3216)

boojack8bd77caa01cd
diff --git a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
index ad70b17956..8347a06560 100644
--- a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
+++ b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
@@ -7,8 +7,8 @@
<!-- tenant mode project -->
<NTabs v-model:value="state.alterType">
<NTabPane
- :tab="$t('alter-schema.alter-multiple-db')"
- name="MULTI_DB"
+ :tab="$t('alter-schema.alter-db-group')"
+ name="DB_GROUP"
>
<ProjectTenantView
:state="state"
@@ -19,21 +19,32 @@
/>
</NTabPane>
<NTabPane
- :tab="$t('alter-schema.alter-single-db')"
- name="SINGLE_DB"
+ :tab="$t('alter-schema.alter-multiple-db')"
+ name="MULTI_DB"
>
- <!-- a simple table -->
<DatabaseTable
mode="PROJECT_SHORT"
:bordered="true"
:custom-click="true"
:database-list="databaseList"
- @select-database="selectDatabase"
- />
+ :show-selection-column="true"
+ @select-database="
+ (db: Database) => toggleDatabaseSelection(db, !isDatabaseSelected(db))
+ "
+ >
+ <template #selection="{ database }">
+ <input
+ type="checkbox"
+ class="h-4 w-4 text-accent rounded disabled:cursor-not-allowed border-control-border focus:ring-accent"
+ :checked="isDatabaseSelected(database)"
+ @input="(e: any) => toggleDatabaseSelection(database, e.target.checked)"
+ />
+ </template>
+ </DatabaseTable>
</NTabPane>
<template #suffix>
<BBTableSearch
- v-if="state.alterType === 'SINGLE_DB'"
+ v-if="state.alterType === 'MULTI_DB'"
class="m-px"
:placeholder="$t('database.search-database-name')"
@change-text="(text: string) => (state.searchText = text)"
@@ -137,8 +148,9 @@
<GhostDialog ref="ghostDialog" />
</template>
-<script lang="ts">
-import { computed, reactive, PropType, defineComponent, ref } from "vue";
+<script lang="ts" setup>
+import dayjs from "dayjs";
+import { computed, reactive, PropType, ref } from "vue";
import { useRouter } from "vue-router";
import { NTabs, NTabPane } from "naive-ui";
import { useEventListener } from "@vueuse/core";
@@ -170,7 +182,6 @@ import {
useProjectStore,
useRepositoryStore,
} from "@/store";
-import dayjs from "dayjs";
type LocalState = ProjectStandardState &
ProjectTenantState &
@@ -178,332 +189,332 @@ type LocalState = ProjectStandardState &
project?: Project;
showFeatureModal: boolean;
searchText: string;
+ selectedDatabaseIdList: Set<number>;
};
-export default defineComponent({
- name: "AlterSchemaPrepForm",
- components: {
- DatabaseTable,
- ProjectStandardView,
- ProjectTenantView,
- NTabs,
- NTabPane,
- GhostDialog,
+const props = defineProps({
+ projectId: {
+ type: Number as PropType<ProjectId>,
+ default: undefined,
},
- props: {
- projectId: {
- type: Number as PropType<ProjectId>,
- default: undefined,
- },
- type: {
- type: String as PropType<
- "bb.issue.database.schema.update" | "bb.issue.database.data.update"
- >,
- required: true,
- },
+ type: {
+ type: String as PropType<
+ "bb.issue.database.schema.update" | "bb.issue.database.data.update"
+ >,
+ required: true,
},
- emits: ["dismiss"],
- setup(props, { emit }) {
- const router = useRouter();
-
- const currentUser = useCurrentUser();
- const projectStore = useProjectStore();
- const repositoryStore = useRepositoryStore();
-
- const ghostDialog = ref<InstanceType<typeof GhostDialog>>();
-
- useEventListener(window, "keydown", (e) => {
- if (e.code === "Escape") {
- cancel();
- }
- });
-
- const state = reactive<LocalState>({
- project: props.projectId
- ? projectStore.getProjectById(props.projectId)
- : undefined,
- alterType: "SINGLE_DB",
- selectedDatabaseIdListForEnvironment: new Map(),
- tenantProjectId: undefined,
- selectedDatabaseName: undefined,
- deployingTenantDatabaseList: [],
- showFeatureModal: false,
- searchText: "",
- });
-
- // Returns true if alter schema, false if change data.
- const isAlterSchema = computed((): boolean => {
- return props.type === "bb.issue.database.schema.update";
- });
+});
- const isTenantProject = computed((): boolean => {
- return state.project?.tenantMode === "TENANT";
- });
+const emit = defineEmits(["dismiss"]);
- if (isTenantProject.value) {
- // For tenant mode projects, alter multiple db via DeploymentConfig
- // is the default suggested way.
- state.alterType = "MULTI_DB";
- }
+const router = useRouter();
- const environmentList = useEnvironmentList(["NORMAL"]);
+const currentUser = useCurrentUser();
+const projectStore = useProjectStore();
+const repositoryStore = useRepositoryStore();
- const databaseList = computed(() => {
- const databaseStore = useDatabaseStore();
- let list;
- if (props.projectId) {
- list = databaseStore.getDatabaseListByProjectId(props.projectId);
- } else {
- list = databaseStore.getDatabaseListByPrincipalId(currentUser.value.id);
- }
+const ghostDialog = ref<InstanceType<typeof GhostDialog>>();
- const keyword = state.searchText.trim();
- if (keyword) {
- list = list.filter((db) => db.name.toLowerCase().includes(keyword));
- }
+useEventListener(window, "keydown", (e) => {
+ if (e.code === "Escape") {
+ cancel();
+ }
+});
- return sortDatabaseList(cloneDeep(list), environmentList.value);
- });
+const state = reactive<LocalState>({
+ project: props.projectId
+ ? projectStore.getProjectById(props.projectId)
+ : undefined,
+ alterType: "SINGLE_DB",
+ selectedDatabaseIdListForEnvironment: new Map(),
+ tenantProjectId: undefined,
+ selectedDatabaseName: undefined,
+ deployingTenantDatabaseList: [],
+ showFeatureModal: false,
+ searchText: "",
+ selectedDatabaseIdList: new Set<number>(),
+});
- const flattenSelectedDatabaseIdList = computed(() => {
- const flattenDatabaseIdList: DatabaseId[] = [];
- for (const databaseIdList of state.selectedDatabaseIdListForEnvironment.values()) {
- flattenDatabaseIdList.push(...databaseIdList);
- }
- return flattenDatabaseIdList;
- });
+const isDatabaseSelected = (database: Database): boolean => {
+ return state.selectedDatabaseIdList.has(database.id);
+};
+
+const toggleDatabaseSelection = (database: Database, on: boolean) => {
+ if (on) {
+ state.selectedDatabaseIdList.add(database.id);
+ } else {
+ state.selectedDatabaseIdList.delete(database.id);
+ }
+};
+
+// Returns true if alter schema, false if change data.
+const isAlterSchema = computed((): boolean => {
+ return props.type === "bb.issue.database.schema.update";
+});
- const showGenerateMultiDb = computed(() => {
- if (isTenantProject.value) return false;
- return state.alterType === "MULTI_DB";
- });
+const isTenantProject = computed((): boolean => {
+ return state.project?.tenantMode === "TENANT";
+});
- const allowGenerateMultiDb = computed(() => {
- return flattenSelectedDatabaseIdList.value.length > 0;
- });
+if (isTenantProject.value) {
+ // For tenant mode projects, alter multiple db via DeploymentConfig
+ // is the default suggested way.
+ state.alterType = "DB_GROUP";
+}
+
+const environmentList = useEnvironmentList(["NORMAL"]);
+
+const databaseList = computed(() => {
+ const databaseStore = useDatabaseStore();
+ let list;
+ if (props.projectId) {
+ list = databaseStore.getDatabaseListByProjectId(props.projectId);
+ } else {
+ list = databaseStore.getDatabaseListByPrincipalId(currentUser.value.id);
+ }
+
+ const keyword = state.searchText.trim();
+ if (keyword) {
+ list = list.filter((db) => db.name.toLowerCase().includes(keyword));
+ }
+
+ return sortDatabaseList(cloneDeep(list), environmentList.value);
+});
- // 'normal' -> normal migration
- // 'online' -> online migration
- // false -> user clicked cancel button
- const isUsingGhostMigration = async (databaseList: Database[]) => {
- // Gh-ost is not available for tenant mode yet.
- if (databaseList.some((db) => db.project.tenantMode === "TENANT")) {
- return "normal";
- }
+const flattenSelectedDatabaseIdList = computed(() => {
+ const flattenDatabaseIdList: DatabaseId[] = [];
+ for (const databaseIdList of state.selectedDatabaseIdListForEnvironment.values()) {
+ flattenDatabaseIdList.push(...databaseIdList);
+ }
+ return flattenDatabaseIdList;
+});
- // never available for "bb.issue.database.data.update"
- if (props.type === "bb.issue.database.data.update") {
- return "normal";
- }
+const showGenerateMultiDb = computed(() => {
+ if (isTenantProject.value) return false;
+ return state.alterType === "MULTI_DB";
+});
- // check if all selected databases supports gh-ost
- if (allowGhostMigration(databaseList)) {
- // open the dialog to ask the user
- const { result, mode } = await ghostDialog.value!.open();
- if (!result) {
- return false; // return false when user clicked the cancel button
- }
- return mode;
- }
+const allowGenerateMultiDb = computed(() => {
+ return flattenSelectedDatabaseIdList.value.length > 0;
+});
- // fallback to normal
- return "normal";
- };
+// 'normal' -> normal migration
+// 'online' -> online migration
+// false -> user clicked cancel button
+const isUsingGhostMigration = async (databaseList: Database[]) => {
+ // Gh-ost is not available for tenant mode yet.
+ if (databaseList.some((db) => db.project.tenantMode === "TENANT")) {
+ return "normal";
+ }
+
+ // never available for "bb.issue.database.data.update"
+ if (props.type === "bb.issue.database.data.update") {
+ return "normal";
+ }
+
+ // check if all selected databases supports gh-ost
+ if (allowGhostMigration(databaseList)) {
+ // open the dialog to ask the user
+ const { result, mode } = await ghostDialog.value!.open();
+ if (!result) {
+ return false; // return false when user clicked the cancel button
+ }
+ return mode;
+ }
+
+ // fallback to normal
+ return "normal";
+};
+
+// Also works when single db selected.
+const generateMultiDb = async () => {
+ const selectedDatabaseIdList = [...flattenSelectedDatabaseIdList.value];
+
+ const selectedDatabaseList = selectedDatabaseIdList.map(
+ (id) => databaseList.value.find((db) => db.id === id)!
+ );
+
+ const mode = await isUsingGhostMigration(selectedDatabaseList);
+ if (mode === false) {
+ return;
+ }
+
+ const query: Record<string, any> = {
+ template: props.type,
+ name: generateIssueName(
+ selectedDatabaseList.map((db) => db.name),
+ mode === "online"
+ ),
+ project: props.projectId,
+ // The server-side will sort the databases by environment.
+ // So we need not to sort them here.
+ databaseList: selectedDatabaseIdList.join(","),
+ };
+ if (mode === "online") {
+ query.ghost = "1";
+ }
+ router.push({
+ name: "workspace.issue.detail",
+ params: {
+ issueSlug: "new",
+ },
+ query,
+ });
+};
+
+const showGenerateTenant = computed(() => {
+ // True when a tenant project is selected and "DB_GROUP" is selected.
+ if (isTenantProject.value) {
+ return true;
+ }
+ return false;
+});
- // Also works when single db selected.
- const generateMultiDb = async () => {
- const selectedDatabaseIdList = [...flattenSelectedDatabaseIdList.value];
+const allowGenerateTenant = computed(() => {
+ if (isTenantProject.value && state.alterType === "MULTI_DB") {
+ if (state.selectedDatabaseIdList.size === 0) {
+ return false;
+ }
+ }
- const selectedDatabaseList = selectedDatabaseIdList.map(
- (id) => databaseList.value.find((db) => db.id === id)!
- );
+ // All databases will be in the same group if dbNameTemplate is empty.
+ if (isTenantProject.value && state.project?.dbNameTemplate === "")
+ return true;
+ if (!state.selectedDatabaseName) return false;
- const mode = await isUsingGhostMigration(selectedDatabaseList);
- if (mode === false) {
- return;
- }
+ // not allowed when database list filtered by deployment config is empty
+ // which means no database will be deployed
+ if (state.deployingTenantDatabaseList.length === 0) return false;
- const query: Record<string, any> = {
- template: props.type,
- name: generateIssueName(
- selectedDatabaseList.map((db) => db.name),
- mode === "online"
- ),
- project: props.projectId,
- // The server-side will sort the databases by environment.
- // So we need not to sort them here.
- databaseList: selectedDatabaseIdList.join(","),
- };
- if (mode === "online") {
- query.ghost = "1";
- }
- router.push({
- name: "workspace.issue.detail",
- params: {
- issueSlug: "new",
- },
- query,
- });
- };
+ return true;
+});
- const showGenerateTenant = computed(() => {
- // True when a tenant project is selected and "MULTI_DB" is selected.
- if (isTenantProject.value && state.alterType === "MULTI_DB") {
- return true;
- }
- return false;
- });
+const generateTenant = async () => {
+ if (!hasFeature("bb.feature.multi-tenancy")) {
+ state.showFeatureModal = true;
+ return;
+ }
- const allowGenerateTenant = computed(() => {
- // All databases will be in the same group if dbNameTemplate is empty.
- if (isTenantProject.value && state.project?.dbNameTemplate === "")
- return true;
- if (!state.selectedDatabaseName) return false;
+ emit("dismiss");
- // not allowed when database list filtered by deployment config is empty
- // which means no database will be deployed
- if (state.deployingTenantDatabaseList.length === 0) return false;
+ const projectId = props.projectId || state.tenantProjectId;
+ if (!projectId) return;
- return true;
- });
+ const project = projectStore.getProjectById(projectId) as Project;
- const generateTenant = async () => {
- if (!hasFeature("bb.feature.multi-tenancy")) {
- state.showFeatureModal = true;
- return;
- }
+ if (project.id === UNKNOWN_ID) return;
- emit("dismiss");
-
- const projectId = props.projectId || state.tenantProjectId;
- if (!projectId) return;
-
- const project = projectStore.getProjectById(projectId) as Project;
-
- if (project.id === UNKNOWN_ID) return;
-
- if (project.workflowType === "UI") {
- router.push({
- name: "workspace.issue.detail",
- params: {
- issueSlug: "new",
- },
- query: {
- template: props.type,
- name: generateIssueName([state.selectedDatabaseName!], false),
- project: project.id,
- databaseName: state.selectedDatabaseName,
- mode: "tenant",
- },
- });
- } else if (project.workflowType === "VCS") {
- repositoryStore
- .fetchRepositoryByProjectId(project.id)
- .then((repository: Repository) => {
- window.open(
- baseDirectoryWebUrl(repository, {
- DB_NAME: state.selectedDatabaseName!,
- TYPE:
- props.type === "bb.issue.database.schema.update"
- ? "ddl"
- : "dml",
- }),
- "_blank"
- );
- });
- }
+ if (project.workflowType === "UI") {
+ const query: Record<string, any> = {
+ template: props.type,
+ project: project.id,
+ mode: "tenant",
};
-
- const selectDatabase = async (database: Database) => {
- if (database.project.workflowType == "UI") {
- const mode = await isUsingGhostMigration([database]);
- if (mode === false) {
- return;
- }
- emit("dismiss");
-
- const query: Record<string, any> = {
- template: props.type,
- name: generateIssueName([database.name], mode === "online"),
- project: database.project.id,
- databaseList: database.id,
- };
- if (mode === "online") {
- query.ghost = "1";
- }
- router.push({
- name: "workspace.issue.detail",
- params: {
- issueSlug: "new",
- },
- query,
- });
- } else if (database.project.workflowType == "VCS") {
- repositoryStore
- .fetchRepositoryByProjectId(database.project.id)
- .then((repository: Repository) => {
- window.open(
- baseDirectoryWebUrl(repository, {
- DB_NAME: database.name,
- ENV_NAME: database.instance.environment.name,
- TYPE:
- props.type === "bb.issue.database.schema.update"
- ? "ddl"
- : "dml",
- }),
- "_blank"
- );
- });
- emit("dismiss");
+ if (state.alterType === "DB_GROUP") {
+ query.name = generateIssueName([state.selectedDatabaseName!], false);
+ query.databaseName = state.selectedDatabaseName;
+ } else {
+ const databaseList: Database[] = [];
+ const databaseStore = useDatabaseStore();
+ for (const databaseId of state.selectedDatabaseIdList) {
+ databaseList.push(databaseStore.getDatabaseById(databaseId));
}
- };
-
- const cancel = () => {
- emit("dismiss");
- };
+ query.name = generateIssueName(
+ databaseList.map((database) => database.name),
+ false
+ );
+ query.databaseList = Array.from(state.selectedDatabaseIdList).join(",");
+ }
- const generateIssueName = (
- databaseNameList: string[],
- isOnlineMode: boolean
- ) => {
- // Create a user friendly default issue name
- const issueNameParts: string[] = [];
- if (databaseNameList.length === 1) {
- issueNameParts.push(`[${databaseNameList[0]}]`);
- } else {
- issueNameParts.push(`[${databaseNameList.length} databases]`);
- }
- if (isOnlineMode) {
- issueNameParts.push("Online schema change");
- } else {
- issueNameParts.push(
- isAlterSchema.value ? `Alter schema` : `Change data`
+ router.push({
+ name: "workspace.issue.detail",
+ params: {
+ issueSlug: "new",
+ },
+ query,
+ });
+ } else if (project.workflowType === "VCS") {
+ repositoryStore
+ .fetchRepositoryByProjectId(project.id)
+ .then((repository: Repository) => {
+ window.open(
+ baseDirectoryWebUrl(repository, {
+ DB_NAME: state.selectedDatabaseName!,
+ TYPE:
+ props.type === "bb.issue.database.schema.update" ? "ddl" : "dml",
+ }),
+ "_blank"
);
- }
- const datetime = dayjs().format("@MM-DD HH:mm");
- const tz = "UTC" + dayjs().format("ZZ");
- issueNameParts.push(`${datetime} ${tz}`);
-
- return issueNameParts.join(" ");
- };
+ });
+ }
+};
+
+const selectDatabase = async (database: Database) => {
+ if (database.project.workflowType == "UI") {
+ const mode = await isUsingGhostMigration([database]);
+ if (mode === false) {
+ return;
+ }
+ emit("dismiss");
- return {
- state,
- ghostDialog,
- isAlterSchema,
- isTenantProject,
- environmentList,
- databaseList,
- showGenerateMultiDb,
- allowGenerateMultiDb,
- flattenSelectedDatabaseIdList,
- generateMultiDb,
- showGenerateTenant,
- allowGenerateTenant,
- generateTenant,
- selectDatabase,
- cancel,
+ const query: Record<string, any> = {
+ template: props.type,
+ name: generateIssueName([database.name], mode === "online"),
+ project: database.project.id,
+ databaseList: database.id,
};
- },
-});
+ if (mode === "online") {
+ query.ghost = "1";
+ }
+ router.push({
+ name: "workspace.issue.detail",
+ params: {
+ issueSlug: "new",
+ },
+ query,
+ });
+ } else if (database.project.workflowType == "VCS") {
+ repositoryStore
+ .fetchRepositoryByProjectId(database.project.id)
+ .then((repository: Repository) => {
+ window.open(
+ baseDirectoryWebUrl(repository, {
+ DB_NAME: database.name,
+ ENV_NAME: database.instance.environment.name,
+ TYPE:
+ props.type === "bb.issue.database.schema.update" ? "ddl" : "dml",
+ }),
+ "_blank"
+ );
+ });
+ emit("dismiss");
+ }
+};
+
+const cancel = () => {
+ emit("dismiss");
+};
+
+const generateIssueName = (
+ databaseNameList: string[],
+ isOnlineMode: boolean
+) => {
+ // Create a user friendly default issue name
+ const issueNameParts: string[] = [];
+ if (databaseNameList.length === 1) {
+ issueNameParts.push(`[${databaseNameList[0]}]`);
+ } else {
+ issueNameParts.push(`[${databaseNameList.length} databases]`);
+ }
+ if (isOnlineMode) {
+ issueNameParts.push("Online schema change");
+ } else {
+ issueNameParts.push(isAlterSchema.value ? `Alter schema` : `Change data`);
+ }
+ const datetime = dayjs().format("@MM-DD HH:mm");
+ const tz = "UTC" + dayjs().format("ZZ");
+ issueNameParts.push(`${datetime} ${tz}`);
+
+ return issueNameParts.join(" ");
+};
</script>
diff --git a/frontend/src/components/AlterSchemaPrepForm/ProjectStandardView.vue b/frontend/src/components/AlterSchemaPrepForm/ProjectStandardView.vue
index ced4ae6346..91a64b41f6 100644
--- a/frontend/src/components/AlterSchemaPrepForm/ProjectStandardView.vue
+++ b/frontend/src/components/AlterSchemaPrepForm/ProjectStandardView.vue
@@ -117,7 +117,7 @@ import {
Project,
} from "../../types";
-export type AlterType = "SINGLE_DB" | "MULTI_DB";
+export type AlterType = "SINGLE_DB" | "MULTI_DB" | "DB_GROUP";
export type State = {
alterType: AlterType;
diff --git a/frontend/src/components/TransferDatabaseForm/TransferMultipleDatabaseForm.vue b/frontend/src/components/TransferDatabaseForm/TransferMultipleDatabaseForm.vue
index da61754719..40fff681dc 100644
--- a/frontend/src/components/TransferDatabaseForm/TransferMultipleDatabaseForm.vue
+++ b/frontend/src/components/TransferDatabaseForm/TransferMultipleDatabaseForm.vue
@@ -9,7 +9,7 @@
:database-list="databaseList"
:show-selection-column="true"
@select-database="
- (db) => toggleDatabaseSelection(db, !isDatabaseSelected(db))
+ (db: Database) => toggleDatabaseSelection(db, !isDatabaseSelected(db))
"
>
<template #selection-all="{ databaseList: renderedDatabaseList }">
@@ -26,7 +26,6 @@
"
/>
</template>
-
<template #selection="{ database }">
<input
type="checkbox"
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index eef17e9436..daa42bfd66 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -523,8 +523,9 @@
"vcs-enabled": "This project has enabled VCS based version control and selecting database below will navigate you to the corresponding Git repository to initiate the change process.",
"vcs-info": "VCS enabled. Selecting this will navigate you to the corresponding Git repository to initiate the change process.",
"alter-single-db": "Alter single database",
- "alter-multiple-db": "Alter multiple databases",
- "alter-multiple-db-info": "For each environment, you can select multiple databases to alter their schemas or just skip that environment. This allows you to compose a single pipeline to propagate changes across multiple environments."
+ "alter-multiple-db": "Manual Selection",
+ "alter-multiple-db-info": "For each environment, you can select multiple databases to alter their schemas or just skip that environment. This allows you to compose a single pipeline to propagate changes across multiple environments.",
+ "alter-db-group": "By Deployment Config"
},
"quick-action": {
"create-db": "Create database",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index e0841b96e9..a8512b7505 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -523,8 +523,9 @@
"vcs-enabled": "该项目开启了基于 VCS 的版本管理,选择下面的数据库会将您导航到相应的 Git 仓库以发起变更流程。",
"vcs-info": "已开启 VCS 版本管理。选择该数据库会跳转到对应的 Git 仓库以发起变更流程。",
"alter-single-db": "变更单个数据库",
- "alter-multiple-db": "变更多个数据库",
- "alter-multiple-db-info": "针对每个环境,您可以选择多个数据库进行变更或者直接跳过该环境,这样您就可以在一条流水线上把变更逐步作用到多个环境。"
+ "alter-multiple-db": "手动选择数据库",
+ "alter-multiple-db-info": "针对每个环境,您可以选择多个数据库进行变更或者直接跳过该环境,这样您就可以在一条流水线上把变更逐步作用到多个环境。",
+ "alter-db-group": "按部署的配置"
},
"quick-action": {
"create-db": "创建数据库",
diff --git a/frontend/src/plugins/issue/logic/initialize/tenant.ts b/frontend/src/plugins/issue/logic/initialize/tenant.ts
index cb6944f75f..2ad2e75815 100644
--- a/frontend/src/plugins/issue/logic/initialize/tenant.ts
+++ b/frontend/src/plugins/issue/logic/initialize/tenant.ts
@@ -9,6 +9,7 @@ import {
findProject,
BuildNewIssueContext,
VALIDATE_ONLY_SQL,
+ findDatabaseListByQuery,
} from "../common";
import { IssueCreateHelper } from "./helper";
@@ -47,15 +48,30 @@ const buildNewTenantSchemaUpdateIssue = async (
if (templateType === "bb.issue.database.data.update") {
migrationType = "DATA";
}
- helper.issueCreate!.createContext = {
- detailList: [
- {
- migrationType: migrationType,
- databaseName: route.query.databaseName,
- statement: VALIDATE_ONLY_SQL,
- },
- ],
- };
+
+ const databaseList = findDatabaseListByQuery(context);
+ if (databaseList.length !== 0) {
+ helper.issueCreate!.createContext = {
+ detailList: databaseList.map((db) => {
+ return {
+ migrationType: migrationType,
+ databaseId: db.id,
+ databaseName: "",
+ statement: VALIDATE_ONLY_SQL,
+ };
+ }),
+ };
+ } else {
+ helper.issueCreate!.createContext = {
+ detailList: [
+ {
+ migrationType: migrationType,
+ databaseName: route.query.databaseName,
+ statement: VALIDATE_ONLY_SQL,
+ },
+ ],
+ };
+ }
await helper.validate();
// we are setting SQL statement to "" because showing /* YOUR_SQL_HERE */
@@ -63,7 +79,9 @@ const buildNewTenantSchemaUpdateIssue = async (
// setting it to empty can provide a placeholder to user, along with an
// exclamation mark indicating "No SQL statement"
const createContext = helper.issueCreate!.createContext as MigrationContext;
- createContext.detailList[0].statement = "";
+ for (const detail of createContext.detailList) {
+ detail.statement = "";
+ }
return helper.generate();
};