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: support select multiply databases for data change & alter schema (#8571)
ecmadaoe9d46ad8d5fa
diff --git a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vueindex 9c2acea8ab..bb978c1240 100644--- a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue+++ b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue@@ -6,7 +6,7 @@isEditSchema ? $t("database.edit-schema") : $t("database.change-data")}}</span><i18n-t- v-if="projectId && isTenantProject"+ v-if="isTenantProject"class="text-sm textinfolabel"tag="span"keypath="deployment-config.pipeline-generated-from-deployment-config"@@ -83,7 +83,7 @@:show-selection-column="true"@select-database="(db: ComposedDatabase) =>- toggleDatabaseSelection(db, !isDatabaseSelected(db))+ toggleDatabasesSelection([db as ComposedDatabase], !isDatabaseSelected(db))"><template@@ -95,7 +95,7 @@class="h-4 w-4 text-accent rounded disabled:cursor-not-allowed border-control-border focus:ring-accent"v-bind="getAllSelectionState(renderedDatabaseList as ComposedDatabase[])"@input="- toggleAllDatabasesSelection(+ toggleDatabasesSelection(renderedDatabaseList as ComposedDatabase[],($event.target as HTMLInputElement).checked)@@ -106,8 +106,13 @@<inputtype="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)"+ :checked="isDatabaseSelected(database as ComposedDatabase)"+ @input="+ toggleDatabasesSelection(+ [database as ComposedDatabase],+ ($event.target as HTMLInputElement).checked+ )+ "/></template></DatabaseV1Table>@@ -174,26 +179,32 @@</template><template v-else><div class="w-full flex flex-row justify-between items-center mb-2">- <div class="px-1 space-x-2">- <NRadio- :checked="state.databaseSelectedTab === 'DATABASE'"- value="DATABASE"- name="database-tab"- @update:checked="state.databaseSelectedTab = 'DATABASE'"- >- {{ $t("common.database") }}- </NRadio>- <NRadio- :checked="state.databaseSelectedTab === 'DATABASE_GROUP'"- value="DATABASE_GROUP"- name="database-tab"- @update:checked="handleDatabaseGroupTabSelect"- >- <div class="flex flex-row items-center">- <span class="mr-1">{{ $t("database-group.self") }}</span>- <FeatureBadge feature="bb.feature.database-grouping" />- </div>- </NRadio>+ <div class="flex items-center space-x-3">+ <ProjectSelect+ :project="state.project?.uid ?? String(UNKNOWN_ID)"+ @update:project="selectProject"+ />+ <div class="px-1 space-x-2">+ <NRadio+ :checked="state.databaseSelectedTab === 'DATABASE'"+ value="DATABASE"+ name="database-tab"+ @update:checked="state.databaseSelectedTab = 'DATABASE'"+ >+ {{ $t("common.database") }}+ </NRadio>+ <NRadio+ :checked="state.databaseSelectedTab === 'DATABASE_GROUP'"+ value="DATABASE_GROUP"+ name="database-tab"+ @update:checked="handleDatabaseGroupTabSelect"+ >+ <div class="flex flex-row items-center">+ <span class="mr-1">{{ $t("database-group.self") }}</span>+ <FeatureBadge feature="bb.feature.database-grouping" />+ </div>+ </NRadio>+ </div></div><aside class="flex justify-end"><BBTableSearch@@ -210,8 +221,40 @@table-class="border":custom-click="true":database-list="schemaDatabaseList"- @select-database="selectDatabase"- />+ :show-selection-column="true"+ @select-database="+ (db: ComposedDatabase) =>+ toggleDatabasesSelection([db as ComposedDatabase], !isDatabaseSelected(db))+ "+ >+ <template #selection-all="{ databaseList: selectedDatabaseList }">+ <input+ v-if="selectedDatabaseList.length > 0"+ type="checkbox"+ class="h-4 w-4 text-accent rounded disabled:cursor-not-allowed border-control-border focus:ring-accent"+ v-bind="getAllSelectionState(selectedDatabaseList as ComposedDatabase[])"+ @input="+ toggleDatabasesSelection(+ selectedDatabaseList as ComposedDatabase[],+ ($event.target as HTMLInputElement).checked+ )+ "+ />+ </template>+ <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 as ComposedDatabase)"+ @click.stop="+ toggleDatabasesSelection(+ [database as ComposedDatabase],+ ($event.target as HTMLInputElement).checked+ )+ "+ />+ </template>+ </DatabaseV1Table><SchemalessDatabaseTablev-if="isEditSchema"mode="ALL"@@ -236,11 +279,14 @@</div><!-- Only show footer in project mode -->- <template v-if="projectId" #footer>+ <template #footer><div class="flex-1 flex items-center justify-between"><div><div- v-if="flattenSelectedDatabaseUidList.length > 0"+ v-if="+ flattenSelectedDatabaseUidList.length > 0 &&+ state.alterType === 'MULTI_DB'+ "class="textinfolabel">{{@@ -255,14 +301,23 @@<NButton @click.prevent="cancel">{{ $t("common.cancel") }}</NButton>- <NButton+ <NTooltipv-if="showGenerateMultiDb"- type="primary"- :disabled="!allowGenerateMultiDb"- @click.prevent="generateMultiDb"+ :disabled="flattenSelectedProjectSet.size <= 1">- {{ $t("common.next") }}- </NButton>+ <template #trigger>+ <NButton+ type="primary"+ :disabled="!allowGenerateMultiDb"+ @click.prevent="generateMultiDb"+ >+ {{ $t("common.next") }}+ </NButton>+ </template>+ <span class="w-56 text-sm">+ {{ $t("database.select-databases-from-same-project") }}+ </span>+ </NTooltip><NButtonv-if="showGenerateTenant"type="primary"@@ -277,7 +332,7 @@</DrawerContent><FeatureModal- :open="featureModalContext.feature"+ :open="!!featureModalContext.feature":feature="featureModalContext.feature"@cancel="featureModalContext.feature = undefined"/>@@ -300,10 +355,8 @@</template><script lang="ts" setup>-import dayjs from "dayjs";-import { cloneDeep } from "lodash-es";import { NButton, NTabs, NTabPane, NRadio } from "naive-ui";-import { computed, reactive, PropType, ref } from "vue";+import { computed, reactive, PropType, ref, watch } from "vue";import { watchEffect } from "vue";import { useRouter } from "vue-router";import {@@ -331,9 +384,10 @@ import {filterDatabaseV1ByKeyword,sortDatabaseV1List,projectV1Slug,+ generateIssueName,} from "@/utils";import SelectDatabaseGroupTable from "../DatabaseGroup/SelectDatabaseGroupTable.vue";-import { DatabaseV1Table, DrawerContent } from "../v2";+import { DatabaseV1Table, DrawerContent, ProjectSelect } from "../v2";import DatabaseGroupPrevEditorModal from "./DatabaseGroupPrevEditorModal.vue";import GhostDialog from "./GhostDialog.vue";import ProjectStandardView, {@@ -405,13 +459,27 @@ const state = reactive<LocalState>({showSchemaEditorModal: false,});+const selectProject = (projectId: string | undefined) => {+ state.project = projectId+ ? projectV1Store.getProjectByUID(projectId)+ : undefined;+};++watch(+ () => props.projectId,+ (projectId) => selectProject(projectId)+);+// Returns true if alter schema, false if change data.const isEditSchema = computed((): boolean => {return props.type === "bb.issue.database.schema.update";});const isTenantProject = computed((): boolean => {- return state.project?.tenantMode === TenantMode.TENANT_MODE_ENABLED;+ return (+ !!props.projectId &&+ state.project?.tenantMode === TenantMode.TENANT_MODE_ENABLED+ );});if (isTenantProject.value) {@@ -447,9 +515,8 @@ watchEffect(async () => {const databaseList = computed(() => {let list: ComposedDatabase[] = [];- if (props.projectId) {- const project = projectV1Store.getProjectByUID(props.projectId);- list = databaseV1Store.databaseListByProject(project.name);+ if (state.project) {+ list = databaseV1Store.databaseListByProject(state.project.name);} else {list = databaseV1Store.databaseListByUser(currentUserV1.value);}@@ -496,18 +563,33 @@ const databaseGroupList = computed(() => {const flattenSelectedDatabaseUidList = computed(() => {const flattenDatabaseIdList: string[] = [];- if (isTenantProject.value && state.alterType === "MULTI_DB") {+ if (!props.projectId) {for (const db of state.selectedDatabaseIdListForTenantMode) {flattenDatabaseIdList.push(db);}} else {- for (const databaseIdList of state.selectedDatabaseUidListForEnvironment.values()) {- flattenDatabaseIdList.push(...databaseIdList);+ if (isTenantProject.value && state.alterType === "MULTI_DB") {+ for (const db of state.selectedDatabaseIdListForTenantMode) {+ flattenDatabaseIdList.push(db);+ }+ } else {+ for (const databaseIdList of state.selectedDatabaseUidListForEnvironment.values()) {+ flattenDatabaseIdList.push(...databaseIdList);+ }}}return flattenDatabaseIdList;});+const flattenSelectedProjectSet = computed(() => {+ const projectSet: Set<string> = new Set();+ for (const uid of flattenSelectedDatabaseUidList.value) {+ const database = databaseV1Store.getDatabaseByUID(uid);+ projectSet.add(database.projectEntity.uid);+ }+ return projectSet;+});+const showGenerateMultiDb = computed(() => {if (isTenantProject.value) return false;return state.alterType === "MULTI_DB";@@ -515,7 +597,10 @@ const showGenerateMultiDb = computed(() => {const allowGenerateMultiDb = computed(() => {if (state.databaseSelectedTab === "DATABASE") {- return flattenSelectedDatabaseUidList.value.length > 0;+ return (+ flattenSelectedProjectSet.value.size === 1 &&+ flattenSelectedDatabaseUidList.value.length > 0+ );} else {return state.selectedDatabaseGroupName;}@@ -566,15 +651,14 @@ const generateMultiDb = async () => {return;}- const selectedDatabaseIdList = [...flattenSelectedDatabaseUidList.value];- const selectedDatabaseList = selectedDatabaseIdList.map(+ const selectedDatabaseList = flattenSelectedDatabaseUidList.value.map((id) => schemaDatabaseList.value.find((db) => db.uid === id)!);if (isEditSchema.value && allowUsingSchemaEditorV1(selectedDatabaseList)) {- schemaEditorContext.value.databaseIdList = cloneDeep(- flattenSelectedDatabaseUidList.value- );+ schemaEditorContext.value.databaseIdList = [+ ...flattenSelectedDatabaseUidList.value,+ ];state.showSchemaEditorModal = true;return;}@@ -584,16 +668,21 @@ const generateMultiDb = async () => {return;}+ if (flattenSelectedProjectSet.value.size !== 1) {+ return;+ }+const query: Record<string, any> = {template: props.type,name: generateIssueName(+ props.type,selectedDatabaseList.map((db) => db.databaseName),mode === "online"),- project: props.projectId,+ project: [...flattenSelectedProjectSet.value][0],// The server-side will sort the databases by environment.// So we need not to sort them here.- databaseList: selectedDatabaseIdList.join(","),+ databaseList: flattenSelectedDatabaseUidList.value.join(","),};if (mode === "online") {query.ghost = "1";@@ -649,18 +738,17 @@ const getAllSelectionState = (};};-const toggleAllDatabasesSelection = (+const toggleDatabasesSelection = (databaseList: ComposedDatabase[],on: boolean): void => {- const set = state.selectedDatabaseIdListForTenantMode;if (on) {databaseList.forEach((db) => {- set.add(db.uid);+ state.selectedDatabaseIdListForTenantMode.add(db.uid);});} else {databaseList.forEach((db) => {- set.delete(db.uid);+ state.selectedDatabaseIdListForTenantMode.delete(db.uid);});}};@@ -683,14 +771,6 @@ const isDatabaseSelected = (database: ComposedDatabase): boolean => {return state.selectedDatabaseIdListForTenantMode.has(database.uid);};-const toggleDatabaseSelection = (database: ComposedDatabase, on: boolean) => {- if (on) {- state.selectedDatabaseIdListForTenantMode.add(database.uid);- } else {- state.selectedDatabaseIdListForTenantMode.delete(database.uid);- }-};-const handleDatabaseGroupTabSelect = () => {if (!hasFeature("bb.feature.database-grouping")) {state.databaseSelectedTab = "DATABASE";@@ -717,19 +797,18 @@ const generateTenant = async () => {return;}- const projectId = props.projectId;- if (!projectId) return;-- const project = projectV1Store.getProjectByUID(projectId);- if (project.uid === String(UNKNOWN_ID)) return;+ if (!state.project) return;+ if (state.project.uid === String(UNKNOWN_ID)) return;const query: Record<string, any> = {template: props.type,- project: project.uid,+ project: state.project.uid,mode: "tenant",};if (state.alterType === "TENANT") {- const databaseList = databaseV1Store.databaseListByProject(project.name);+ const databaseList = databaseV1Store.databaseListByProject(+ state.project.name+ );if (isEditSchema.value && allowUsingSchemaEditorV1(databaseList)) {schemaEditorContext.value.databaseIdList = databaseList.filter((database) => database.syncState === State.ACTIVE)@@ -740,8 +819,10 @@ const generateTenant = async () => {// In tenant deploy pipeline, we use project name instead of database name// if more than one databases are to be deployed.const name =- databaseList.length > 1 ? project.title : databaseList[0].databaseName;- query.name = generateIssueName([name], false);+ databaseList.length > 1+ ? state.project.title+ : databaseList[0].databaseName;+ query.name = generateIssueName(props.type, [name], false);query.databaseName = "";} else {const databaseList: ComposedDatabase[] = [];@@ -760,6 +841,7 @@ const generateTenant = async () => {}query.name = generateIssueName(+ props.type,databaseList.map((database) => database.databaseName),false);@@ -798,7 +880,11 @@ const selectDatabase = async (database: ComposedDatabase) => {const query: Record<string, any> = {template: props.type,- name: generateIssueName([database.databaseName], mode === "online"),+ name: generateIssueName(+ props.type,+ [database.databaseName],+ mode === "online"+ ),project: database.projectEntity.uid,databaseList: database.uid,};@@ -817,27 +903,4 @@ const selectDatabase = async (database: ComposedDatabase) => {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(isEditSchema.value ? `Edit 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.vueindex 10ff84640c..028101fdf0 100644--- a/frontend/src/components/AlterSchemaPrepForm/ProjectStandardView.vue+++ b/frontend/src/components/AlterSchemaPrepForm/ProjectStandardView.vue@@ -112,7 +112,7 @@<template v-else><!-- single stage view --><slot name="header"></slot>- <DatabaseTable+ <DatabaseV1Tablemode="PROJECT_SHORT"table-class="border":custom-click="true"diff --git a/frontend/src/components/DatabaseTable.vue b/frontend/src/components/DatabaseTable.vuedeleted file mode 100644index 2ce32cdbf5..0000000000--- a/frontend/src/components/DatabaseTable.vue+++ /dev/null@@ -1,522 +0,0 @@-<template>- <div ref="wrapper" rule="database-table" v-bind="$attrs">- <BBGrid- :column-list="columnList"- :data-source="pagedDataSource"- :custom-header="true"- :class="tableClass"- :row-clickable="rowClickable"- @click-row="clickDatabase"- >- <template #header>- <div role="table-row" class="bb-grid-row bb-grid-header-row group">- <div- v-for="(column, index) in columnList"- :key="index"- role="table-cell"- class="bb-grid-header-cell capitalize"- :class="[column.class]"- >- <template v-if="showSelectionColumn && index === 0">- <slot name="selection-all" :database-list="mixedDatabaseList" />- </template>- <template v-else>{{ column.title }}</template>- </div>- </div>- </template>-- <template #item="{ item: database }: { item: Database }">- <div v-if="showSelectionColumn" class="bb-grid-cell !px-2">- <slot name="selection" :database="database" />- </div>- <div class="bb-grid-cell">- <div class="flex items-center space-x-2">- <SQLEditorButton- :database="database"- :disabled="!allowQuery(database)"- :tooltip="true"- @failed="handleGotoSQLEditorFailed"- />- <DatabaseName :database="database" tag="span" />- <BBBadge- v-if="isPITRDatabase(database)"- text="PITR"- :can-remove="false"- class="text-xs"- />- <NTooltip- v-if="!showMiscColumn && database.syncStatus != 'OK'"- placement="right"- >- <template #trigger>- <heroicons-outline:exclamation-circle- class="w-5 h-5 text-error"- />- </template>-- <div class="whitespace-nowrap">- {{- $t("database.last-sync-status-long", [- database.syncStatus,- humanizeTs(database.lastSuccessfulSyncTs),- ])- }}- </div>- </NTooltip>- </div>- </div>- <div v-if="showSchemaVersionColumn" class="hidden lg:bb-grid-cell">- {{ database.schemaVersion }}- </div>- <div v-if="showProjectColumn" class="bb-grid-cell">- <div class="flex flex-row space-x-2 items-center">- <div>{{ projectName(database.project) }}</div>- <div- v-if="showTenantIcon && database.project.tenantMode === 'TENANT'"- class="tooltip-wrapper"- >- <span class="tooltip whitespace-nowrap">- {{ $t("project.mode.batch") }}- </span>- <TenantIcon class="text-control" />- </div>- <div class="tooltip-wrapper">- <svg- v-if="database.project.workflowType == 'UI'"- class="w-4 h-4"- fill="none"- stroke="currentColor"- viewBox="0 0 24 24"- xmlns="http://www.w3.org/2000/svg"- ></svg>- <template v-else-if="database.project.workflowType == 'VCS'">- <span v-if="mode === 'ALL_SHORT'" class="tooltip w-40">- {{ $t("alter-schema.vcs-info") }}- </span>- <span v-else class="tooltip whitespace-nowrap">- {{ $t("database.gitops-enabled") }}- </span>-- <GitIcon- class="w-4 h-4 text-control hover:text-control-hover"- />- </template>- </div>- </div>- </div>- <div v-if="showEnvironmentColumn" class="bb-grid-cell">- <div class="flex items-center">- {{ environmentName(database.instance.environment) }}- <ProductionEnvironmentIcon- class="ml-1"- :environment="database.instance.environment"- />- </div>- </div>- <div v-if="showInstanceColumn" class="bb-grid-cell">- <div class="flex flex-row items-center space-x-1">- <InstanceEngineIcon :instance="database.instance" />- <span class="flex-1 whitespace-pre-wrap">- {{ instanceName(database.instance) }}- </span>- </div>- </div>- <div v-if="showMiscColumn" class="bb-grid-cell">- <div class="w-full flex justify-center">- <NTooltip placement="left">- <template #trigger>- <div- class="flex items-center justify-center rounded-full select-none w-5 h-5 overflow-hidden text-white font-medium text-base"- :class="- database.syncStatus === 'OK' ? 'bg-success' : 'bg-error'- "- >- <template v-if="database.syncStatus === 'OK'">- <heroicons-solid:check class="w-4 h-4" />- </template>- <template v-else>- <span- class="h-2 w-2 flex items-center justify-center"- aria-hidden="true"- >!</span- >- </template>- </div>- </template>-- <span>- <template v-if="database.syncStatus === 'OK'">- {{- $t("database.synced-at", {- time: humanizeTs(database.lastSuccessfulSyncTs),- })- }}- </template>- <template v-else>- {{- $t("database.not-found-last-successful-sync-was", {- time: humanizeTs(database.lastSuccessfulSyncTs),- })- }}- </template>- </span>- </NTooltip>- </div>- </div>- </template>-- <template #footer>- <div- v-if="hasReservedDatabases && !state.showReservedDatabaseList"- class="flex items-center justify-center cursor-pointer hover:bg-gray-200 py-2 text-gray-400 text-sm"- @click="showReservedDatabaseList()"- >- {{ $t("database.show-reserved-databases") }}- </div>- </template>- </BBGrid>- </div>-- <div- v-if="showPagination"- class="flex justify-end !mt-2"- :class="paginationClass"- >- <NPagination- :item-count="table.getCoreRowModel().rows.length"- :page="table.getState().pagination.pageIndex + 1"- :page-size="table.getState().pagination.pageSize"- :show-quick-jumper="true"- @update-page="handleChangePage"- @update-page-size="(ps) => table.setPageSize(ps)"- />- </div>-- <BBModal- v-if="state.showIncorrectProjectModal"- :title="$t('common.warning')"- @close="handleIncorrectProjectModalCancel"- >- <div class="col-span-1 w-96">- {{ $t("database.incorrect-project-warning") }}- </div>- <div class="pt-6 flex justify-end">- <button- type="button"- class="btn-normal py-2 px-4"- @click.prevent="handleIncorrectProjectModalCancel"- >- {{ $t("common.cancel") }}- </button>- <button- type="button"- class="btn-primary ml-3 inline-flex justify-center py-2 px-4"- @click.prevent="handleIncorrectProjectModalConfirm"- >- {{ $t("database.go-to-transfer") }}- </button>- </div>- </BBModal>-</template>--<script lang="ts" setup>-import {- ColumnDef,- getCoreRowModel,- getPaginationRowModel,- useVueTable,-} from "@tanstack/vue-table";-import cloneDeep from "lodash-es/cloneDeep";-import { NTooltip, NPagination } from "naive-ui";-import { computed, nextTick, PropType, reactive, ref, watch } from "vue";-import { useI18n } from "vue-i18n";-import { useRouter } from "vue-router";-import { SQLEditorButton } from "@/components/DatabaseDetail";-import DatabaseName from "@/components/DatabaseName.vue";-import { useCurrentUserIamPolicy, useDatabaseV1Store } from "@/store";-import { getScrollParent } from "@/utils";-import { BBGridColumn } from "../bbkit/types";-import { Database } from "../types";-import { databaseSlug, isPITRDatabase, VueClass } from "../utils";-import InstanceEngineIcon from "./InstanceEngineIcon.vue";-import TenantIcon from "./TenantIcon.vue";--type Mode =- | "ALL"- | "ALL_SHORT"- | "ALL_TINY"- | "INSTANCE"- | "PROJECT"- | "PROJECT_SHORT";--interface State {- showIncorrectProjectModal: boolean;- warningDatabase?: Database;- showReservedDatabaseList: boolean;-}--const props = defineProps({- bordered: {- default: true,- type: Boolean,- },- tableClass: {- type: [String, Array, Object] as PropType<VueClass>,- default: undefined,- },- paginationClass: {- type: [String, Array, Object] as PropType<VueClass>,- default: undefined,- },- mode: {- default: "ALL",- type: String as PropType<Mode>,- },- singleInstance: {- default: true,- type: Boolean,- },- showSelectionColumn: {- type: Boolean,- default: false,- },- rowClickable: {- default: true,- type: Boolean,- },- customClick: {- default: false,- type: Boolean,- },- databaseList: {- required: true,- type: Object as PropType<Database[]>,- },- pageSize: {- type: Number,- default: 20,- },- scrollOnPageChange: {- type: Boolean,- default: true,- },- schemaless: {- type: Boolean,- default: false,- },-});--const emit = defineEmits(["select-database"]);--const router = useRouter();-const currentUserIamPolicy = useCurrentUserIamPolicy();-const databaseV1Store = useDatabaseV1Store();-const { t } = useI18n();-const state = reactive<State>({- showIncorrectProjectModal: false,- showReservedDatabaseList: false,-});-const wrapper = ref<HTMLElement>();--const sortedDatabaseList = computed(() => {- const list = [...props.databaseList];- list.sort((a, b) => {- // Fallback to `id` DESC- return -(+a.id - +b.id);- });- return list;-});--const regularDatabaseList = computed(() =>- sortedDatabaseList.value.filter((db) => !isPITRDatabase(db))-);-const reservedDatabaseList = computed(() =>- sortedDatabaseList.value.filter((db) => isPITRDatabase(db))-);-const hasReservedDatabases = computed(- () => reservedDatabaseList.value.length > 0-);--const mixedDatabaseList = computed(() => {- const databaseList = [...regularDatabaseList.value];- if (state.showReservedDatabaseList) {- databaseList.push(...reservedDatabaseList.value);- }- return databaseList;-});--const columnListMap = computed(() => {- const NAME = {- title: t("common.name"),- width: "minmax(auto, 1.5fr)",- };- const SCHEMA_VERSION = props.schemaless- ? undefined- : {- title: t("common.schema-version"),- width: { lg: "minmax(auto, 1fr)" },- class: "hidden lg:flex",- };- const PROJECT = {- title: t("common.project"),- width: "minmax(auto, 1fr)",- };- const ENVIRONMENT = {- title: t("common.environment"),- width: "minmax(auto, 1fr)",- };- const INSTANCE = {- title: t("common.instance"),- width: "minmax(auto, 1fr)",- };- const SYNC_STATUS = {- title: t("database.sync-status"),- width: "auto",- class: "items-center",- };- return new Map<Mode, (BBGridColumn | undefined)[]>([- [- "ALL",- [NAME, SCHEMA_VERSION, PROJECT, ENVIRONMENT, INSTANCE, SYNC_STATUS],- ],- ["ALL_SHORT", [NAME, SCHEMA_VERSION, PROJECT, ENVIRONMENT, INSTANCE]],- ["ALL_TINY", [NAME, PROJECT, ENVIRONMENT, INSTANCE]],- ["INSTANCE", [NAME, SCHEMA_VERSION, PROJECT, SYNC_STATUS]],- ["PROJECT", [NAME, SCHEMA_VERSION, ENVIRONMENT, INSTANCE, SYNC_STATUS]],- ["PROJECT_SHORT", [NAME, SCHEMA_VERSION, ENVIRONMENT, INSTANCE]],- ]);-});--const showSchemaVersionColumn = computed(() => {- return props.mode !== "ALL_TINY" && !props.schemaless;-});--const showInstanceColumn = computed(() => {- return props.mode != "INSTANCE";-});--const showProjectColumn = computed(() => {- return props.mode != "PROJECT" && props.mode != "PROJECT_SHORT";-});--const showEnvironmentColumn = computed(() => {- return props.mode != "INSTANCE";-});--const showMiscColumn = computed(() => {- if (- props.mode === "ALL_SHORT" ||- props.mode === "ALL_TINY" ||- props.mode === "PROJECT_SHORT"- ) {- return false;- }- return true;-});--const columnList = computed(() => {- const list = cloneDeep(columnListMap.value.get(props.mode)!).filter(Boolean);- if (props.showSelectionColumn) {- list.unshift({- title: "",- width: "minmax(auto, 2rem)",- class: "items-center !px-2",- });- }- return list as BBGridColumn[];-});--const table = useVueTable<Database>({- get data() {- return mixedDatabaseList.value;- },- get columns() {- return columnList.value.map<ColumnDef<Database>>((col, index) => ({- header: col.title!,- }));- },- getCoreRowModel: getCoreRowModel(),- getPaginationRowModel: getPaginationRowModel(),-});--const pagedDataSource = computed(() => {- return table.getRowModel().rows.map((row) => row.original);-});--const showPagination = computed(() => {- return mixedDatabaseList.value.length > props.pageSize;-});--const handleChangePage = (page: number) => {- table.setPageIndex(page - 1);- if (props.scrollOnPageChange && wrapper.value) {- const parent = getScrollParent(wrapper.value);- parent.scrollTo(0, 0);- }-};-watch(- () => props.pageSize,- (ps) => {- table.setPageSize(ps);- },- { immediate: true }-);--const showReservedDatabaseList = () => {- const count = regularDatabaseList.value.length;- const pageCount = table.getPageCount();- const targetPage =- count === pageCount * props.pageSize ? pageCount + 1 : pageCount;- state.showReservedDatabaseList = true;- nextTick(() => {- handleChangePage(targetPage);- });-};--const allowQuery = (database: Database) => {- const composedDatabase = databaseV1Store.getDatabaseByUID(- String(database.id)- );- return currentUserIamPolicy.allowToQueryDatabaseV1(composedDatabase);-};--const showTenantIcon = computed(() => {- return ["ALL", "ALL_SHORT", "INSTANCE"].includes(props.mode);-});--const handleGotoSQLEditorFailed = (database: Database) => {- state.warningDatabase = database;- state.showIncorrectProjectModal = true;-};--const handleIncorrectProjectModalConfirm = () => {- if (state.warningDatabase) {- router.push(`/db/${databaseSlug(state.warningDatabase)}`);- }-};--const handleIncorrectProjectModalCancel = () => {- state.showIncorrectProjectModal = false;- state.warningDatabase = undefined;-};--const clickDatabase = (- database: Database,- section: number,- row: number,- e: MouseEvent-) => {- if (!props.rowClickable) return;-- if (props.customClick) {- emit("select-database", database);- } else {- const url = `/db/${databaseSlug(database)}`;- if (e.ctrlKey || e.metaKey) {- window.open(url, "_blank");- } else {- router.push(url);- }- }-};-</script>diff --git a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vueindex c6020648ca..434ca2cb2e 100644--- a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue+++ b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue@@ -135,7 +135,7 @@</div><FeatureModal- v-if="state.showFeatureModal"+ :open="state.showFeatureModal"feature="bb.feature.sql-review"@cancel="state.showFeatureModal = false"/>diff --git a/frontend/src/components/QuickActionPanel.vue b/frontend/src/components/QuickActionPanel.vueindex 7457fde564..fb3304422f 100644--- a/frontend/src/components/QuickActionPanel.vue+++ b/frontend/src/components/QuickActionPanel.vue@@ -272,8 +272,8 @@/><FeatureModal- :open="state.showFeatureModal && state.feature"- :feature="state.feature"+ :open="state.showFeatureModal && !!state.feature"+ :feature="(state.feature as FeatureType)"@cancel="state.showFeatureModal = false"/></template>@@ -299,7 +299,7 @@ import {useProjectV1ListByCurrentUser,useSubscriptionV1Store,} from "@/store";-import { QuickActionType } from "@/types";+import { QuickActionType, FeatureType } from "@/types";import { idFromSlug } from "@/utils";interface LocalState {diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex cab5da4a00..47d2c78e46 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -206,6 +206,7 @@"pitr": "PITR","fix": "Fix","go-now": "Go now",+ "sync": "Sync","sync-now": "Sync Now","show-help": "Show help","success": "Succeed",@@ -1334,6 +1335,7 @@"select-branch": "Select a branch","delete-this-branch": "Delete this branch","table-detail": "Table detail",+ "batch-action-disabled": "Can not {action} for the databases from different projects","successfully-transferred-updateddatabase-name-to-project-updateddatabase-project-name": "Successfully transferred '{0}' to project '{1}'.","backup-name": "Backup name","create-backup": "Create backup",@@ -1430,6 +1432,7 @@"unassigned-databases": "Unassigned databases","restore-database": "Restore database","selected-n-databases": "{n} database selected | {n} databases selected",+ "select-databases-from-same-project": "Please select databases from the same project","sync-schema": {"title": "Sync Schema","description": "Bytebase supports synchronizing a schema to one or multiple target databases.",diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex afb1107fe5..9864146328 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -206,6 +206,7 @@"pitr": "PITR","fix": "Corregir","go-now": "Ir ahora",+ "sync": "Sincronizar","sync-now": "Sincronizar ahora","show-help": "Mostrar ayuda","success": "Éxito",@@ -1333,6 +1334,7 @@"select-branch": "Seleccione una rama","delete-this-branch": "Eliminar esta rama","table-detail": "Detalle de la tabla",+ "batch-action-disabled": "No se puede {action} para las bases de datos de diferentes proyectos","successfully-transferred-updateddatabase-name-to-project-updateddatabase-project-name": "Se transfirió correctamente '{0}' al proyecto '{1}'.","backup-name": "Nombre de la copia de seguridad","create-backup": "Crear copia de seguridad",@@ -1429,6 +1431,7 @@"unassigned-databases": "Bases de datos no asignadas","restore-database": "Restaurar base de datos","selected-n-databases": "{n} base de datos seleccionada | {n} bases de datos seleccionadas",+ "select-databases-from-same-project": "Por favor seleccione bases de datos del mismo proyecto","sync-schema": {"title": "Sincronizar esquema","description": "Bytebase admite la sincronización de un esquema con una o varias bases de datos de destino",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 36c2045e90..358cd3aff7 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -206,6 +206,7 @@"pitr": "PITR","fix": "修复","go-now": "立即前往",+ "sync": "同步","sync-now": "现在同步","show-help": "查看帮助","success": "成功",@@ -1330,6 +1331,7 @@"select-branch": "选择一个分支","delete-this-branch": "删除这个分支","table-detail": "表详情",+ "batch-action-disabled": "无法对来自不同项目的数据库{action}","successfully-transferred-updateddatabase-name-to-project-updateddatabase-project-name": "成功将'{0}'转移到项目'{1}'。","database-backup": "数据库备份","backup-name": "备份名称",@@ -1427,6 +1429,7 @@"unassigned-databases": "未分配的数据库","restore-database": "恢复数据库","selected-n-databases": "已选择 {n} 个数据库",+ "select-databases-from-same-project": "请选择同一个项目下的数据库","sync-schema": {"title": "库表同步","description": "Bytebase 支持将一个指定的 Schema 同步到一个或多个目标数据库。",diff --git a/frontend/src/utils/issue/index.ts b/frontend/src/utils/issue/index.tsindex 1abffd118c..74b06d3fd5 100644--- a/frontend/src/utils/issue/index.ts+++ b/frontend/src/utils/issue/index.ts@@ -1,7 +1,8 @@+import dayjs from "dayjs";import { Issue, IssueType, StageId } from "@/types";export function stageName(issue: Issue, stageId: StageId): string {- for (const stage of issue.pipeline.stageList) {+ for (const stage of issue.pipeline?.stageList ?? []) {if (stage.id == stageId) {return stage.name;}@@ -25,3 +26,29 @@ export function isDatabaseRelatedIssueType(issueType: IssueType): boolean {"bb.issue.database.restore.pitr",].includes(issueType);}++export const generateIssueName = (+ type: "bb.issue.database.schema.update" | "bb.issue.database.data.update",+ 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(+ type === "bb.issue.database.schema.update" ? `Edit schema` : `Change data`+ );+ }+ const datetime = dayjs().format("@MM-DD HH:mm");+ const tz = "UTC" + dayjs().format("ZZ");+ issueNameParts.push(`${datetime} ${tz}`);++ return issueNameParts.join(" ");+};