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: rollback schema (#14060)
ecmadaoca7e079d463b
diff --git a/frontend/src/components/Database/DatabaseChangeHistoryPanel.vue b/frontend/src/components/Database/DatabaseChangeHistoryPanel.vueindex f29754f84f..40d2d74384 100644--- a/frontend/src/components/Database/DatabaseChangeHistoryPanel.vue+++ b/frontend/src/components/Database/DatabaseChangeHistoryPanel.vue@@ -38,6 +38,24 @@</div></template></TooltipButton>+ <TooltipButton+ v-if="allowAlterSchema"+ tooltip-mode="DISABLED-ONLY"+ :disabled="+ !selectedChangeHistory ||+ getHistoryChangeType(selectedChangeHistory.type) !== 'DDL'+ "+ @click="rollback"+ >+ <template #default>+ {{ $t("common.rollback") }}+ </template>+ <template #tooltip>+ <div class="whitespace-pre-line">+ {{ $t("change-history.rollback-tip") }}+ </div>+ </template>+ </TooltipButton><TooltipButtonv-if="allowEstablishBaseline"tooltip-mode="DISABLED-ONLY"@@ -139,7 +157,10 @@ import {import { useDatabaseDetailContext } from "@/components/Database/context";import { TooltipButton } from "@/components/v2";import { Drawer, DrawerContent } from "@/components/v2";-import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";+import {+ PROJECT_V1_ROUTE_ISSUE_DETAIL,+ PROJECT_V1_ROUTE_SYNC_SCHEMA,+} from "@/router/dashboard/projectV1";import { useChangeHistoryStore, useDBSchemaV1Store } from "@/store";import { DEFAULT_PAGE_SIZE } from "@/store/modules/common";import type { ComposedDatabase } from "@/types";@@ -150,7 +171,7 @@ import {ChangeHistory_Type,ChangeHistoryView,} from "@/types/proto/v1/database_service";-import { extractProjectResourceName } from "@/utils";+import { extractProjectResourceName, getHistoryChangeType } from "@/utils";interface LocalState {showBaselineModal: boolean;@@ -210,6 +231,32 @@ const changeHistoryList = computed(() => {return changeHistoryStore.changeHistoryListByDatabase(props.database.name);});+const selectedChangeHistory = computed(() => {+ if (state.selectedChangeHistoryNameList.length !== 1) {+ return;+ }+ return changeHistoryStore.getChangeHistoryByName(+ state.selectedChangeHistoryNameList[0]+ );+});++const rollback = () => {+ if (!selectedChangeHistory.value) {+ return;+ }++ router.push({+ name: PROJECT_V1_ROUTE_SYNC_SCHEMA,+ params: {+ projectId: extractProjectResourceName(props.database.project),+ },+ query: {+ version: selectedChangeHistory.value.name,+ target: props.database.name,+ },+ });+};+const handleExportChangeHistory = async () => {if (state.isExporting) {return;diff --git a/frontend/src/components/Instance/InstanceSyncButton.vue b/frontend/src/components/Instance/InstanceSyncButton.vueindex 03e031676f..b5d9a823c0 100644--- a/frontend/src/components/Instance/InstanceSyncButton.vue+++ b/frontend/src/components/Instance/InstanceSyncButton.vue@@ -40,8 +40,8 @@ import { hasWorkspacePermissionV2 } from "@/utils";withDefaults(defineProps<{- type: "default" | "primary";- size: "small" | "medium";+ type?: "default" | "primary";+ size?: "small" | "medium";disabled?: boolean;quaternary?: boolean;}>(),diff --git a/frontend/src/components/SyncDatabaseSchema/DatabaseSchemaSelector.vue b/frontend/src/components/SyncDatabaseSchema/DatabaseSchemaSelector.vueindex bfb45c8db4..bd80d2d898 100644--- a/frontend/src/components/SyncDatabaseSchema/DatabaseSchemaSelector.vue+++ b/frontend/src/components/SyncDatabaseSchema/DatabaseSchemaSelector.vue@@ -418,15 +418,17 @@ watch(allowedMigrationTypeList.includes(changeHistory.type));- if (changeHistoryList.length > 0) {- // Default select the first migration history.- state.changeHistoryName = head(changeHistoryList)?.name;- } else {- // If database has no migration history, we will use its latest schema.- state.changeHistoryName = mockLatestSchemaChangeHistory(- database,- undefined- ).name;+ if (!state.changeHistoryName) {+ if (changeHistoryList.length > 0) {+ // Default select the first migration history.+ state.changeHistoryName = head(changeHistoryList)?.name;+ } else {+ // If database has no migration history, we will use its latest schema.+ state.changeHistoryName = mockLatestSchemaChangeHistory(+ database,+ undefined+ ).name;+ }}} finally {isPreparingSchemaVersionOptions.value = false;@@ -434,7 +436,8 @@ watch(} else {state.changeHistoryName = undefined;}- }+ },+ { immediate: true });watch(diff --git a/frontend/src/components/SyncDatabaseSchema/SelectTargetDatabasesView.vue b/frontend/src/components/SyncDatabaseSchema/SelectTargetDatabasesView.vueindex 10f9406ab9..a68f07735e 100644--- a/frontend/src/components/SyncDatabaseSchema/SelectTargetDatabasesView.vue+++ b/frontend/src/components/SyncDatabaseSchema/SelectTargetDatabasesView.vue@@ -185,7 +185,7 @@v-show="selectedDatabase":statement="state.selectedDatabaseName- ? databaseDiffCache[state.selectedDatabaseName].edited+ ? (databaseDiffCache[state.selectedDatabaseName]?.edited ?? ''): ''":engine="engine"@@ -284,6 +284,7 @@ const props = defineProps<{sourceSchemaType: SourceSchemaType;databaseSourceSchema?: DatabaseSourceSchema;rawSqlState?: RawSQLState;+ targetDatabaseNameList?: string[];}>();const { t } = useI18n();@@ -450,6 +451,16 @@ const handleSelectedDatabaseNameListChanged = (databaseNameList: string[]) => {state.showSelectDatabasePanel = false;};+watch(+ () => props.targetDatabaseNameList,+ () => {+ handleSelectedDatabaseNameListChanged(props.targetDatabaseNameList ?? []);+ },+ {+ immediate: true,+ }+);+const handleUnselectDatabase = (database: ComposedDatabase) => {state.selectedDatabaseNameList = state.selectedDatabaseNameList.filter((name) => name !== database.namediff --git a/frontend/src/components/SyncDatabaseSchema/index.vue b/frontend/src/components/SyncDatabaseSchema/index.vueindex 5cb32635c1..138f510f6c 100644--- a/frontend/src/components/SyncDatabaseSchema/index.vue+++ b/frontend/src/components/SyncDatabaseSchema/index.vue@@ -55,6 +55,7 @@:source-schema-type="state.sourceSchemaType":database-source-schema="changeHistorySourceSchemaState as any":raw-sql-state="rawSQLState"+ :target-database-name-list="targetDatabaseList"/></template></StepTab>@@ -66,7 +67,7 @@ import { isUndefined } from "lodash-es";import type { ButtonProps } from "naive-ui";import { NRadioGroup, NRadio, useDialog } from "naive-ui";import { v4 as uuidv4 } from "uuid";-import { computed, reactive, ref } from "vue";+import { computed, reactive, ref, watchEffect } from "vue";import { useI18n } from "vue-i18n";import { useRouter } from "vue-router";import { StepTab } from "@/components/v2";@@ -104,6 +105,8 @@ interface LocalState {const props = defineProps<{project: ComposedProject;sourceSchemaType?: SourceSchemaType;+ source?: ChangeHistorySourceSchema;+ targetDatabaseList?: string[];}>();const { t } = useI18n();@@ -135,6 +138,17 @@ const handleChangeHistorySchemaVersionChanges = (Object.assign(changeHistorySourceSchemaState, schemaVersion);};+const autoNext = ref<boolean>(true);+watchEffect(() => {+ if (props.source) {+ handleChangeHistorySchemaVersionChanges(props.source);+ if (autoNext.value) {+ state.currentStep = SELECT_TARGET_DATABASE_LIST;+ autoNext.value = false;+ }+ }+});+const stepTabList = computed(() => {return [{ title: t("database.sync-schema.select-source-schema") },diff --git a/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseOperations.vue b/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseOperations.vueindex 1f8ba2f260..ff48c2f9f0 100644--- a/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseOperations.vue+++ b/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseOperations.vue@@ -361,127 +361,131 @@ const isInDefaultProject = computed(const actions = computed((): DatabaseAction[] => {const resp: DatabaseAction[] = [];- if (operations.value.has("EXPORT-DATA")) {- resp.push({- icon: h(DownloadIcon),- text: t("custom-approval.risk-rule.risk.namespace.data_export"),- disabled: !allowExportData.value || props.databases.length !== 1,- click: () => generateMultiDb("bb.issue.database.data.export"),- tooltip: (action) => {- if (!allowExportData.value) {- return t("database.batch-action-permission-denied", {- action,+ for (const operation of operations.value) {+ switch (operation) {+ case "EXPORT-DATA":+ resp.push({+ icon: h(DownloadIcon),+ text: t("custom-approval.risk-rule.risk.namespace.data_export"),+ disabled: !allowExportData.value || props.databases.length !== 1,+ click: () => generateMultiDb("bb.issue.database.data.export"),+ tooltip: (action) => {+ if (!allowExportData.value) {+ return t("database.batch-action-permission-denied", {+ action,+ });+ }+ if (props.databases.length > 1) {+ return t("database.data-export-action-disabled");+ }+ return "";+ },+ });+ break;+ case "SYNC-SCHEMA":+ resp.push({+ icon: h(RefreshCcwIcon),+ text: t("common.sync"),+ disabled: !allowSyncDatabases.value || props.databases.length < 1,+ click: syncSchema,+ tooltip: (action) => getDisabledTooltip(action),+ });+ break;+ case "EDIT-LABELS":+ resp.push({+ icon: h(TagIcon),+ text: t("database.edit-labels"),+ disabled: !allowEditLabels.value || props.databases.length < 1,+ click: () => (state.showLabelEditorDrawer = true),+ tooltip: (action) => {+ if (!allowEditLabels.value) {+ return t("database.batch-action-permission-denied", {+ action,+ });+ }+ return getDisabledTooltip(action);+ },+ });+ break;+ case "TRANSFER":+ if (!operationsInProjectDetail.value) {+ resp.push({+ icon: h(ArrowRightLeftIcon),+ text: t("database.transfer-project"),+ disabled: !allowTransferProject.value || props.databases.length < 1,+ click: () => (state.showTransferOutDatabaseForm = true),+ tooltip: (action) => {+ if (!allowTransferProject.value) {+ return t("database.batch-action-permission-denied", {+ action,+ });+ }+ return getDisabledTooltip(action);+ },});- }- if (props.databases.length > 1) {- return t("database.data-export-action-disabled");- }- return "";- },- });- }- if (operations.value.has("SYNC-SCHEMA")) {- resp.push({- icon: h(RefreshCcwIcon),- text: t("common.sync"),- disabled: !allowSyncDatabases.value || props.databases.length < 1,- click: syncSchema,- tooltip: (action) => getDisabledTooltip(action),- });- }- if (operations.value.has("EDIT-LABELS")) {- resp.push({- icon: h(TagIcon),- text: t("database.edit-labels"),- disabled: !allowEditLabels.value || props.databases.length < 1,- click: () => (state.showLabelEditorDrawer = true),- tooltip: (action) => {- if (!allowEditLabels.value) {- return t("database.batch-action-permission-denied", {- action,+ } else if (!isInDefaultProject.value) {+ resp.push({+ icon: h(UnlinkIcon),+ text: t("database.unassign"),+ disabled: !allowTransferProject.value || props.databases.length < 1,+ click: () => (state.showUnassignAlert = true),+ tooltip: (action) => {+ if (!allowTransferProject.value) {+ return t("database.batch-action-permission-denied", {+ action,+ });+ }+ return getDisabledTooltip(action);+ },});}- return getDisabledTooltip(action);- },- });- }- if (operations.value.has("TRANSFER")) {- if (!operationsInProjectDetail.value) {- resp.push({- icon: h(ArrowRightLeftIcon),- text: t("database.transfer-project"),- disabled: !allowTransferProject.value || props.databases.length < 1,- click: () => (state.showTransferOutDatabaseForm = true),- tooltip: (action) => {- if (!allowTransferProject.value) {- return t("database.batch-action-permission-denied", {- action,- });- }- return getDisabledTooltip(action);- },- });- } else if (!isInDefaultProject.value) {- resp.push({- icon: h(UnlinkIcon),- text: t("database.unassign"),- disabled: !allowTransferProject.value || props.databases.length < 1,- click: () => (state.showUnassignAlert = true),- tooltip: (action) => {- if (!allowTransferProject.value) {- return t("database.batch-action-permission-denied", {- action,- });- }- return getDisabledTooltip(action);- },- });+ break;+ case "CHANGE-DATA":+ resp.push({+ icon: h(PencilIcon),+ text: t("database.change-data"),+ disabled:+ !allowChangeData.value ||+ !selectedProjectName.value ||+ props.databases.length < 1 ||+ selectedProjectNames.value.has(DEFAULT_PROJECT_NAME),+ click: () => generateMultiDb("bb.issue.database.data.update"),+ tooltip: (action) => {+ if (!allowChangeData.value) {+ return t("database.batch-action-permission-denied", {+ action,+ });+ }+ return getDisabledTooltip(action);+ },+ });+ break;+ case "EDIT-SCHEMA":+ resp.push({+ icon: h(PenSquareIcon),+ text: t("database.edit-schema"),+ disabled:+ !databaseSupportAlterSchema.value ||+ !allowEditSchema.value ||+ !selectedProjectName.value ||+ props.databases.length < 1 ||+ selectedProjectNames.value.has(DEFAULT_PROJECT_NAME),+ click: () => generateMultiDb("bb.issue.database.schema.update"),+ tooltip: (action) => {+ if (!databaseSupportAlterSchema.value) {+ return t("database.batch-action-not-support-alter-schema");+ }+ if (!allowEditSchema.value) {+ return t("database.batch-action-permission-denied", {+ action,+ });+ }+ return getDisabledTooltip(action);+ },+ });+ break;}}- if (operations.value.has("CHANGE-DATA")) {- resp.unshift({- icon: h(PencilIcon),- text: t("database.change-data"),- disabled:- !allowChangeData.value ||- !selectedProjectName.value ||- props.databases.length < 1 ||- selectedProjectNames.value.has(DEFAULT_PROJECT_NAME),- click: () => generateMultiDb("bb.issue.database.data.update"),- tooltip: (action) => {- if (!allowChangeData.value) {- return t("database.batch-action-permission-denied", {- action,- });- }- return getDisabledTooltip(action);- },- });- }- if (operations.value.has("EDIT-SCHEMA")) {- resp.unshift({- icon: h(PenSquareIcon),- text: t("database.edit-schema"),- disabled:- !databaseSupportAlterSchema.value ||- !allowEditSchema.value ||- !selectedProjectName.value ||- props.databases.length < 1 ||- selectedProjectNames.value.has(DEFAULT_PROJECT_NAME),- click: () => generateMultiDb("bb.issue.database.schema.update"),- tooltip: (action) => {- if (!databaseSupportAlterSchema.value) {- return t("database.batch-action-not-support-alter-schema");- }- if (!allowEditSchema.value) {- return t("database.batch-action-permission-denied", {- action,- });- }- return getDisabledTooltip(action);- },- });- }return resp;});diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 0fce0d9dc4..e67fcb7c52 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -1757,7 +1757,8 @@"all-tables": "All tables","affected-tables": "Affected Tables","select-affection-tables": "Select affected tables",- "view-full": "View full"+ "view-full": "View full",+ "rollback-tip": "Select a specific DDL history to rollback."},"database": {"sync-database": "Sync database",diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex f6e6f02974..aebc8ec218 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -1757,7 +1757,8 @@"all-tables": "Todas las tablas","affected-tables": "Tablas afectadas","select-affection-tables": "Seleccionar tablas afectadas",- "view-full": "Ver completo"+ "view-full": "Ver completo",+ "rollback-tip": "Seleccione un historial de DDL específico para revertir."},"database": {"sync-database": "Sincronizar base de datos",@@ -3790,4 +3791,4 @@"setup": {"self": "Configuración"}-}+}\ No newline at end of filediff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex d3569b856a..cbfcb32693 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -1757,7 +1757,8 @@"all-tables": "すべてのテーブル","affected-tables": "影響を受けるテーブル","select-affection-tables": "影響を受けるテーブルを選択",- "view-full": "すべて見る"+ "view-full": "すべて見る",+ "rollback-tip": "ロールバックする特定の DDL 履歴を選択します。"},"database": {"sync-database": "データベースを同期",@@ -3790,4 +3791,4 @@"setup": {"self": "設定"}-}+}\ No newline at end of filediff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 1a552072ef..cd8fd81508 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -1757,7 +1757,8 @@"all-tables": "所有表","affected-tables": "受影响的表","select-affection-tables": "选择受影响的表",- "view-full": "查看全部"+ "view-full": "查看全部",+ "rollback-tip": "选择要回滚到的某个 DDL 历史记录。"},"database": {"sync-database": "同步数据库",diff --git a/frontend/src/views/project/ProjectSyncDatabasePanel.vue b/frontend/src/views/project/ProjectSyncDatabasePanel.vueindex 91810caef0..c87a4763a2 100644--- a/frontend/src/views/project/ProjectSyncDatabasePanel.vue+++ b/frontend/src/views/project/ProjectSyncDatabasePanel.vue@@ -1,17 +1,92 @@<template>- <SyncDatabaseSchema :key="project.name" :project="project" />+ <SyncDatabaseSchema+ :key="project.name"+ :project="project"+ :source="source"+ :source-schema-type="source ? 'SCHEMA_HISTORY_VERSION' : undefined"+ :target-database-list="targetDatabaseList"+ /></template><script setup lang="ts">-import { computed } from "vue";+import { computed, ref, onMounted } from "vue";+import { useRoute } from "vue-router";import SyncDatabaseSchema from "@/components/SyncDatabaseSchema/index.vue";-import { useProjectByName } from "@/store";+import { type ChangeHistorySourceSchema } from "@/components/SyncDatabaseSchema/types";+import {+ useProjectByName,+ useDatabaseV1Store,+ useChangeHistoryStore,+} from "@/store";import { projectNamePrefix } from "@/store/modules/v1/common";+import { UNKNOWN_DATABASE_NAME } from "@/types";+import { ChangeHistoryView } from "@/types/proto/v1/database_service";+import { extractDatabaseNameAndChangeHistoryUID } from "@/utils";const props = defineProps<{projectId: string;}>();+const route = useRoute();+const changeHistoryStore = useChangeHistoryStore();+const databaseStore = useDatabaseV1Store();+const targetDatabaseList = ref<string[]>([]);++const changeHistoryVersion = computed(() => {+ const version = route.query.version as string;+ return version || "";+});++const changeHistory = computed(() => {+ if (!changeHistoryVersion.value) {+ return;+ }+ return changeHistoryStore.getChangeHistoryByName(changeHistoryVersion.value);+});++onMounted(async () => {+ if (!changeHistoryVersion.value) {+ return;+ }+ const history = await changeHistoryStore.getOrFetchChangeHistoryByName(+ changeHistoryVersion.value,+ ChangeHistoryView.CHANGE_HISTORY_VIEW_FULL+ );+ if (!history) {+ return;+ }+ const { databaseName } = extractDatabaseNameAndChangeHistoryUID(history.name);+ await databaseStore.getOrFetchDatabaseByName(databaseName);++ const target = route.query.target as string;+ const databaseList = (target || "").split(",").filter((n) => n);++ const databaseNameList = [];+ for (const dbName of databaseList) {+ const database = await databaseStore.getOrFetchDatabaseByName(dbName);+ if (database.name !== UNKNOWN_DATABASE_NAME) {+ databaseNameList.push(databaseName);+ }+ }+ targetDatabaseList.value = databaseNameList;+});++const source = computed((): ChangeHistorySourceSchema | undefined => {+ if (!changeHistory.value) {+ return;+ }+ const { databaseName } = extractDatabaseNameAndChangeHistoryUID(+ changeHistory.value.name+ );+ const database = databaseStore.getDatabaseByName(databaseName);+ return {+ databaseName,+ changeHistory: changeHistory.value,+ environmentName: database.effectiveEnvironment,+ projectName: database.project,+ };+});+const { project } = useProjectByName(computed(() => `${projectNamePrefix}${props.projectId}`));