Skip to content

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

chore: can enable online migration in schema editor modal (#12674)

Liu Ji87cc1f06f38b
diff --git a/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vue b/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vue
index e5fb935473..9bdda5b45a 100644
--- a/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vue
+++ b/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vue
@@ -82,6 +82,8 @@
<SchemaEditorSQLCheckButton
:database-list="databaseList"
:get-statement="generateOrGetEditingDDL"
+ :use-online-schema-change="state.useOnlineSchemaChange"
+ @enable-online-schema-change="state.useOnlineSchemaChange = true"
/>
</template>
</NTabs>
@@ -92,6 +94,12 @@
<NCheckbox v-model:checked="state.planOnly">
{{ $t("issue.sql-review-only") }}
</NCheckbox>
+ <NCheckbox
+ v-if="allowUseOnlineSchemaChange"
+ v-model:checked="state.useOnlineSchemaChange"
+ >
+ {{ $t("task.online-migration.enable") }}
+ </NCheckbox>
<NButton @click="dismissModal">
{{ $t("common.cancel") }}
</NButton>
@@ -145,6 +153,7 @@ import { Engine } from "@/types/proto/v1/common";
import type { DatabaseMetadata } from "@/types/proto/v1/database_service";
import { DatabaseMetadataView } from "@/types/proto/v1/database_service";
import { TinyTimer, defer, extractProjectResourceName } from "@/utils";
+import { allowGhostForDatabase } from "../IssueV1/components/Sidebar/GhostSection/common";
import { MonacoEditor } from "../MonacoEditor";
import { provideSQLCheckContext } from "../SQLCheck";
import type { EditTarget, GenerateDiffDDLResult } from "../SchemaEditorLite";
@@ -167,6 +176,7 @@ interface LocalState {
isUploadingFile: boolean;
// planOnly is used to indicate whether only to create plan.
planOnly: boolean;
+ useOnlineSchemaChange: boolean;
}
const props = defineProps({
@@ -205,6 +215,7 @@ const state = reactive<LocalState>({
targets: [],
isUploadingFile: false,
planOnly: props.planOnly,
+ useOnlineSchemaChange: false,
});
const databaseV1Store = useDatabaseV1Store();
const notificationStore = useNotificationStore();
@@ -246,6 +257,10 @@ const editTargetsKey = computed(() => {
});
});
+const allowUseOnlineSchemaChange = computed(() => {
+ return databaseList.value.every((db) => allowGhostForDatabase(db));
+});
+
const prepareDatabaseMetadata = async () => {
state.isPreparingMetadata = true;
state.targets = [];
@@ -420,6 +435,9 @@ const handlePreviewIssue = async () => {
template: "bb.issue.database.schema.update",
};
query.databaseList = databaseList.value.map((db) => db.name).join(",");
+ if (state.useOnlineSchemaChange) {
+ query.ghost = "1";
+ }
if (state.selectedTab === "raw-sql") {
query.sql = state.editStatement;
diff --git a/frontend/src/components/AlterSchemaPrepForm/SchemaEditorSQLCheckButton/SchemaEditorSQLCheckButton.vue b/frontend/src/components/AlterSchemaPrepForm/SchemaEditorSQLCheckButton/SchemaEditorSQLCheckButton.vue
index 43a64baca5..d8f13796bf 100644
--- a/frontend/src/components/AlterSchemaPrepForm/SchemaEditorSQLCheckButton/SchemaEditorSQLCheckButton.vue
+++ b/frontend/src/components/AlterSchemaPrepForm/SchemaEditorSQLCheckButton/SchemaEditorSQLCheckButton.vue
@@ -3,24 +3,55 @@
v-if="show"
:database="database"
:get-statement="getStatement"
+ :change-type="
+ useOnlineSchemaChange
+ ? CheckRequest_ChangeType.DDL_GHOST
+ : CheckRequest_ChangeType.DDL
+ "
:button-props="{
size: 'small',
}"
+ :highlight-row-filter="
+ (row) => row.checkResult.title === 'advice.online-migration'
+ "
class="justify-end"
- />
+ >
+ <template #row-title-extra="{ row, confirm }">
+ <NButton
+ v-if="row.checkResult.title === 'advice.online-migration'"
+ size="small"
+ type="primary"
+ @click="handleEnableOnlineChange(confirm)"
+ >
+ {{ $t("task.online-migration.enable") }}
+ </NButton>
+ </template>
+ </SQLCheckButton>
</template>
<script lang="ts" setup>
import { toRef } from "vue";
import { SQLCheckButton } from "@/components/SQLCheck";
import type { ComposedDatabase } from "@/types";
+import { CheckRequest_ChangeType } from "@/types/proto/v1/sql_service";
+import type { Defer } from "@/utils";
import { useSchemaEditorSQLCheck } from "./useSchemaEditorSQLCheck";
const props = defineProps<{
databaseList: ComposedDatabase[];
getStatement: () => Promise<{ statement: string; errors: string[] }>;
+ useOnlineSchemaChange: boolean;
+}>();
+
+const emit = defineEmits<{
+ (event: "enable-online-schema-change"): void;
}>();
const { show, database } = useSchemaEditorSQLCheck({
databaseList: toRef(props, "databaseList"),
});
+
+const handleEnableOnlineChange = (confirm: Defer<boolean> | undefined) => {
+ emit("enable-online-schema-change");
+ confirm?.resolve(false);
+};
</script>
diff --git a/frontend/src/components/SQLCheck/SQLCheckButton.vue b/frontend/src/components/SQLCheck/SQLCheckButton.vue
index 058137c55a..c30e6602ea 100644
--- a/frontend/src/components/SQLCheck/SQLCheckButton.vue
+++ b/frontend/src/components/SQLCheck/SQLCheckButton.vue
@@ -173,8 +173,17 @@ const runCheckInternal = async (
const handleButtonClick = async () => {
await runChecks();
+
if (hasError.value) {
+ const d = defer<boolean>();
+ confirmDialog.value = d;
+ d.promise.finally(onPanelClose);
+
showDetailPanel.value = true;
+
+ return d.promise;
+ } else {
+ confirmDialog.value = undefined;
}
};