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: add affected tables in change history (#7413)
boojack5d14b6e75b0c
diff --git a/frontend/src/components/ChangeHistory/ChangeHistoryTable.vue b/frontend/src/components/ChangeHistory/ChangeHistoryTable.vueindex cec8e1b71b..253d7cc1ab 100644--- a/frontend/src/components/ChangeHistory/ChangeHistoryTable.vue+++ b/frontend/src/components/ChangeHistory/ChangeHistoryTable.vue@@ -24,9 +24,10 @@<BBTableHeaderCell class="w-56" :title="columnList[3].title" /><BBTableHeaderCell class="w-16" :title="columnList[4].title" /><BBTableHeaderCell :title="columnList[5].title" />- <BBTableHeaderCell class="w-28" :title="columnList[6].title" />+ <BBTableHeaderCell :title="columnList[6].title" /><BBTableHeaderCell class="w-28" :title="columnList[7].title" /><BBTableHeaderCell class="w-28" :title="columnList[8].title" />+ <BBTableHeaderCell class="w-28" :title="columnList[9].title" /></template><template v-else><BBTableHeaderCell@@ -83,9 +84,20 @@</router-link></template></BBTableCell>+ <BBTableCell v-if="mode === 'DATABASE'">+ <TextOverflowPopover+ :content="+ getAffectedTablesOfChangeHistory(history)+ .map(getAffectedTableDisplayName)+ .join(', ')+ "+ :max-length="100"+ placement="bottom"+ />+ </BBTableCell><BBTableCell>- <SQLPreviewPopover- :statement="history.statement"+ <TextOverflowPopover+ :content="history.statement":max-length="100"placement="bottom"/>@@ -116,8 +128,9 @@ import {humanizeDate,extractUserResourceName,changeHistoryLink,+ getAffectedTablesOfChangeHistory,} from "@/utils";-import SQLPreviewPopover from "@/components/misc/SQLPreviewPopover.vue";+import TextOverflowPopover from "@/components/misc/TextOverflowPopover.vue";import ChangeHistoryStatusIcon from "./ChangeHistoryStatusIcon.vue";import {ChangeHistory,@@ -127,6 +140,7 @@ import {changeHistory_TypeToJSON,} from "@/types/proto/v1/database_service";import { useUserStore } from "@/store";+import { AffectedTable } from "@/types/changeHistory";type Mode = "DATABASE" | "PROJECT";@@ -163,6 +177,9 @@ const columnList = computed(() => {{title: t("common.issue"),},+ {+ title: t("db.tables"),+ },{title: "SQL",},@@ -213,6 +230,18 @@ const creatorOfChangeHistory = (history: ChangeHistory) => {return useUserStore().getUserByEmail(email);};+const getAffectedTableDisplayName = (affectedTable: AffectedTable) => {+ const { schema, table, dropped } = affectedTable;+ let name = table;+ if (schema !== "") {+ name = `${schema}.${table}`;+ }+ if (dropped) {+ name = `${name} (deleted)`;+ }+ return name;+};+const allSelectionState = computed(() => {const set = props.selectedChangeHistoryNameList || [];const list = props.historySectionListdiff --git a/frontend/src/components/DatabaseChangeHistoryPanel.vue b/frontend/src/components/DatabaseChangeHistoryPanel.vueindex f9d0e814ff..2cd297faf7 100644--- a/frontend/src/components/DatabaseChangeHistoryPanel.vue+++ b/frontend/src/components/DatabaseChangeHistoryPanel.vue@@ -10,7 +10,21 @@:title="$t('change-history.refreshing-history')"/></div>- <div class="flex flex-row justify-end items-center space-x-2">+ <div class="flex flex-row justify-end items-center grow space-x-2">+ <div class="w-40">+ <BBSelect+ :selected-item="state.selectedAffectedTable"+ :item-list="affectedTables"+ :show-prefix-item="false"+ @select-item="(item: AffectedTable) => state.selectedAffectedTable = item"+ >+ <template #menuItem="{ item }">+ <span :class="item.dropped && 'text-gray-400'">+ {{ getAffectedTableDisplayName(item) }}+ </span>+ </template>+ </BBSelect>+ </div><BBTooltipButtonv-if="showEstablishBaselineButton"type="normal"@@ -87,8 +101,11 @@ import { useRouter } from "vue-router";import { BBTooltipButton } from "@/bbkit";import { ComposedDatabase, DEFAULT_PROJECT_V1_NAME } from "@/types";import { BBTableSectionDataSource } from "@/bbkit/types";-import { instanceV1HasAlterSchema } from "@/utils";-import { useChangeHistoryStore } from "@/store";+import {+ getAffectedTablesOfChangeHistory,+ instanceV1HasAlterSchema,+} from "@/utils";+import { useChangeHistoryStore, useDBSchemaV1Store } from "@/store";import { TenantMode } from "@/types/proto/v1/project_service";import {ChangeHistory,@@ -98,12 +115,21 @@ import {} from "@/types/proto/v1/database_service";import { ChangeHistoryTable } from "@/components/ChangeHistory";import dayjs from "dayjs";+import { AffectedTable } from "@/types/changeHistory";+import { isEqual, orderBy } from "lodash-es";++const EmptyAffectedTable: AffectedTable = {+ schema: "",+ table: "",+ dropped: false,+};interface LocalState {showBaselineModal: boolean;loading: boolean;selectedChangeHistoryNameList: string[];isExporting: boolean;+ selectedAffectedTable: AffectedTable;}const props = defineProps({@@ -127,17 +153,17 @@ const state = reactive<LocalState>({loading: false,selectedChangeHistoryNameList: [],isExporting: false,+ selectedAffectedTable: EmptyAffectedTable,});-const prepareChangeHistoryList = () => {+const prepareChangeHistoryList = async () => {state.loading = true;- changeHistoryStore- .fetchChangeHistoryList({- parent: props.database.name,- })- .finally(() => {- state.loading = false;- });+ await changeHistoryStore.fetchChangeHistoryList({+ parent: props.database.name,+ });+ // prepare database metadata for getting affected tables.+ await useDBSchemaV1Store().getOrFetchDatabaseMetadata(props.database.name);+ state.loading = false;};onBeforeMount(prepareChangeHistoryList);@@ -177,17 +203,59 @@ const changeHistoryList = computed(() => {return changeHistoryStore.changeHistoryListByDatabase(props.database.name);});+const shownChangeHistoryList = computed(() => {+ return changeHistoryList.value.filter((changeHistory) => {+ if (+ state.selectedAffectedTable &&+ !isEqual(state.selectedAffectedTable, EmptyAffectedTable)+ ) {+ const affectedTables = getAffectedTablesOfChangeHistory(changeHistory);+ return affectedTables.find((item) =>+ isEqual(item, state.selectedAffectedTable)+ );+ }+ return true;+ });+});+const changeHistorySectionList = computed((): BBTableSectionDataSource<ChangeHistory>[] => {return [{title: "",- list: changeHistoryList.value,+ list: shownChangeHistoryList.value,},];});+const affectedTables = computed(() => {+ return [+ EmptyAffectedTable,+ ...orderBy(+ changeHistoryList.value+ .map((changeHistory) => getAffectedTablesOfChangeHistory(changeHistory))+ .flat(),+ ["dropped"]+ ),+ ];+});++const getAffectedTableDisplayName = (affectedTable: AffectedTable) => {+ if (isEqual(affectedTable, EmptyAffectedTable)) {+ return t("change-history.all-tables");+ }+ const { schema, table, dropped } = affectedTable;+ let name = table;+ if (schema !== "") {+ name = `${schema}.${table}`;+ }+ if (dropped) {+ name = `${name} (deleted)`;+ }+ return name;+};+const handleExportChangeHistory = async () => {if (state.isExporting) {return;diff --git a/frontend/src/components/Issue/activity/ActionSentence.vue b/frontend/src/components/Issue/activity/ActionSentence.vueindex e6c756bc72..6b515e4fb6 100644--- a/frontend/src/components/Issue/activity/ActionSentence.vue+++ b/frontend/src/components/Issue/activity/ActionSentence.vue@@ -25,7 +25,7 @@ import {} from "@/utils";import { useSheetV1Store, useSheetStatementByUID } from "@/store";import TaskName from "./TaskName.vue";-import SQLPreviewPopover from "@/components/misc/SQLPreviewPopover.vue";+import TextOverflowPopover from "@/components/misc/TextOverflowPopover.vue";import StageName from "./StageName.vue";import { LogEntity, LogEntity_Action } from "@/types/proto/v1/logging_service";import { extractUserResourceName } from "@/utils";@@ -289,11 +289,11 @@ const Renderer = defineComponent({});const renderStatement = (statement: string) => {- return h(SQLPreviewPopover, {- statement,+ return h(TextOverflowPopover, {+ content: statement,maxLength: 50,width: 400,- statementClass: "text-main",+ contentClass: "text-main",});};diff --git a/frontend/src/components/TableDetailDrawer.vue b/frontend/src/components/TableDetailDrawer.vueindex 32d7b94dac..ec54249f2a 100644--- a/frontend/src/components/TableDetailDrawer.vue+++ b/frontend/src/components/TableDetailDrawer.vue@@ -8,7 +8,7 @@><NDrawerContentclass="w-[calc(100vw-256px)]"- :title="$t('schema-designer.quick-action')"+ :title="$t('database.table-detail')":closable="true"><divdiff --git a/frontend/src/components/misc/SQLPreviewPopover.vue b/frontend/src/components/misc/SQLPreviewPopover.vuedeleted file mode 100644index f4cd2a0d77..0000000000--- a/frontend/src/components/misc/SQLPreviewPopover.vue+++ /dev/null@@ -1,50 +0,0 @@-<template>- <NPopover- :disabled="statement.length <= maxLength"- :placement="placement"- style="max-height: 300px"- width="trigger"- scrollable- >- <highlight-code-block :code="statement" class="whitespace-pre-wrap" />-- <template #trigger>- <span :class="statementClass">- {{- statement.length <= maxLength- ? statement- : statement.substring(0, maxLength) + "..."- }}- </span>- </template>- </NPopover>-</template>--<script lang="ts">-import { defineComponent, PropType } from "vue";-import { NPopover, PopoverPlacement } from "naive-ui";-import { VueClass } from "@/utils";--export default defineComponent({- name: "SQLPreviewPopover",- components: { NPopover },- props: {- statement: {- type: String,- default: "",- },- maxLength: {- type: Number,- default: 100,- },- placement: {- type: String as PropType<PopoverPlacement>,- default: "top",- },- statementClass: {- type: [String, Object, Array] as PropType<VueClass>,- default: undefined,- },- },-});-</script>diff --git a/frontend/src/components/misc/TextOverflowPopover.vue b/frontend/src/components/misc/TextOverflowPopover.vuenew file mode 100644index 0000000000..6df307f849--- /dev/null+++ b/frontend/src/components/misc/TextOverflowPopover.vue@@ -0,0 +1,57 @@+<template>+ <NPopover+ :disabled="content.length <= maxLength"+ :placement="placement"+ style="max-height: 300px"+ width="trigger"+ scrollable+ >+ <highlight-code-block+ v-if="codeMode"+ :code="content"+ class="whitespace-pre-wrap"+ />+ <div v-else class="whitespace-pre-wrap">+ {{ content }}+ </div>++ <template #trigger>+ <span :class="contentClass">+ {{+ content.length <= maxLength+ ? content+ : content.substring(0, maxLength) + "..."+ }}+ </span>+ </template>+ </NPopover>+</template>++<script lang="ts" setup>+import { PropType } from "vue";+import { NPopover, PopoverPlacement } from "naive-ui";+import { VueClass } from "@/utils";++defineProps({+ content: {+ type: String,+ default: "",+ },+ maxLength: {+ type: Number,+ default: 100,+ },+ placement: {+ type: String as PropType<PopoverPlacement>,+ default: "top",+ },+ contentClass: {+ type: [String, Object, Array] as PropType<VueClass>,+ default: undefined,+ },+ codeMode: {+ type: Boolean,+ default: true,+ },+});+</script>diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex f7e1671c6b..b2c319d07c 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -1135,7 +1135,9 @@"instance-bad-connection": "Unable to connect instance \"{name}\" to retrieve change history.","contact-dba": "Please contact your DBA to config it","export": "Export Change History",- "need-to-select-first": "Need to select change history first"+ "need-to-select-first": "Need to select change history first",+ "all-tables": "All tables",+ "affected-tables": "Affected Tables"},"database": {"select": "Select database",@@ -1152,6 +1154,7 @@"change-data": "Change Data","change-data-in-vcs": "Change Data in VCS","design-schema": "Design Schema",+ "table-detail": "Table detail","successfully-transferred-updateddatabase-name-to-project-updateddatabase-project-name": "Successfully transferred '{0}' to project '{1}'.","backup-name": "Backup name","create-backup": "Create backup",diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex 3275c36228..efc9533428 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -1134,7 +1134,9 @@"instance-bad-connection": "No se pudo conectar la instancia \"{name}\" para recuperar el historial de cambios.","contact-dba": "Por favor, contacte a su DBA para configurarlo","export": "Exportar historial de cambios",- "need-to-select-first": "Necesita seleccionar primero el historial de cambios"+ "need-to-select-first": "Necesita seleccionar primero el historial de cambios",+ "all-tables": "Todas las tablas",+ "affected-tables": "Tablas afectadas"},"database": {"select": "Seleccionar base de datos",@@ -1150,6 +1152,7 @@"alter-schema-in-vcs": "Modificar esquema en VCS","change-data": "Cambiar datos","change-data-in-vcs": "Cambiar datos en VCS",+ "table-detail": "Detalle de la tabla","successfully-transferred-updateddatabase-name-to-project-updateddatabase-project-name": "Se transfirió correctamente '{0}' al proyecto '{1}'.","backup-name": "Nombre de la copia de seguridad","create-backup": "Crear copia de seguridad",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex cd3a097020..51b87d27f2 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -1131,7 +1131,9 @@"instance-bad-connection": "无法连接实例「{name}」以获取变更历史。","contact-dba": "请联系您的 DBA 进行配置。","export": "导出变更历史",- "need-to-select-first": "需要先选择变更历史"+ "need-to-select-first": "需要先选择变更历史",+ "all-tables": "所有表",+ "affected-tables": "受影响的表"},"database": {"select": "选择数据库",@@ -1146,6 +1148,7 @@"alter-schema-in-vcs": "变更 Schema (VCS)","change-data": "变更数据","change-data-in-vcs": "变更数据 (VCS)",+ "table-detail": "表详情","successfully-transferred-updateddatabase-name-to-project-updateddatabase-project-name": "成功将'{0}'转移到项目'{1}'。","database-backup": "数据库备份","backup-name": "备份名称",diff --git a/frontend/src/types/changeHistory.ts b/frontend/src/types/changeHistory.tsnew file mode 100644index 0000000000..0765e01e01--- /dev/null+++ b/frontend/src/types/changeHistory.ts@@ -0,0 +1,5 @@+export interface AffectedTable {+ schema: string;+ table: string;+ dropped: boolean;+}diff --git a/frontend/src/utils/v1/changeHistory.ts b/frontend/src/utils/v1/changeHistory.tsindex 458b0a9696..d305241977 100644--- a/frontend/src/utils/v1/changeHistory.ts+++ b/frontend/src/utils/v1/changeHistory.ts@@ -2,12 +2,28 @@ import slug from "slug";import { UNKNOWN_ID } from "@/types";import { ChangeHistory } from "@/types/proto/v1/database_service";import { extractDatabaseResourceName } from "./database";+import { useDBSchemaV1Store, useDatabaseV1Store } from "@/store";+import { isUndefined, orderBy } from "lodash-es";+import { AffectedTable } from "@/types/changeHistory";export const extractChangeHistoryUID = (changeHistorySlug: string) => {const parts = changeHistorySlug.split("-");return parts[parts.length - 1] ?? String(UNKNOWN_ID);};+export const extractDatabaseNameAndChangeHistoryUID = (+ changeHistoryName: string+) => {+ const parts = changeHistoryName.split("/changeHistories/");+ if (parts.length !== 2) {+ throw new Error("Invalid change history name");+ }+ return {+ databaseName: parts[0],+ uid: extractChangeHistoryUID(parts[1]),+ };+};+export const changeHistorySlug = (uid: string, version: string): string => {return [slug(version), uid].join("-");};@@ -18,3 +34,33 @@ export const changeHistoryLink = (changeHistory: ChangeHistory): string => {const parent = `instances/${instance}/databases/${database}`;return `/${parent}/changeHistories/${changeHistorySlug(uid, version)}`;};++export const getAffectedTablesOfChangeHistory = (+ changeHistory: ChangeHistory+): AffectedTable[] => {+ const { databaseName } = extractDatabaseNameAndChangeHistoryUID(+ changeHistory.name+ );+ const database = useDatabaseV1Store().getDatabaseByName(databaseName);+ const metadata = useDBSchemaV1Store().getDatabaseMetadata(database.name);+ return orderBy(+ changeHistory.changedResources?.databases+ .find((db) => db.name === database.databaseName)+ ?.schemas.map((schema) => {+ return schema.tables.map((table) => {+ const dropped = isUndefined(+ metadata.schemas+ .find((s) => s.name === schema.name)+ ?.tables.find((t) => t.name === table.name)+ );+ return {+ schema: schema.name,+ table: table.name,+ dropped,+ };+ });+ })+ .flat() || [],+ ["dropped"]+ );+};diff --git a/frontend/src/views/ChangeHistoryDetail.vue b/frontend/src/views/ChangeHistoryDetail.vueindex e36c22c66e..fa635af506 100644--- a/frontend/src/views/ChangeHistoryDetail.vue+++ b/frontend/src/views/ChangeHistoryDetail.vue@@ -97,11 +97,35 @@</div></div>+ <div v-if="affectedTables.length > 0" class="mt-6 px-4">+ <span class="flex items-center text-lg text-main mt-6 capitalize">+ {{ $t("change-history.affected-tables") }}+ </span>+ <div+ class="w-full flex flex-row justify-start items-center gap-x-3 gap-y-2"+ >+ <div+ v-for="affectedTable in affectedTables"+ :key="`${affectedTable.schema}.${affectedTable.table}`"+ >+ <span+ :class="+ !affectedTable.dropped+ ? 'text-blue-600 cursor-pointer hover:opacity-80'+ : 'text-gray-400 italic'+ "+ @click="handleAffectedTableClick(affectedTable)"+ >{{ getAffectedTableDisplayName(affectedTable) }}</span+ >+ </div>+ </div>+ </div>+<div class="mt-6 px-4"><aid="statement"href="#statement"- class="flex items-center text-lg text-main mb-2 hover:underline"+ class="w-auto flex items-center text-lg text-main mb-2 hover:underline">{{ $t("common.statement") }}<button@@ -237,10 +261,18 @@</div></BBModal></div>++ <TableDetailDrawer+ v-if="selectedAffectedTable"+ :database-name="database.name"+ :schema-name="selectedAffectedTable.schema"+ :table-name="selectedAffectedTable.table"+ @dismiss="selectedAffectedTable = undefined"+ /></template><script lang="ts" setup>-import { computed, reactive, watch } from "vue";+import { computed, reactive, watch, ref } from "vue";import { toClipboard } from "@soerenmartius/vue3-clipboard";import { CodeDiff } from "v-code-diff";import {@@ -248,10 +280,12 @@ import {extractChangeHistoryUID,extractIssueId,extractUserResourceName,+ getAffectedTablesOfChangeHistory,} from "@/utils";import {pushNotification,useChangeHistoryStore,+ useDBSchemaV1Store,useDatabaseV1Store,useUserStore,} from "@/store";@@ -263,6 +297,8 @@ import {} from "@/types/proto/v1/database_service";import { PushEvent, VcsType, vcsTypeToJSON } from "@/types/proto/v1/vcs";import ChangeHistoryStatusIcon from "@/components/ChangeHistory/ChangeHistoryStatusIcon.vue";+import TableDetailDrawer from "@/components/TableDetailDrawer.vue";+import { AffectedTable } from "@/types/changeHistory";interface LocalState {showDiff: boolean;@@ -275,8 +311,14 @@ const props = defineProps<{changeHistorySlug: string;}>();+const databaseStore = useDatabaseV1Store();+const dbSchemaStore = useDBSchemaV1Store();const changeHistoryStore = useChangeHistoryStore();+const selectedAffectedTable = ref<AffectedTable | undefined>();+const database = computed(() => {+ return databaseStore.getDatabaseByName(changeHistoryParent.value);+});const changeHistoryParent = computed(() => {return `instances/${props.instance}/databases/${props.database}`;});@@ -287,26 +329,54 @@ const changeHistoryName = computed(() => {return `${changeHistoryParent.value}/changeHistories/${changeHistoryUID.value}`;});+const affectedTables = computed(() => {+ if (changeHistory.value === undefined) {+ return [];+ }+ return getAffectedTablesOfChangeHistory(changeHistory.value);+});+watch(changeHistoryParent,- (parent) => {- useDatabaseV1Store().getOrFetchDatabaseByName(parent);- changeHistoryStore.fetchChangeHistoryList({+ async (parent) => {+ const database = await databaseStore.getOrFetchDatabaseByName(parent);+ await dbSchemaStore.getOrFetchDatabaseMetadata(database.name);+ await changeHistoryStore.fetchChangeHistoryList({parent,});},{ immediate: true });+watch(changeHistoryName,- (name) => {- changeHistoryStore.fetchChangeHistory({+ async (name) => {+ await changeHistoryStore.fetchChangeHistory({name,});},{ immediate: true });+const getAffectedTableDisplayName = (affectedTable: AffectedTable): string => {+ const { schema, table, dropped } = affectedTable;+ let name = table;+ if (schema !== "") {+ name = `${schema}.${table}`;+ }+ if (dropped) {+ name = `${name} (deleted)`;+ }+ return name;+};++const handleAffectedTableClick = (affectedTable: AffectedTable): void => {+ if (affectedTable.dropped) {+ return;+ }+ selectedAffectedTable.value = affectedTable;+};+// get all change histories before (include) the one of given id, ordered by descending version.const prevChangeHistoryList = computed(() => {const changeHistoryList = changeHistoryStore.changeHistoryListByDatabase(