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/migration-history-detail): show baseline change when drift detected (#577)
qsliu93a4f64b2e34
diff --git a/frontend/src/locales/en.yml b/frontend/src/locales/en.ymlindex dda95d2b27..56cea92c85 100644--- a/frontend/src/locales/en.yml+++ b/frontend/src/locales/en.yml@@ -636,6 +636,11 @@ migration-history:workflow: Workflowcommit-info: by {author} at {time}no-schema-change: this migration has no schema change+ schema-drift: Schema drift detected+ before-left-schema-choice: Compare the schema+ left-schema-choice-prev-history-schema: after prev migration+ left-schema-choice-current-history-schema-prev: before this migration+ after-left-schema-choice: and after this migrationshow-diff: Show diffleft-vs-right: Prev (left) vs This version (right)schema-snapshot-after-migration: The schema snapshot recorded after applying this migrationdiff --git a/frontend/src/locales/zh-CN.yml b/frontend/src/locales/zh-CN.ymlindex 334e4381f8..edb4107908 100644--- a/frontend/src/locales/zh-CN.yml+++ b/frontend/src/locales/zh-CN.yml@@ -582,6 +582,11 @@ migration-history:workflow: 工作流commit-info: 由 {author} 于 {time}no-schema-change: 本次迁移没有任何 Schema 的改动+ schema-drift: 上次迁移后的 Schema 与本次迁移前不一致+ before-left-schema-choice: 比较+ left-schema-choice-prev-history-schema: 上次迁移后+ left-schema-choice-current-history-schema-prev: 本次迁移前+ after-left-schema-choice: 和本次迁移后的 Schemashow-diff: 显示差异left-vs-right: 之前 (左) vs 当前版本 (右)schema-snapshot-after-migration: 完成这次迁移后的 schema 快照diff --git a/frontend/src/views/MigrationHistoryDetail.vue b/frontend/src/views/MigrationHistoryDetail.vueindex 66a7284295..1e38b0b35a 100644--- a/frontend/src/views/MigrationHistoryDetail.vue+++ b/frontend/src/views/MigrationHistoryDetail.vue@@ -122,9 +122,50 @@<heroicons-outline:clipboard class="w-6 h-6" /></button></a>++ <div v-if="hasDrift" class="flex flex-row items-center space-x-2 mt-2">+ <div class="text-sm font-normal text-accent">+ ({{ $t("migration-history.schema-drift") }})+ </div>+ <span class="textinfolabel">+ {{ $t("migration-history.before-left-schema-choice") }}+ </span>+ <div>+ <BBSelect+ :selected-item="state.leftSelected"+ :item-list="['previousHistorySchema', 'currentHistorySchemaPrev']"+ @select-item="+ (value) => {+ state.leftSelected = value;+ state.leftSchema =+ state.leftSelected === 'previousHistorySchema'+ ? previousHistorySchema+ : migrationHistory.schemaPrev;+ state.showDiff = state.leftSchema !== state.rightSchema;+ }+ "+ >+ <template #menuItem="{ item: value }">+ {{+ value === "previousHistorySchema"+ ? $t(+ "migration-history.left-schema-choice-prev-history-schema"+ )+ : $t(+ "migration-history.left-schema-choice-current-history-schema-prev"+ )+ }}+ </template>+ </BBSelect>+ </div>+ <span class="textinfolabel">+ {{ $t("migration-history.after-left-schema-choice") }}+ </span>+ </div>+<div class="flex flex-row items-center space-x-2 mt-2"><BBSwitch- v-if="migrationHistory.schemaPrev != migrationHistory.schema"+ v-if="state.leftSchema !== state.rightSchema":label="$t('migration-history.show-diff')":value="state.showDiff"@toggle="@@ -141,7 +182,7 @@}}</div><div- v-if="migrationHistory.schemaPrev == migrationHistory.schema"+ v-if="state.leftSchema === state.rightSchema"class="text-sm font-normal text-accent">({{ $t("migration-history.no-schema-change") }})@@ -150,8 +191,8 @@<code-diffv-if="state.showDiff"class="mt-4 w-full"- :old-string="migrationHistory.schemaPrev"- :new-string="migrationHistory.schema"+ :old-string="state.leftSchema"+ :new-string="state.rightSchema"output-format="side-by-side"/><div@@ -174,18 +215,30 @@ import { CodeDiff } from "v-code-diff";import MigrationHistoryStatusIcon from "../components/MigrationHistoryStatusIcon.vue";import { idFromSlug, nanosecondsToString } from "../utils";import {+ Database,MigrationHistory,MigrationHistoryPayload,VCSPushEvent,} from "../types";+import { BBSelect } from "../bbkit";++type LeftSchemaSelected =+ | "previousHistorySchema" // schema after last migration+ | "currentHistorySchemaPrev"; // schema before this migrationinterface LocalState {showDiff: boolean;+ leftSelected: LeftSchemaSelected;+ // leftSchema is the schema snapshot at the left side of the diff.+ // Default to migrationHistory.schemaPrev. If drift is detected, it can be selected to be lastRecordedSchema.+ leftSchema: string;+ // rightSchema is the schema snapshot at the right side of the diff. Always migrationHistory.schema.+ rightSchema: string;}export default defineComponent({name: "MigrationHistoryDetail",- components: { CodeDiff, MigrationHistoryStatusIcon },+ components: { CodeDiff, MigrationHistoryStatusIcon, BBSelect },props: {databaseSlug: {required: true,@@ -199,21 +252,48 @@ export default defineComponent({setup(props) {const store = useStore();+ const database = computed((): Database => {+ return store.getters["database/databaseById"](+ idFromSlug(props.databaseSlug)+ );+ });++ // get all migration histories before (include) the one of given id, ordered by descending version.+ const prevMigrationHistoryList = computed((): MigrationHistory[] => {+ const migrationHistoryList: MigrationHistory[] = store.getters[+ "instance/migrationHistoryListByInstanceIdAndDatabaseName"+ ](database.value.instance.id, database.value.name);+ return migrationHistoryList.filter(+ (mh) => mh.id <= idFromSlug(props.migrationHistorySlug)+ );+ });+const migrationHistory = computed((): MigrationHistory => {+ if (prevMigrationHistoryList.value.length > 0)+ return prevMigrationHistoryList.value[0];return store.getters["instance/migrationHistoryById"](idFromSlug(props.migrationHistorySlug)- );+ ) as MigrationHistory;});+ // previousHistorySchema is the schema snapshot of the last migration history before the one of given id.+ // Only referenced if hasDrift is true.+ const previousHistorySchema = computed(+ (): string => prevMigrationHistoryList.value[1].schema+ );++ const hasDrift = computed(+ (): boolean =>+ prevMigrationHistoryList.value.length > 1 && // no drift if no previous migration history+ previousHistorySchema.value !== migrationHistory.value.schemaPrev+ );+const state = reactive<LocalState>({showDiff:migrationHistory.value.schema != migrationHistory.value.schemaPrev,- });-- const database = computed(() => {- return store.getters["database/databaseById"](- idFromSlug(props.databaseSlug)- );+ leftSelected: "currentHistorySchemaPrev",+ leftSchema: migrationHistory.value.schemaPrev,+ rightSchema: migrationHistory.value.schema,});const pushEvent = computed((): VCSPushEvent | undefined => {@@ -265,6 +345,8 @@ export default defineComponent({nanosecondsToString,database,migrationHistory,+ previousHistorySchema,+ hasDrift,pushEvent,vcsBranch,vcsBranchUrl,