Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat(frontend): gh-ost integration part.2 (#1141)
Liu Ji52c48ec83be3
diff --git a/frontend/package.json b/frontend/package.jsonindex bbe75403d4..3ce7ae4d22 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -26,6 +26,7 @@"node-sql-parser": "^4.0.8","papaparse": "^5.3.1","pinia": "^2.0.12",+ "semver": "^7.3.7","slug": "^4.0.2","splitpanes": "^3.0.6","sql-formatter": "^4.0.2",@@ -46,6 +47,7 @@"@types/node": "^16.11.9","@types/papaparse": "^5.3.1","@types/prettier": "^2.4.2",+ "@types/semver": "^7.3.9","@types/slug": "^0.9.1","@types/splitpanes": "^2.2.1","@types/uuid": "^8.3.0",diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yamlindex b8884c34e4..4fa42ba6ea 100644--- a/frontend/pnpm-lock.yaml+++ b/frontend/pnpm-lock.yaml@@ -12,6 +12,7 @@ specifiers:'@types/node': ^16.11.9'@types/papaparse': ^5.3.1'@types/prettier': ^2.4.2+ '@types/semver': ^7.3.9'@types/slug': ^0.9.1'@types/splitpanes': ^2.2.1'@types/uuid': ^8.3.0@@ -39,6 +40,7 @@ specifiers:pinia: ^2.0.12postcss: ^8.4.12prettier: ^2.4.1+ semver: ^7.3.7slug: ^4.0.2splitpanes: ^3.0.6sql-formatter: ^4.0.2@@ -71,6 +73,7 @@ dependencies:node-sql-parser: 4.1.1papaparse: 5.3.1+ semver: 7.3.7slug: 4.1.0splitpanes: 3.1.1sql-formatter: 4.0.2@@ -91,6 +94,7 @@ devDependencies:'@types/node': 16.11.26'@types/papaparse': 5.3.2'@types/prettier': 2.4.4+ '@types/semver': 7.3.9'@types/slug': 0.9.1'@types/splitpanes': 2.2.1'@types/uuid': 8.3.4@@ -492,6 +496,10 @@ packages:resolution: {integrity: sha512-ReVR2rLTV1kvtlWFyuot+d1pkpG2Fw/XKE3PDAdj57rbM97ttSp9JZ2UsP+2EHTylra9cUf6JA7tGwW1INzUrA==}dev: true+ /@types/semver/7.3.9:+ resolution: {integrity: sha512-L/TMpyURfBkf+o/526Zb6kd/tchUP3iBDEPjqjb+U2MAJhVRxxrmr2fwpe08E7QsV7YLcpq0tUaQ9O9x97ZIxQ==}+ dev: true+/@types/slug/0.9.1:resolution: {integrity: sha512-zR/u8WFQ4/6uCIikjI00a5uB084XjgEGNRAvM4a1BL39Bw9yEiDQFiPS2DgJ8lPDkR2Qd/vZ26dCR9XqlKbDqQ==}dev: true@@ -530,7 +538,7 @@ packages:functional-red-black-tree: 1.0.1ignore: 5.2.0regexpp: 3.2.0- semver: 7.3.5+ semver: 7.3.7tsutils: [email protected]typescript: 4.6.2transitivePeerDependencies:@@ -603,7 +611,7 @@ packages:debug: 4.3.3globby: 11.1.0is-glob: 4.0.3- semver: 7.3.5+ semver: 7.3.7tsutils: [email protected]typescript: 4.6.2transitivePeerDependencies:@@ -1592,7 +1600,7 @@ packages:eslint: 8.11.0eslint-utils: [email protected]natural-compare: 1.4.0- semver: 7.3.5+ semver: 7.3.7vue-eslint-parser: [email protected]transitivePeerDependencies:- supports-color@@ -2229,7 +2237,6 @@ packages:engines: {node: '>=10'}dependencies:yallist: 4.0.0- dev: true/magic-string/0.25.9:resolution: {integrity: sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ==}@@ -2765,13 +2772,12 @@ packages:hasBin: truedev: true- /semver/7.3.5:- resolution: {integrity: sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==}+ /semver/7.3.7:+ resolution: {integrity: sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==}engines: {node: '>=10'}hasBin: truedependencies:lru-cache: 6.0.0- dev: true/shebang-command/2.0.0:resolution: {integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==}@@ -3277,7 +3283,7 @@ packages:resolution: {integrity: sha512-eecDqHk4WjEvy6VHQ6teHczppQ9yJO2wExCy7yu7WiFj35qbw0h4G6Erv46MvP3ClL8FggFzD7s1qM6vdqJUfw==}dependencies:'@volar/shared': 0.29.8- semver: 7.3.5+ semver: 7.3.7upath: 2.0.1vscode-languageserver: 8.0.0-next.9vscode-languageserver-textdocument: 1.0.4@@ -3372,7 +3378,7 @@ packages:espree: 9.3.1esquery: 1.4.0lodash: 4.17.21- semver: 7.3.5+ semver: 7.3.7transitivePeerDependencies:- supports-colordev: true@@ -3477,7 +3483,6 @@ packages:/yallist/4.0.0:resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==}- dev: true/yaml-eslint-parser/0.3.2:resolution: {integrity: sha512-32kYO6kJUuZzqte82t4M/gB6/+11WAuHiEnK7FreMo20xsCKPeFH5tDBU7iWxR7zeJpNnMXfJyXwne48D0hGrg==}diff --git a/frontend/src/bbkit/BBDialog.vue b/frontend/src/bbkit/BBDialog.vuenew file mode 100644index 0000000000..d92115f5bf--- /dev/null+++ b/frontend/src/bbkit/BBDialog.vue@@ -0,0 +1,85 @@+<template>+ <BBModal+ v-if="state.visible"+ :title="title"+ :subtitle="subtitle"+ :show-close="closable"+ :esc-closable="closable"+ @close="onNegativeClick"+ >+ <slot name="default"></slot>++ <div class="pt-4 border-t border-block-border flex justify-end space-x-3">+ <button+ type="button"+ class="btn-normal py-2 px-4"+ @click.prevent="onNegativeClick"+ >+ {{ negativeText || $t("common.cancel") }}+ </button>+ <button+ type="button"+ class="btn-primary py-2 px-4"+ @click.prevent="onPositiveClick"+ >+ {{ positiveText || $t("common.confirm") }}+ </button>+ </div>+ </BBModal>+</template>++<script lang="ts" setup>+import { reactive } from "vue";+import { Defer, defer } from "@/utils";++defineProps({+ title: {+ type: String,+ required: true,+ },+ subtitle: {+ type: String,+ default: "",+ },+ closable: {+ type: Boolean,+ default: false,+ },+ negativeText: {+ type: String,+ default: undefined,+ },+ positiveText: {+ type: String,+ default: undefined,+ },+});++const state = reactive({+ visible: false,+ defer: undefined as Defer<boolean> | undefined,+});++const open = () => {+ if (state.defer) {+ state.defer.reject(new Error("duplicated call"));+ }++ state.defer = defer<boolean>();+ state.visible = true;++ return state.defer.promise;+};++const onPositiveClick = () => {+ state.visible = false;+ state.defer?.resolve(true);+};++const onNegativeClick = () => {+ state.visible = false;+ state.defer?.resolve(false);+};++defineExpose({ open });+</script>diff --git a/frontend/src/bbkit/BBModal.vue b/frontend/src/bbkit/BBModal.vueindex f96e87542c..034755cd83 100644--- a/frontend/src/bbkit/BBModal.vue+++ b/frontend/src/bbkit/BBModal.vue@@ -1,5 +1,6 @@<template><teleport to="#bb-modal-stack">+ <div class="fixed inset-0 bg-transparent" :style="style" /><divclass="bb-modal":style="style"@@ -53,6 +54,10 @@ export default defineComponent({type: Boolean,default: true,},+ escClosable: {+ type: Boolean,+ default: true,+ },},emits: ["close"],setup(props, { emit }) {@@ -67,6 +72,11 @@ export default defineComponent({};const escHandler = (e: KeyboardEvent) => {+ e.preventDefault();+ e.stopPropagation();+ if (!props.escClosable) {+ return;+ }if (!active.value) {// only to close the topmost modal when pressing ESCreturn;diff --git a/frontend/src/bbkit/index.ts b/frontend/src/bbkit/index.tsindex 9b2dc7d3df..88f70660d6 100644--- a/frontend/src/bbkit/index.ts+++ b/frontend/src/bbkit/index.ts@@ -7,6 +7,7 @@ import BBButtonConfirm from "./BBButtonConfirm.vue";import BBCheckbox from "./BBCheckbox.vue";import BBContextMenu from "./BBContextMenu.vue";import BBModal from "./BBModal.vue";+import BBDialog from "./BBDialog.vue";import BBNotification from "./BBNotification.vue";import BBOutline from "./BBOutline.vue";import BBSelect from "./BBSelect.vue";@@ -37,6 +38,7 @@ export {BBCheckbox,BBContextMenu,BBModal,+ BBDialog,BBNotification,BBOutline,BBSelect,diff --git a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vueindex e0056d65a8..22205fc5f9 100644--- a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue+++ b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue@@ -64,7 +64,7 @@v-if="state.alterType == 'MULTI_DB'"class="btn-primary ml-3 inline-flex justify-center py-2 px-4":disabled="!allowGenerateMultiDb"- @click.prevent="generateMultDb"+ @click.prevent="generateMultiDb">{{ $t("common.next") }}</button>@@ -85,11 +85,16 @@feature="bb.feature.multi-tenancy"@cancel="state.showFeatureModal = false"/>++ <GhostDialog ref="ghostDialog" /></template><script lang="ts">-import { computed, reactive, PropType, defineComponent } from "vue";+import { computed, reactive, PropType, defineComponent, ref } from "vue";import { useRouter } from "vue-router";+import { NTabs, NTabPane } from "naive-ui";+import { useEventListener } from "@vueuse/core";+import { cloneDeep } from "lodash-es";import DatabaseTable from "../DatabaseTable.vue";import {baseDirectoryWebUrl,@@ -99,9 +104,8 @@ import {ProjectId,Repository,UNKNOWN_ID,-} from "../../types";-import { sortDatabaseList } from "../../utils";-import { cloneDeep } from "lodash-es";+} from "@/types";+import { allowGhostMigration, isDev, sortDatabaseList } from "@/utils";import VCSTipsInfo from "./VCSTipsInfo.vue";import ProjectStandardView, {State as ProjectStandardState,@@ -112,8 +116,7 @@ import ProjectTenantView, {import CommonTenantView, {State as CommonTenantState,} from "./CommonTenantView.vue";-import { NTabs, NTabPane } from "naive-ui";-import { useEventListener } from "@vueuse/core";+import GhostDialog from "./GhostDialog.vue";import {hasFeature,useCurrentUser,@@ -141,6 +144,7 @@ export default defineComponent({CommonTenantView,NTabs,NTabPane,+ GhostDialog,},props: {projectId: {@@ -162,6 +166,8 @@ export default defineComponent({const projectStore = useProjectStore();const repositoryStore = useRepositoryStore();+ const ghostDialog = ref<InstanceType<typeof GhostDialog>>();+useEventListener(window, "keydown", (e) => {if (e.code === "Escape") {cancel();@@ -220,32 +226,66 @@ export default defineComponent({return state.selectedDatabaseIdForEnvironment.size > 0;});- const generateMultDb = () => {+ // 'normal' -> normal migration+ // 'online' -> online migration+ // false -> user clicked cancel button+ const isUsingGhostMigration = async (databaseList: Database[]) => {+ if (!isDev()) {+ 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";+ };++ const generateMultiDb = async () => {const databaseIdList: DatabaseId[] = [];+ const selectedDatabaseList: Database[] = [];for (var i = 0; i < environmentList.value.length; i++) {- if (- state.selectedDatabaseIdForEnvironment.get(- environmentList.value[i].id- )- ) {- databaseIdList.push(- state.selectedDatabaseIdForEnvironment.get(- environmentList.value[i].id- )!+ const envId = environmentList.value[i].id;+ const databaseId = state.selectedDatabaseIdForEnvironment.get(envId);+ if (databaseId) {+ databaseIdList.push(databaseId);+ selectedDatabaseList.push(+ databaseList.value.find((db) => db.id === databaseId)!);}}++ const mode = await isUsingGhostMigration(selectedDatabaseList);+ if (mode === false) {+ return;+ }+ const query: Record<string, any> = {+ template: props.type,+ name: isAlterSchema.value ? `Alter schema` : `Change data`,+ project: props.projectId,+ databaseList: databaseIdList.join(","),+ };+ if (mode === "online") {+ query.ghost = "1";+ }router.push({name: "workspace.issue.detail",params: {issueSlug: "new",},- query: {- template: props.type,- name: isAlterSchema.value ? `Alter schema` : `Change data`,- project: props.projectId,- databaseList: databaseIdList.join(","),- },+ query,});};@@ -299,23 +339,30 @@ export default defineComponent({}};- const selectDatabase = (database: Database) => {- emit("dismiss");-+ 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: `[${database.name}] ${+ isAlterSchema.value ? `Alter schema` : `Change data`+ }`,+ project: database.project.id,+ databaseList: database.id,+ };+ if (mode === "online") {+ query.ghost = "1";+ }router.push({name: "workspace.issue.detail",params: {issueSlug: "new",},- query: {- template: props.type,- name: `[${database.name}] ${- isAlterSchema.value ? `Alter schema` : `Change data`- }`,- project: database.project.id,- databaseList: database.id,- },+ query,});} else if (database.project.workflowType == "VCS") {repositoryStore@@ -323,6 +370,7 @@ export default defineComponent({.then((repository: Repository) => {window.open(baseDirectoryWebUrl(repository), "_blank");});+ emit("dismiss");}};@@ -344,6 +392,7 @@ export default defineComponent({return {wrapperClass,state,+ ghostDialog,isAlterSchema,isTenantProject,environmentList,@@ -351,7 +400,7 @@ export default defineComponent({standardProjectDatabaseList,tenantProjectDatabaseList,allowGenerateMultiDb,- generateMultDb,+ generateMultiDb,allowGenerateTenant,generateTenant,selectDatabase,diff --git a/frontend/src/components/AlterSchemaPrepForm/GhostDialog.vue b/frontend/src/components/AlterSchemaPrepForm/GhostDialog.vuenew file mode 100644index 0000000000..56d31c502f--- /dev/null+++ b/frontend/src/components/AlterSchemaPrepForm/GhostDialog.vue@@ -0,0 +1,89 @@+<template>+ <BBDialog+ ref="dialog"+ :title="$t('issue.migration-mode.title')"+ :positive-text="$t('common.next')"+ >+ <div class="w-[24rem] space-y-4 pl-8 pr-2 pb-4">+ <div class="flex items-start space-x-2">+ <input+ v-model="state.mode"+ tabindex="-1"+ type="radio"+ class="text-accent disabled:text-accent-disabled focus:ring-accent mt-0.5"+ value="normal"+ />+ <div @click="state.mode = 'normal'">+ <div class="textlabel">+ {{ $t("issue.migration-mode.normal.title") }}+ </div>+ <div class="textinfolabel mt-1">+ <i18n-t tag="p" keypath="issue.migration-mode.normal.description" />+ </div>+ </div>+ </div>+ <div class="flex items-start space-x-2">+ <input+ v-model="state.mode"+ tabindex="-1"+ type="radio"+ class="text-accent disabled:text-accent-disabled focus:ring-accent mt-0.5"+ value="online"+ />+ <div @click="state.mode = 'online'">+ <div class="textlabel">+ {{ $t("issue.migration-mode.online.title") }}+ </div>+ <div class="textinfolabel mt-1">+ <i18n-t tag="p" keypath="issue.migration-mode.online.description">+ <template #link>+ <LearnMoreLink+ url="https://github.com/bytebase/bytebase/blob/main/docs/design/gh-ost-integration.md"+ />+ </template>+ </i18n-t>+ </div>+ </div>+ </div>+ </div>+ </BBDialog>+</template>++<script lang="ts" setup>+import { reactive, ref } from "vue";+import { BBDialog } from "@/bbkit";+import LearnMoreLink from "../LearnMoreLink.vue";++type Mode = "normal" | "online";++type LocalState = {+ mode: Mode;+};++const dialog = ref<InstanceType<typeof BBDialog> | null>(null);++const state = reactive<LocalState>({+ mode: "normal",+});++const open = (): Promise<{ result: boolean; mode: Mode }> => {+ state.mode = "normal"; // reset state++ return dialog.value!.open().then(+ (result) => {+ return {+ result,+ mode: state.mode,+ };+ },+ (_error) => {+ return {+ result: false,+ mode: "normal",+ };+ }+ );+};++defineExpose({ open });+</script>diff --git a/frontend/src/components/AlterSchemaPrepForm/index.ts b/frontend/src/components/AlterSchemaPrepForm/index.tsindex c7794601d7..596a620ea8 100644--- a/frontend/src/components/AlterSchemaPrepForm/index.ts+++ b/frontend/src/components/AlterSchemaPrepForm/index.ts@@ -1,3 +1,6 @@import AlterSchemaPrepForm from "./AlterSchemaPrepForm.vue";+import GhostDialog from "./GhostDialog.vue";export default AlterSchemaPrepForm;++export { GhostDialog };diff --git a/frontend/src/components/LearnMoreLink.vue b/frontend/src/components/LearnMoreLink.vuenew file mode 100644index 0000000000..5ac98b8c93--- /dev/null+++ b/frontend/src/components/LearnMoreLink.vue@@ -0,0 +1,15 @@+<template>+ <a class="normal-link inline-flex items-center" :href="url" target="__BLANK">+ {{ $t("common.learn-more") }}+ <heroicons-outline:external-link class="w-4 h-4 ml-1" />+ </a>+</template>++<script lang="ts" setup>+defineProps({+ url: {+ type: String,+ required: true,+ },+});+</script>diff --git a/frontend/src/locales/en.yml b/frontend/src/locales/en.ymlindex 55b966998c..72f401701f 100644--- a/frontend/src/locales/en.yml+++ b/frontend/src/locales/en.yml@@ -426,6 +426,17 @@ issue:stage-select:active: "{name} (active)"not-allowed-to-single-database-in-tenant-mode: Can't {operation} to single database in tenant mode+ migration-mode:+ title: Migration mode+ normal:+ title: Normal migration (for normal-sized table)+ description: Perform schema change directly on the target table.+ online:+ title: Online migration (for large-sized table)+ description: >-+ Perform schema change on a duplicated empty table. Sync the data and+ swap the table name after sync finishes. Applying migration on a large+ table directly would cause long-time unavailability {link}.alter-schema:vcs-enabled: >-This project has enabled VCS based version control and selecting databasediff --git a/frontend/src/locales/zh-CN.yml b/frontend/src/locales/zh-CN.ymlindex 4fcfa48e88..aaf1acfbf9 100644--- a/frontend/src/locales/zh-CN.yml+++ b/frontend/src/locales/zh-CN.yml@@ -411,6 +411,14 @@ issue:stage-select:active: "{name}(活动中)"not-allowed-to-single-database-in-tenant-mode: 在多租户模式下无法对单个数据库{operation}+ migration-mode:+ title: 迁移模式+ normal:+ title: 普通变更 (适用于正常大小的表)+ description: 直接在目标表上执行 schema 变更。+ online:+ title: 在线变更 (适用于数据量大的表)+ description: 在复制的空表上执行 schema 变更,开始从原表同步数据,并在同步完成之后交换表名。如果直接在原表上变更会导致长时间不可用 {link}。alter-schema:vcs-enabled: 该项目开启了基于 VCS 的版本管理,选择下面的数据库会将您导航到相应的 Git 仓库以发起变更流程。vcs-info: 代表项目开启了基于 VCS 的版本管理。选择该类项目下的数据库会将您导航到对应的 Git 仓库以发起变更流程。diff --git a/frontend/src/utils/database.ts b/frontend/src/utils/database.tsindex 848154c65b..a6362da0f5 100644--- a/frontend/src/utils/database.ts+++ b/frontend/src/utils/database.ts@@ -1,3 +1,4 @@+import semverCompare from "semver/functions/compare";import { Database, DataSourceType, Environment, Principal } from "../types";import { isDBAOrOwner } from "./role";import { isDev } from "./util";@@ -52,3 +53,17 @@ export function sortDatabaseList(return bEnvIndex - aEnvIndex;});}++const MIN_GHOST_SUPPORT_MYSQL_VERSION = "5.6.0";++export function allowGhostMigration(databaseList: Database[]): boolean {+ return databaseList.every((db) => {+ return (+ db.instance.engine === "MYSQL" &&+ semverCompare(+ db.instance.engineVersion,+ MIN_GHOST_SUPPORT_MYSQL_VERSION+ ) >= 0+ );+ });+}diff --git a/frontend/src/utils/util.ts b/frontend/src/utils/util.tsindex da5c408860..38b0f14856 100644--- a/frontend/src/utils/util.ts+++ b/frontend/src/utils/util.ts@@ -154,3 +154,17 @@ export function getStringCookie(name: string): string {export function getHighlightHTMLByKeyWords(s: string, k: string) {return s.replaceAll(k, `<b class="text-accent">${k}</b>`);}++export type Defer<T> = {+ promise: Promise<T>;+ resolve: (value: T | PromiseLike<T>) => void;+ reject: (reason?: any) => void;+};+export function defer<T = any>() {+ const d = {} as Defer<T>;+ d.promise = new Promise<T>((resolve, reject) => {+ d.resolve = resolve;+ d.reject = reject;+ });+ return d;+}diff --git a/frontend/src/views/DatabaseDetail.vue b/frontend/src/views/DatabaseDetail.vueindex 0c89b4d2b9..30ce882d3a 100644--- a/frontend/src/views/DatabaseDetail.vue+++ b/frontend/src/views/DatabaseDetail.vue@@ -280,10 +280,19 @@</div></BBModal></div>++ <GhostDialog ref="ghostDialog" /></template><script lang="ts">-import { computed, onMounted, reactive, watch, defineComponent } from "vue";+import {+ computed,+ onMounted,+ reactive,+ watch,+ defineComponent,+ ref,+} from "vue";import { useRouter } from "vue-router";import ProjectSelect from "../components/ProjectSelect.vue";import DatabaseBackupPanel from "../components/DatabaseBackupPanel.vue";@@ -292,7 +301,14 @@ import DatabaseOverviewPanel from "../components/DatabaseOverviewPanel.vue";import InstanceEngineIcon from "../components/InstanceEngineIcon.vue";import { DatabaseLabelProps } from "../components/DatabaseLabels";import { SelectDatabaseLabel } from "../components/TransferDatabaseForm";-import { idFromSlug, isDBAOrOwner, connectionSlug, hidePrefix } from "../utils";+import {+ idFromSlug,+ isDBAOrOwner,+ connectionSlug,+ hidePrefix,+ isDev,+ allowGhostMigration,+} from "../utils";import {ProjectId,UNKNOWN_ID,@@ -304,6 +320,7 @@ import {} from "../types";import { BBTabFilterItem } from "../bbkit/types";import { useI18n } from "vue-i18n";+import { GhostDialog } from "@/components/AlterSchemaPrepForm";import {pushNotification,useCurrentUser,@@ -337,6 +354,7 @@ export default defineComponent({InstanceEngineIcon,DatabaseLabelProps,SelectDatabaseLabel,+ GhostDialog,},props: {databaseSlug: {@@ -349,6 +367,7 @@ export default defineComponent({const repositoryStore = useRepositoryStore();const router = useRouter();const { t } = useI18n();+ const ghostDialog = ref<InstanceType<typeof GhostDialog>>();const databaseTabItemList: DatabaseTabItem[] = [{ name: t("common.overview"), hash: "overview" },@@ -482,19 +501,47 @@ export default defineComponent({state.showTransferDatabaseModal = true;};- const alterSchema = () => {+ // 'normal' -> normal migration+ // 'online' -> online migration+ // false -> user clicked cancel button+ const isUsingGhostMigration = async (databaseList: Database[]) => {+ if (!isDev()) {+ 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";+ };++ const alterSchema = async () => {if (database.value.project.workflowType == "UI") {+ const mode = await isUsingGhostMigration([database.value]);+ if (mode === false) return;+ const query: Record<string, any> = {+ template: "bb.issue.database.schema.update",+ name: `[${database.value.name}] Alter schema`,+ project: database.value.project.id,+ databaseList: database.value.id,+ };+ if (mode === "online") {+ query.ghost = "1";+ }router.push({name: "workspace.issue.detail",params: {issueSlug: "new",},- query: {- template: "bb.issue.database.schema.update",- name: `[${database.value.name}] Alter schema`,- project: database.value.project.id,- databaseList: database.value.id,- },+ query,});} else if (database.value.project.workflowType == "VCS") {repositoryStore@@ -622,6 +669,7 @@ export default defineComponent({MIGRATION_HISTORY_TAB,BACKUP_TAB,state,+ ghostDialog,isTenantProject,database,allowChangeProject,