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: implement export change history (#7199)
boojackc2ee764c972f
diff --git a/frontend/package.json b/frontend/package.jsonindex 5092fecfaf..178df3d78b 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -33,12 +33,14 @@"elkjs": "^0.8.2","emittery": "^1.0.1","escape-string-regexp": "5.0.0",+ "file-saver": "^2.0.5","google-protobuf": "^3.21.2","highlight.js": "11.6.0","html-to-image": "^1.11.4","inter-ui": "3.19.3","js-base64": "^3.7.5","js-yaml": "4.1.0",+ "jszip": "^3.10.1","libphonenumber-js": "^1.10.34","lodash-es": "4.17.21","markdown-it": "^13.0.1",@@ -90,6 +92,7 @@"@types/d3-shape": "^3.1.0","@types/dompurify": "2.4.0","@types/downloadjs": "1.4.3",+ "@types/file-saver": "^2.0.5","@types/js-yaml": "4.0.5","@types/lodash-es": "4.17.7","@types/markdown-it": "^12.2.3",diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yamlindex 98826ae075..c6029f27c7 100644--- a/frontend/pnpm-lock.yaml+++ b/frontend/pnpm-lock.yaml@@ -62,6 +62,9 @@ dependencies:escape-string-regexp:specifier: 5.0.0version: 5.0.0+ file-saver:+ specifier: ^2.0.5+ version: 2.0.5google-protobuf:specifier: ^3.21.2version: 3.21.2@@ -80,6 +83,9 @@ dependencies:js-yaml:specifier: 4.1.0version: 4.1.0+ jszip:+ specifier: ^3.10.1+ version: 3.10.1libphonenumber-js:specifier: ^1.10.34version: 1.10.34@@ -229,6 +235,9 @@ devDependencies:'@types/downloadjs':specifier: 1.4.3version: 1.4.3+ '@types/file-saver':+ specifier: ^2.0.5+ version: 2.0.5'@types/js-yaml':specifier: 4.0.5version: 4.0.5@@ -1066,6 +1075,10 @@ packages:resolution: {integrity: sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ==}dev: true+ /@types/[email protected]:+ resolution: {integrity: sha512-zv9kNf3keYegP5oThGLaPk8E081DFDuwfqjtiTzm6PoxChdJ1raSuADf2YGCVIyrSynLrgc8JWv296s7Q7pQSQ==}+ dev: true+/@types/[email protected]:resolution: {integrity: sha512-Nmh0K3iWQJzniTuPRcJn5hxXkfB1T1pgB89SBig5PlJQU5yocazeu4jATJlaA0GYFKWMqDdvYemoSnF2pXgLVA==}dev: false@@ -3042,6 +3055,10 @@ packages:flat-cache: 3.0.4dev: true+ resolution: {integrity: sha512-P9bmyZ3h/PRG+Nzga+rbdI4OEpNDzAVyy74uVO9ATgzLK6VtAsYybF/+TOCvrc0MO793d6+42lLyZTw7/ArVzA==}+ dev: false+resolution: {integrity: sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==}engines: {node: '>=8'}@@ -3264,6 +3281,10 @@ packages:engines: {node: '>= 4'}dev: true+ resolution: {integrity: sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==}+ dev: false+resolution: {integrity: sha512-HR7EVodfFUdQCTIeySw+WDRFJlPcLOJbXfwwZ7Oom6tjsvZ3bOkCDJHehQC3nxJrv7+f9XecwazynjU8e4Vw3Q==}dev: false@@ -3349,6 +3370,10 @@ packages:resolution: {integrity: sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==}dev: false+ resolution: {integrity: sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==}+ dev: false+resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==}dev: true@@ -3397,6 +3422,15 @@ packages:semver: 6.3.0dev: true+ resolution: {integrity: sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==}+ dependencies:+ lie: 3.3.0+ pako: 1.0.11+ readable-stream: 2.3.8+ setimmediate: 1.0.5+ dev: false+resolution: {integrity: sha512-ymToLHqL02udwVdbkowNpzjFd6UzozMtshPQKVi5k1EjKRqKqBrOnE9QbLEb0/pV76SAiIT13hdL8R6suc+f3g==}dev: true@@ -3501,6 +3535,12 @@ packages:resolution: {integrity: sha512-p6g4NaQH4gK1gre32+kV14Mk6GPo2EDcPDvjbi+D2ycsPFsN4gVWNbs0itdHLZqByg6YEK8mE7OeP200I/ScTQ==}dev: false+ resolution: {integrity: sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==}+ dependencies:+ immediate: 3.0.6+ dev: false+resolution: {integrity: sha512-utWOt/GHzuUxnLKxB6dk81RoOeoNeHgbrXiuGk4yyF5qlRz+iIVWu56E2fqGHFrXz0QNUhLB/8nKqvRH66JKGQ==}engines: {node: '>=10'}@@ -3926,6 +3966,10 @@ packages:engines: {node: '>=6'}dev: false+ resolution: {integrity: sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==}+ dev: false+resolution: {integrity: sha512-6dNZu0Ki+gyV0eBsFKJhYr+MdQYAzFUGlBMNj3GNrmHxmz1lfRa24CjFObPXtjcetlOv5Ad299MhIK0znp3afw==}dev: false@@ -4245,6 +4289,10 @@ packages:hasBin: truedev: true+ resolution: {integrity: sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==}+ dev: false+resolution: {integrity: sha512-xL96WDdCZYdU7Slin569tFX712BxsxslWwAfAhCYjQKGTq7dAU91Lomy6nLLhh/dyGhk/YH4TwTSRxTzhuHyZg==}hasBin: true@@ -4362,6 +4410,18 @@ packages:string_decoder: 0.10.31dev: false+ resolution: {integrity: sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==}+ dependencies:+ core-util-is: 1.0.3+ inherits: 2.0.4+ isarray: 1.0.0+ process-nextick-args: 2.0.1+ safe-buffer: 5.1.2+ string_decoder: 1.1.1+ util-deprecate: 1.0.2+ dev: false+resolution: {integrity: sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==}engines: {node: '>= 6'}@@ -4469,6 +4529,10 @@ packages:tslib: 2.6.0dev: false+ resolution: {integrity: sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==}+ dev: false+resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==}dev: false@@ -4521,6 +4585,10 @@ packages:resolution: {integrity: sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==}dev: false+ resolution: {integrity: sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==}+ dev: false+resolution: {integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==}engines: {node: '>=8'}@@ -4600,6 +4668,12 @@ packages:resolution: {integrity: sha512-ev2QzSzWPYmy9GuqfIVildA4OdcGLeFZQrq5ys6RtiuF+RQQiZWr8TZNyAcuVXyQRYfEO+MsoB/1BuQVhOJuoQ==}dev: false+ resolution: {integrity: sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==}+ dependencies:+ safe-buffer: 5.1.2+ dev: false+resolution: {integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==}dependencies:diff --git a/frontend/src/components/ChangeHistory/ChangeHistoryTable.vue b/frontend/src/components/ChangeHistory/ChangeHistoryTable.vueindex f082d01f3c..010d5972c6 100644--- a/frontend/src/components/ChangeHistory/ChangeHistoryTable.vue+++ b/frontend/src/components/ChangeHistory/ChangeHistoryTable.vue@@ -16,13 +16,18 @@class="w-2":title="columnList[0].title"/>- <BBTableHeaderCell class="w-8" :title="columnList[1].title" />- <BBTableHeaderCell class="w-16" :title="columnList[2].title" />+ <BBTableHeaderCell+ :left-padding="4"+ class="w-2"+ :title="columnList[1].title"+ />+ <BBTableHeaderCell class="w-8" :title="columnList[2].title" /><BBTableHeaderCell class="w-16" :title="columnList[3].title" />- <BBTableHeaderCell class="w-48" :title="columnList[4].title" />- <BBTableHeaderCell class="w-16" :title="columnList[5].title" />+ <BBTableHeaderCell class="w-16" :title="columnList[4].title" />+ <BBTableHeaderCell class="w-48" :title="columnList[5].title" /><BBTableHeaderCell class="w-16" :title="columnList[6].title" /><BBTableHeaderCell class="w-16" :title="columnList[7].title" />+ <BBTableHeaderCell class="w-16" :title="columnList[8].title" /></template><template v-else><BBTableHeaderCell@@ -39,6 +44,14 @@</template></template><template #body="{ rowData: history }: { rowData: ChangeHistory }">+ <BBTableCell v-if="mode == 'DATABASE'">+ <NCheckbox+ :disabled="!allowToSelectChangeHistory(history)"+ :checked="selectedChangeHistoryNameList?.includes(history.name)"+ @update:checked="() => handleToggleChangeHistorySelected(history)"+ @click.stop=""+ />+ </BBTableCell><BBTableCell :left-padding="4"><ChangeHistoryStatusIcon :status="history.status" /></BBTableCell>@@ -88,9 +101,10 @@</template><script lang="ts" setup>-import { computed, PropType } from "vue";+import { computed } from "vue";import { useRouter } from "vue-router";import { useI18n } from "vue-i18n";+import { NCheckbox } from "naive-ui";import { ComposedDatabase } from "@/types";import { BBTableSectionDataSource } from "@/bbkit/types";@@ -112,20 +126,16 @@ import { useUserStore } from "@/store";type Mode = "DATABASE" | "PROJECT";-const props = defineProps({- mode: {- default: "DATABASE",- type: String as PropType<Mode>,- },- databaseSectionList: {- required: true,- type: Array as PropType<ComposedDatabase[]>,- },- historySectionList: {- required: true,- type: Array as PropType<BBTableSectionDataSource<ChangeHistory>[]>,- },-});+const props = defineProps<{+ mode?: Mode;+ databaseSectionList: ComposedDatabase[];+ historySectionList: BBTableSectionDataSource<ChangeHistory>[];+ selectedChangeHistoryNameList?: string[];+}>();++const emit = defineEmits<{+ (event: "update:selected", value: string[]): void;+}>();const router = useRouter();@@ -134,6 +144,9 @@ const { t } = useI18n();const columnList = computed(() => {if (props.mode === "DATABASE") {return [+ {+ title: "",+ },{title: "",},@@ -195,4 +208,24 @@ const creatorOfChangeHistory = (history: ChangeHistory) => {const email = extractUserResourceName(history.creator);return useUserStore().getUserByEmail(email);};++const allowToSelectChangeHistory = (history: ChangeHistory) => {+ return (+ history.type === ChangeHistory_Type.BASELINE ||+ history.type === ChangeHistory_Type.MIGRATE ||+ history.type === ChangeHistory_Type.MIGRATE_SDL+ );+};++const handleToggleChangeHistorySelected = (history: ChangeHistory) => {+ const selected = props.selectedChangeHistoryNameList ?? [];+ if (selected.includes(history.name)) {+ emit(+ "update:selected",+ selected.filter((name) => name !== history.name)+ );+ } else {+ emit("update:selected", [...selected, history.name]);+ }+};</script>diff --git a/frontend/src/components/DatabaseChangeHistoryPanel.vue b/frontend/src/components/DatabaseChangeHistoryPanel.vueindex f5ee3b80f7..61be429d74 100644--- a/frontend/src/components/DatabaseChangeHistoryPanel.vue+++ b/frontend/src/components/DatabaseChangeHistoryPanel.vue@@ -1,40 +1,62 @@<template><div class="flex flex-col space-y-4"><div- class="flex flex-row items-center text-lg leading-6 font-medium text-main space-x-2"+ class="w-full flex flex-row justify-between items-center text-lg leading-6 font-medium text-main space-x-2">- <span>{{ $t("change-history.self") }}</span>- <BBTooltipButton- v-if="showEstablishBaselineButton"- type="primary"- :disabled="!allowMigrate"- tooltip-mode="DISABLED-ONLY"- data-label="bb-establish-baseline-button"- @click="state.showBaselineModal = true"- >- {{ $t("change-history.establish-baseline") }}- <template v-if="database.project === DEFAULT_PROJECT_V1_NAME" #tooltip>- <div class="whitespace-pre-line">- {{- $t("issue.not-allowed-to-operate-unassigned-database", {- operation: $t(- "change-history.establish-baseline"- ).toLowerCase(),- })- }}- </div>- </template>- </BBTooltipButton>- <div>+ <div class="flex flex-row justify-start items-center space-x-2">+ <span>{{ $t("change-history.self") }}</span><BBSpinv-if="state.loading":title="$t('change-history.refreshing-history')"/></div>+ <div class="flex flex-row justify-end items-center space-x-2">+ <BBTooltipButton+ v-if="showEstablishBaselineButton"+ type="normal"+ :disabled="!allowExportChangeHistory"+ tooltip-mode="DISABLED-ONLY"+ @click="handleExportChangeHistory"+ >+ {{ $t("change-history.export") }}+ <template #tooltip>+ <div class="whitespace-pre-line">+ {{ $t("change-history.need-to-select-first") }}+ </div>+ </template>+ </BBTooltipButton>+ <BBTooltipButton+ v-if="showEstablishBaselineButton"+ type="primary"+ :disabled="!allowMigrate"+ tooltip-mode="DISABLED-ONLY"+ data-label="bb-establish-baseline-button"+ @click="state.showBaselineModal = true"+ >+ {{ $t("change-history.establish-baseline") }}+ <template+ v-if="database.project === DEFAULT_PROJECT_V1_NAME"+ #tooltip+ >+ <div class="whitespace-pre-line">+ {{+ $t("issue.not-allowed-to-operate-unassigned-database", {+ operation: $t(+ "change-history.establish-baseline"+ ).toLowerCase(),+ })+ }}+ </div>+ </template>+ </BBTooltipButton>+ </div></div><ChangeHistoryTable+ :mode="'DATABASE'":database-section-list="[database]":history-section-list="changeHistorySectionList"+ :selected-change-history-name-list="state.selectedChangeHistoryNameList"+ @update:selected="state.selectedChangeHistoryNameList = $event"/></div>@@ -57,21 +79,28 @@</template><script lang="ts" setup>+import saveAs from "file-saver";+import JSZip from "jszip";import { computed, onBeforeMount, PropType, reactive } from "vue";import { useI18n } from "vue-i18n";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 { TenantMode } from "@/types/proto/v1/project_service";-import { ChangeHistory } from "@/types/proto/v1/database_service";+import {+ ChangeHistory,+ ChangeHistory_Type,+} from "@/types/proto/v1/database_service";import { ChangeHistoryTable } from "@/components/ChangeHistory";+import dayjs from "dayjs";interface LocalState {showBaselineModal: boolean;loading: boolean;+ selectedChangeHistoryNameList: string[];}const props = defineProps({@@ -93,6 +122,7 @@ const router = useRouter();const state = reactive<LocalState>({showBaselineModal: false,loading: false,+ selectedChangeHistoryNameList: [],});const prepareChangeHistoryList = () => {@@ -123,6 +153,10 @@ const showEstablishBaselineButton = computed(() => {return true;});+const allowExportChangeHistory = computed(() => {+ return state.selectedChangeHistoryNameList.length > 0;+});+const allowMigrate = computed(() => {if (!props.allowEdit) return false;@@ -150,6 +184,35 @@ const changeHistorySectionList = computed(});+const handleExportChangeHistory = async () => {+ const selectedChangeHistoryList = state.selectedChangeHistoryNameList+ .map((name) => {+ return changeHistoryList.value.find((item) => item.name === name);+ })+ .filter(Boolean) as ChangeHistory[];+ const zip = new JSZip();++ for (const changeHistory of selectedChangeHistoryList) {+ if (+ changeHistory.type === ChangeHistory_Type.MIGRATE ||+ changeHistory.type === ChangeHistory_Type.MIGRATE_SDL+ ) {+ zip.file(`${changeHistory.version}.sql`, changeHistory.statement);+ } else if (changeHistory.type === ChangeHistory_Type.BASELINE) {+ zip.file(`${changeHistory.version}_baseline.sql`, changeHistory.schema);+ } else {+ // NOT SUPPORTED.+ }+ }++ const content = await zip.generateAsync({ type: "blob" });+ const fileName = `${props.database.databaseName}_${dayjs().format(+ "YYYYMMDD"+ )}.zip`;+ saveAs(content, fileName);+ state.selectedChangeHistoryNameList = [];+};+const doCreateBaseline = () => {state.showBaselineModal = false;diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 7fc04a1ed7..fa3ebf2b82 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -1116,7 +1116,9 @@"establish-database-baseline": "Establish \"{name}\" baseline","instance-missing-change-schema": "Missing change history schema on instance \"{name}\".","instance-bad-connection": "Unable to connect instance \"{name}\" to retrieve change history.",- "contact-dba": "Please contact your DBA to config it"+ "contact-dba": "Please contact your DBA to config it",+ "export": "Export Change History",+ "need-to-select-first": "Need to select change history first"},"database": {"select": "Select database",diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex 981be6b49a..a4526fdbb7 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -1115,7 +1115,9 @@"establish-database-baseline": "Establecer línea base de \"{name}\"","instance-missing-change-schema": "Esquema de historial de cambios faltante en la instancia \"{name}\".","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"+ "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"},"database": {"select": "Seleccionar base de datos",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex de0613c859..a6e1397abb 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -1112,7 +1112,9 @@"establish-database-baseline": "建立「{name}」基线","instance-missing-change-schema": "实例「{name}」缺失用于记录变更历史的 schema。","instance-bad-connection": "无法连接实例「{name}」以获取变更历史。",- "contact-dba": "请联系您的 DBA 进行配置。"+ "contact-dba": "请联系您的 DBA 进行配置。",+ "export": "导出变更历史",+ "need-to-select-first": "需要先选择变更历史"},"database": {"select": "选择数据库",