Skip to content

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

chore: adjust gh-ost and backup checks in frontend (#16369)

boojack028639cfac98
diff --git a/frontend/src/components/IssueV1/components/DataExportSection/ExportOptionSection/ExportOptionSection.vue b/frontend/src/components/IssueV1/components/DataExportSection/ExportOptionSection/ExportOptionSection.vue
index 8b51497a05..bde14c2c0f 100644
--- a/frontend/src/components/IssueV1/components/DataExportSection/ExportOptionSection/ExportOptionSection.vue
+++ b/frontend/src/components/IssueV1/components/DataExportSection/ExportOptionSection/ExportOptionSection.vue
@@ -142,7 +142,7 @@ const handleSaveEdit = async () => {
const updatedPlan = await planServiceClient.updatePlan({
plan: planPatch,
- updateMask: ["steps"],
+ updateMask: ["specs"],
});
issue.value.planEntity = updatedPlan;
diff --git a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
index 3f95bbcd60..126cc7e215 100644
--- a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
+++ b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
@@ -667,7 +667,7 @@ const updateStatement = async (statement: string) => {
const updatedPlan = await planServiceClient.updatePlan({
plan: planPatch,
- updateMask: ["steps"],
+ updateMask: ["specs"],
});
issue.value.planEntity = updatedPlan;
diff --git a/frontend/src/components/Plan/components/Sidebar/GhostSection/GhostFlagsPanel.vue b/frontend/src/components/Plan/components/Sidebar/GhostSection/GhostFlagsPanel.vue
index 5260b421c8..31ff156009 100644
--- a/frontend/src/components/Plan/components/Sidebar/GhostSection/GhostFlagsPanel.vue
+++ b/frontend/src/components/Plan/components/Sidebar/GhostSection/GhostFlagsPanel.vue
@@ -113,7 +113,7 @@ const trySave = async () => {
spec.changeDatabaseConfig.ghostFlags = cloneDeep(flags.value);
await planServiceClient.updatePlan({
plan: planPatch,
- updateMask: ["steps"],
+ updateMask: ["specs"],
});
pushNotification({
diff --git a/frontend/src/components/Plan/components/Sidebar/GhostSection/GhostSection.vue b/frontend/src/components/Plan/components/Sidebar/GhostSection/GhostSection.vue
index 68b27cc28d..b3fb8f19ed 100644
--- a/frontend/src/components/Plan/components/Sidebar/GhostSection/GhostSection.vue
+++ b/frontend/src/components/Plan/components/Sidebar/GhostSection/GhostSection.vue
@@ -67,9 +67,10 @@ import { useGhostSettingContext } from "./context";
const showFlagsPanel = ref(false);
-const { allowChange, enabled, database } = useGhostSettingContext();
+const { allowChange, enabled, databases } = useGhostSettingContext();
const instance = computed(() => {
- return database.value.instanceResource;
+ return databases.value.find((db) => !db.instanceResource.activation)
+ ?.instanceResource;
});
</script>
diff --git a/frontend/src/components/Plan/components/Sidebar/GhostSection/GhostSwitch.vue b/frontend/src/components/Plan/components/Sidebar/GhostSection/GhostSwitch.vue
index f7c517f481..3c2fbef2af 100644
--- a/frontend/src/components/Plan/components/Sidebar/GhostSection/GhostSwitch.vue
+++ b/frontend/src/components/Plan/components/Sidebar/GhostSection/GhostSwitch.vue
@@ -22,14 +22,8 @@ import type { ErrorItem } from "@/components/misc/ErrorList.vue";
import { default as ErrorList } from "@/components/misc/ErrorList.vue";
import { planServiceClient } from "@/grpcweb";
import { pushNotification } from "@/store";
-import { Engine } from "@/types/proto/v1/common";
import { Plan_ChangeDatabaseConfig_Type } from "@/types/proto/v1/plan_service";
-import { engineNameV1 } from "@/utils";
-import {
- allowGhostForDatabase,
- MIN_GHOST_SUPPORT_MARIADB_VERSION,
- MIN_GHOST_SUPPORT_MYSQL_VERSION,
-} from "./common";
+import { allowGhostForDatabase } from "./common";
import { useGhostSettingContext } from "./context";
const { t } = useI18n();
@@ -39,40 +33,32 @@ const {
selectedSpec,
allowChange,
enabled,
- database,
events,
+ databases,
} = useGhostSettingContext();
const errors = computed(() => {
const errors: ErrorItem[] = [];
- if (!database.value.instanceResource.activation) {
+ if (databases.value.some((db) => !db.instanceResource.activation)) {
errors.push(
t("subscription.instance-assignment.missing-license-attention")
);
}
- // As we use the same database from backup to save temp tables in gh-ost, check if backup is available.
- if (!database.value.backupAvailable) {
+ const backupUnavailableDatabases = databases.value.filter(
+ (db) => !db.backupAvailable || !allowGhostForDatabase(db)
+ );
+ if (backupUnavailableDatabases.length > 0) {
errors.push(
t(
- "task.online-migration.error.not-applicable.needs-database-for-saving-temp-data",
+ "task.online-migration.error.not-applicable.database-doesnt-meet-ghost-requirement",
{
- // The same database name as backup.
- database: "bbdataarchive",
+ database: backupUnavailableDatabases
+ .map((db) => db.databaseName)
+ .join(", "),
}
)
);
}
- if (!allowGhostForDatabase(database.value)) {
- errors.push(
- t(
- "task.online-migration.error.not-applicable.task-doesnt-meet-ghost-requirement"
- )
- );
- errors.push({
- error: `${engineNameV1(Engine.MYSQL)} >= ${MIN_GHOST_SUPPORT_MYSQL_VERSION}, ${engineNameV1(Engine.MARIADB)} >= ${MIN_GHOST_SUPPORT_MARIADB_VERSION}`,
- indent: 1,
- });
- }
return errors;
});
@@ -103,7 +89,7 @@ const toggleChecked = async (on: boolean) => {
: Plan_ChangeDatabaseConfig_Type.MIGRATE;
await planServiceClient.updatePlan({
plan: planPatch,
- updateMask: ["steps"],
+ updateMask: ["specs"],
});
pushNotification({
diff --git a/frontend/src/components/Plan/components/Sidebar/GhostSection/context.ts b/frontend/src/components/Plan/components/Sidebar/GhostSection/context.ts
index 4b0f027d80..e52c6f8cd3 100644
--- a/frontend/src/components/Plan/components/Sidebar/GhostSection/context.ts
+++ b/frontend/src/components/Plan/components/Sidebar/GhostSection/context.ts
@@ -1,10 +1,9 @@
import Emittery from "emittery";
import type { InjectionKey, Ref } from "vue";
import { computed, inject, provide, unref } from "vue";
-import { databaseForSpec } from "@/components/Plan/logic";
-import { databaseForTask } from "@/components/Rollout/RolloutDetail";
-import { useCurrentUserV1, extractUserId } from "@/store";
-import { unknownDatabase, type ComposedProject } from "@/types";
+import { targetsForSpec } from "@/components/Plan/logic";
+import { useCurrentUserV1, extractUserId, useDatabaseV1Store } from "@/store";
+import { isValidDatabaseName, type ComposedProject } from "@/types";
import { Issue, IssueStatus } from "@/types/proto/v1/issue_service";
import type { Plan, Plan_Spec } from "@/types/proto/v1/plan_service";
import {
@@ -17,11 +16,7 @@ import {
hasProjectPermissionV2,
isNullOrUndefined,
} from "@/utils";
-import {
- allowGhostForDatabase,
- allowGhostForSpec,
- getGhostEnabledForSpec,
-} from "./common";
+import { allowGhostForSpec, getGhostEnabledForSpec } from "./common";
export const KEY = Symbol(
"bb.plan.setting.gh-ost"
@@ -41,6 +36,8 @@ export const provideGhostSettingContext = (refs: {
rollout?: Ref<Rollout | undefined>;
}) => {
const currentUser = useCurrentUserV1();
+ const databaseStore = useDatabaseV1Store();
+
const {
isCreating,
project,
@@ -55,20 +52,19 @@ export const provideGhostSettingContext = (refs: {
update: never;
}>();
- const database = computed(() => {
- if (selectedTask?.value) {
- return databaseForTask(project.value, selectedTask.value);
- } else if (selectedSpec.value) {
- return databaseForSpec(project.value, selectedSpec.value);
- }
- return unknownDatabase();
+ const databases = computed(() => {
+ const targets = selectedSpec.value
+ ? targetsForSpec(selectedSpec.value)
+ : [];
+ return targets
+ .map((target) => databaseStore.getDatabaseByName(target))
+ .filter((db) => isValidDatabaseName(db.name));
});
const shouldShow = computed(() => {
return (
selectedSpec.value &&
allowGhostForSpec(selectedSpec.value) &&
- allowGhostForDatabase(database.value) &&
!isNullOrUndefined(getGhostEnabledForSpec(selectedSpec.value))
);
});
@@ -132,7 +128,7 @@ export const provideGhostSettingContext = (refs: {
shouldShow,
allowChange,
enabled,
- database,
+ databases,
events,
};
diff --git a/frontend/src/components/Plan/components/Sidebar/PreBackupSection/PreBackupSwitch.vue b/frontend/src/components/Plan/components/Sidebar/PreBackupSection/PreBackupSwitch.vue
index 94713f6c79..c650b49391 100644
--- a/frontend/src/components/Plan/components/Sidebar/PreBackupSection/PreBackupSwitch.vue
+++ b/frontend/src/components/Plan/components/Sidebar/PreBackupSection/PreBackupSwitch.vue
@@ -27,18 +27,29 @@ import { computed } from "vue";
import { useI18n } from "vue-i18n";
import LearnMoreLink from "@/components/LearnMoreLink.vue";
import { pushNotification } from "@/store";
-import { usePreBackupSettingContext } from "./context";
+import {
+ PRE_BACKUP_AVAILABLE_ENGINES,
+ usePreBackupSettingContext,
+} from "./context";
const { t } = useI18n();
-const { enabled, allowChange, database, toggle } = usePreBackupSettingContext();
+const { enabled, allowChange, databases, toggle } =
+ usePreBackupSettingContext();
const disallowPreBackupMessage = computed(() => {
if (allowChange.value) {
return undefined;
}
- if (!database.value.backupAvailable) {
+ if (!databases.value.some((db) => !db.backupAvailable)) {
return t("database.create-target-database-or-schema-for-backup");
}
+ if (
+ databases.value.some(
+ (db) => !PRE_BACKUP_AVAILABLE_ENGINES.includes(db.instanceResource.engine)
+ )
+ ) {
+ return false;
+ }
return undefined;
});
@@ -46,7 +57,7 @@ const disallowPreBackupLink = computed(() => {
if (allowChange.value) {
return undefined;
}
- if (!database.value.backupAvailable) {
+ if (!databases.value.some((db) => !db.backupAvailable)) {
return "https://www.bytebase.com/docs/change-database/rollback-data-changes?source=console";
}
return undefined;
diff --git a/frontend/src/components/Plan/components/Sidebar/PreBackupSection/context.ts b/frontend/src/components/Plan/components/Sidebar/PreBackupSection/context.ts
index e429f13a39..abf3f09fee 100644
--- a/frontend/src/components/Plan/components/Sidebar/PreBackupSection/context.ts
+++ b/frontend/src/components/Plan/components/Sidebar/PreBackupSection/context.ts
@@ -1,5 +1,5 @@
import Emittery from "emittery";
-import { cloneDeep } from "lodash-es";
+import { cloneDeep, head } from "lodash-es";
import {
computed,
inject,
@@ -8,11 +8,10 @@ import {
type InjectionKey,
type Ref,
} from "vue";
-import { databaseForSpec, isDatabaseChangeSpec } from "@/components/Plan/logic";
-import { databaseForTask } from "@/components/Rollout/RolloutDetail";
+import { isDatabaseChangeSpec, targetsForSpec } from "@/components/Plan/logic";
import { planServiceClient } from "@/grpcweb";
-import { useCurrentUserV1, extractUserId } from "@/store";
-import { unknownDatabase, type ComposedProject } from "@/types";
+import { useCurrentUserV1, extractUserId, useDatabaseV1Store } from "@/store";
+import { isValidDatabaseName, type ComposedProject } from "@/types";
import { Engine } from "@/types/proto/v1/common";
import { IssueStatus, type Issue } from "@/types/proto/v1/issue_service";
import {
@@ -32,7 +31,7 @@ import {
} from "@/utils";
import { getArchiveDatabase } from "./utils";
-const PRE_BACKUP_AVAILABLE_ENGINES = [
+export const PRE_BACKUP_AVAILABLE_ENGINES = [
Engine.MYSQL,
Engine.TIDB,
Engine.MSSQL,
@@ -58,27 +57,20 @@ export const providePreBackupSettingContext = (refs: {
rollout?: Ref<Rollout | undefined>;
}) => {
const currentUser = useCurrentUserV1();
- const {
- isCreating,
- project,
- plan,
- selectedSpec,
- selectedTask,
- issue,
- rollout,
- } = refs;
+ const databaseStore = useDatabaseV1Store();
+ const { isCreating, project, plan, selectedSpec, issue, rollout } = refs;
const events = new Emittery<{
update: boolean;
}>();
- const database = computed(() => {
- if (selectedTask?.value) {
- return databaseForTask(project.value, selectedTask.value);
- } else if (selectedSpec.value) {
- return databaseForSpec(project.value, selectedSpec.value);
- }
- return unknownDatabase();
+ const databases = computed(() => {
+ const targets = selectedSpec.value
+ ? targetsForSpec(selectedSpec.value)
+ : [];
+ return targets
+ .map((target) => databaseStore.getDatabaseByName(target))
+ .filter((db) => isValidDatabaseName(db.name));
});
const shouldShow = computed((): boolean => {
@@ -93,19 +85,10 @@ export const providePreBackupSettingContext = (refs: {
if (isDatabaseChangeSpec(selectedSpec.value)) {
return true;
}
- const { engine } = database.value.instanceResource;
- if (!PRE_BACKUP_AVAILABLE_ENGINES.includes(engine)) {
- return false;
- }
return true;
});
const allowChange = computed((): boolean => {
- // Disallow pre-backup if no backup available for the target database.
- if (!database.value.backupAvailable) {
- return false;
- }
-
// Allow toggle pre-backup when creating.
if (isCreating.value) {
return true;
@@ -152,17 +135,25 @@ export const providePreBackupSettingContext = (refs: {
return !isNullOrUndefined(preBackupDatabase) && preBackupDatabase !== "";
});
- const archiveDatabase = computed((): string =>
- getArchiveDatabase(database.value.instanceResource.engine)
- );
+ // TODO(steven): remove me.
+ const archiveDatabase = computed((): string => {
+ const database = head(databases.value);
+ return getArchiveDatabase(
+ database?.instanceResource.engine || Engine.MYSQL
+ );
+ });
const toggle = async (on: boolean) => {
if (isCreating.value) {
if (selectedSpec.value && selectedSpec.value.changeDatabaseConfig) {
if (on) {
+ // TODO(steven): switch to boolean value.
+ const database = head(databases.value);
selectedSpec.value.changeDatabaseConfig.preUpdateBackupDetail = {
database:
- database.value.instance + "/databases/" + archiveDatabase.value,
+ (database?.instance || "instances/UNKNOWN_INSTANCE") +
+ "/databases/" +
+ archiveDatabase.value,
};
} else {
selectedSpec.value.changeDatabaseConfig.preUpdateBackupDetail =
@@ -181,9 +172,13 @@ export const providePreBackupSettingContext = (refs: {
);
}
if (on) {
+ // TODO(steven): switch to boolean value.
+ const database = head(databases.value);
spec.changeDatabaseConfig.preUpdateBackupDetail = {
database:
- database.value.instance + "/databases/" + archiveDatabase.value,
+ (database?.instance || "instances/UNKNOWN_INSTANCE") +
+ "/databases/" +
+ archiveDatabase.value,
};
} else {
spec.changeDatabaseConfig.preUpdateBackupDetail = undefined;
@@ -191,7 +186,7 @@ export const providePreBackupSettingContext = (refs: {
await planServiceClient.updatePlan({
plan: planPatch,
- updateMask: ["steps"],
+ updateMask: ["specs"],
});
}
@@ -203,7 +198,7 @@ export const providePreBackupSettingContext = (refs: {
shouldShow,
enabled,
allowChange,
- database,
+ databases,
events,
toggle,
};
diff --git a/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue b/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue
index c49cf471d0..5d9ea626fd 100644
--- a/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue
+++ b/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue
@@ -544,7 +544,7 @@ const updateStatement = async (statement: string) => {
const updatedPlan = await planServiceClient.updatePlan({
plan: planPatch,
- updateMask: ["steps"],
+ updateMask: ["specs"],
});
Object.assign(plan.value, updatedPlan);
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 9031f6c369..43851cd7d4 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -287,8 +287,7 @@
"error": {
"nothing-changed": "Nothing changed",
"not-applicable": {
- "task-doesnt-meet-ghost-requirement": "Task doesn't meet gh-ost's requirement",
- "needs-database-for-saving-temp-data": "Needs database {database} for saving temporary data."
+ "database-doesnt-meet-ghost-requirement": "Database {database} doesn't meet gh-ost's requirement"
}
},
"advice-split-statement-to-single-online-migration-issue": "Advice splitting this statement to single online migration issue."
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 620795ad17..35a01e2d86 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -287,8 +287,7 @@
"error": {
"nothing-changed": "nada ha cambiado",
"not-applicable": {
- "task-doesnt-meet-ghost-requirement": "La tarea no cumple con el requisito de gh-ost",
- "needs-database-for-saving-temp-data": "Necesita la base de datos ({database}) para guardar tablas temporales."
+ "database-doesnt-meet-ghost-requirement": "La base de datos {database} no cumple con el requisito de gh-ost"
}
},
"advice-split-statement-to-single-online-migration-issue": "Se recomienda dividir esta declaración en un único problema de migración en línea."
@@ -2613,4 +2612,4 @@
"last-visit": "Última visita",
"changelog-for-version": "Registro de cambios para {version}"
}
-}
\ No newline at end of file
+}
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index be77e63660..54f7b3ecc7 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -287,8 +287,7 @@
"error": {
"nothing-changed": "変化なし",
"not-applicable": {
- "task-doesnt-meet-ghost-requirement": "タスクは gh-ost の要件を満たしていません",
- "needs-database-for-saving-temp-data": "一時データを保存するにはデータベース({database})が必要です。"
+ "database-doesnt-meet-ghost-requirement": "データベース {database} は gh-ost の要件を満たしていません"
}
},
"advice-split-statement-to-single-online-migration-issue": "このステートメントを 1 つのオンライン移行の問題に分割することをアドバイスします。"
@@ -2613,4 +2612,4 @@
"last-visit": "最終訪問",
"changelog-for-version": "{version} の変更履歴"
}
-}
\ No newline at end of file
+}
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index c126aace9b..011df95169 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -287,8 +287,7 @@
"error": {
"nothing-changed": "Không có gì thay đổi",
"not-applicable": {
- "task-doesnt-meet-ghost-requirement": "Nhiệm vụ không đáp ứng được yêu cầu của gh-ost",
- "needs-database-for-saving-temp-data": "Cần có cơ sở dữ liệu ({database}) để lưu dữ liệu tạm thời."
+ "database-doesnt-meet-ghost-requirement": "Cơ sở dữ liệu {database} không đáp ứng được yêu cầu của gh-ost"
}
},
"advice-split-statement-to-single-online-migration-issue": "Đề nghị chia câu lệnh này thành một vấn đề di chuyển trực tuyến."
@@ -2613,4 +2612,4 @@
"last-visit": "Lần truy cập cuối",
"changelog-for-version": "Nhật ký thay đổi cho phiên bản {version}"
}
-}
\ No newline at end of file
+}
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 7232e3d9ae..2e212c4ec4 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -287,8 +287,7 @@
"error": {
"nothing-changed": "无任何改变",
"not-applicable": {
- "task-doesnt-meet-ghost-requirement": "任务不符合 gh-ost 的要求",
- "needs-database-for-saving-temp-data": "需要数据库 {database} 来保存临时数据。"
+ "database-doesnt-meet-ghost-requirement": "数据库 {database} 不符合 gh-ost 的要求"
}
},
"advice-split-statement-to-single-online-migration-issue": "建议将该语句拆分成单独的在线大表变更工单。"
diff --git a/frontend/src/views/project/ProjectPlanDetail.vue b/frontend/src/views/project/ProjectPlanDetail.vue
index 9da0cb179b..be170ccadb 100644
--- a/frontend/src/views/project/ProjectPlanDetail.vue
+++ b/frontend/src/views/project/ProjectPlanDetail.vue
@@ -1,5 +1,5 @@
<template>
- <div class="-mx-4 relative overflow-x-hidden">
+ <div class="-mx-4 relative overflow-x-hidden h-full">
<template v-if="ready">
<PlanDetailPage />
</template>