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: use issue table in export center (#11401)
boojack84059dbff053
diff --git a/backend/api/v1/issue_service.go b/backend/api/v1/issue_service.goindex 5246ae8534..e3f9e2a7ea 100644--- a/backend/api/v1/issue_service.go+++ b/backend/api/v1/issue_service.go@@ -231,6 +231,10 @@ func (s *IssueService) getIssueFind(ctx context.Context, permissionFilter *storeissueFind.TaskTypes = &[]api.TaskType{api.TaskDatabaseDataUpdate,}+ case "DATA_EXPORT":+ issueFind.TaskTypes = &[]api.TaskType{+ api.TaskDatabaseDataExport,+ }default:return nil, status.Errorf(codes.InvalidArgument, `unknown value %q`, spec.value)}diff --git a/frontend/src/components/DataExportPrepForm/DataExportPrepForm.vue b/frontend/src/components/DataExportPrepForm/DataExportPrepForm.vuenew file mode 100644index 0000000000..f441710f78--- /dev/null+++ b/frontend/src/components/DataExportPrepForm/DataExportPrepForm.vue@@ -0,0 +1,260 @@+<template>+ <DrawerContent>+ <template #header>+ <div class="flex flex-col gap-y-1">+ <span>+ {{ $t("issue.data-export.title") }}+ </span>+ </div>+ </template>++ <div+ class="space-y-4 h-full w-[calc(100vw-8rem)] lg:w-[60rem] max-w-[calc(100vw-8rem)] overflow-x-auto"+ >+ <div v-if="ready">+ <div class="space-y-3">+ <div class="w-full flex items-center space-x-2">+ <AdvancedSearchBox+ v-model:params="state.params"+ :autofocus="false"+ :placeholder="$t('database.filter-database')"+ :support-option-id-list="supportOptionIdList"+ />+ <DatabaseLabelFilter+ v-model:selected="state.selectedLabels"+ :database-list="rawDatabaseList"+ :placement="'left-start'"+ />+ </div>+ <DatabaseV1Table+ mode="ALL_SHORT"+ table-class="border"+ :custom-click="true"+ :database-list="selectableDatabaseList"+ :show-selection-column="true"+ :show-sql-editor-button="false"+ :show-placeholder="true"+ @select-database="handleSelectedDatabaseChange"+ >+ <template #selection="{ database }">+ <NRadio+ :checked="isDatabaseSelected(database as ComposedDatabase)"+ :value="(database as ComposedDatabase).uid"+ @click="+ () =>+ handleSelectedDatabaseChange(database as ComposedDatabase)+ "+ />+ </template>+ </DatabaseV1Table>+ </div>+ </div>+ <div+ v-if="!ready"+ class="w-full h-[20rem] flex items-center justify-center"+ >+ <BBSpin />+ </div>+ </div>++ <template #footer>+ <div class="flex-1 flex items-center justify-between">+ <div></div>++ <div class="flex items-center justify-end gap-x-3">+ <NButton @click.prevent="cancel">+ {{ $t("common.cancel") }}+ </NButton>+ <NButton+ type="primary"+ :disabled="!state.selectedDatabaseUid"+ @click="navigateToIssuePage"+ >+ {{ $t("common.next") }}+ </NButton>+ </div>+ </div>+ </template>+ </DrawerContent>+</template>++<script lang="ts" setup>+import { NButton, NRadio } from "naive-ui";+import { computed, reactive } from "vue";+import { useRouter } from "vue-router";+import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";+import {+ useCurrentUserV1,+ useSearchDatabaseV1List,+ useDatabaseV1Store,+ useProjectV1Store,+} from "@/store";+import type { ComposedDatabase } from "@/types";+import { UNKNOWN_ID, DEFAULT_PROJECT_V1_NAME } from "@/types";+import { State } from "@/types/proto/v1/common";+import type { SearchScopeId, SearchParams } from "@/utils";+import {+ filterDatabaseV1ByKeyword,+ sortDatabaseV1List,+ extractEnvironmentResourceName,+ extractInstanceResourceName,+ generateIssueName,+ extractProjectResourceName,+} from "@/utils";+import { DatabaseLabelFilter, DatabaseV1Table, DrawerContent } from "../v2";++type LocalState = {+ label: string;+ selectedDatabaseUid?: string;+ selectedLabels: { key: string; value: string }[];+ params: SearchParams;+};++const props = defineProps({+ projectId: {+ type: String,+ default: undefined,+ },+});++const emit = defineEmits(["dismiss"]);++const router = useRouter();+const currentUserV1 = useCurrentUserV1();+const projectV1Store = useProjectV1Store();+const databaseV1Store = useDatabaseV1Store();++const state = reactive<LocalState>({+ label: "environment",+ selectedLabels: [],+ params: {+ query: "",+ scopes: [],+ },+});++const selectedProject = computed(() => {+ if (props.projectId) {+ return projectV1Store.getProjectByUID(props.projectId);+ }+ const filter = state.params.scopes.find(+ (scope) => scope.id === "project"+ )?.value;+ if (filter) {+ return projectV1Store.getProjectByName(`projects/${filter}`);+ }+ return undefined;+});++const selectedInstance = computed(() => {+ return (+ state.params.scopes.find((scope) => scope.id === "instance")?.value ??+ `${UNKNOWN_ID}`+ );+});++const selectedEnvironment = computed(() => {+ return (+ state.params.scopes.find((scope) => scope.id === "environment")?.value ??+ `${UNKNOWN_ID}`+ );+});++const { ready } = useSearchDatabaseV1List({+ filter: "instance = instances/-",+});++const rawDatabaseList = computed(() => {+ let list: ComposedDatabase[] = [];+ if (selectedProject.value) {+ list = databaseV1Store.databaseListByProject(selectedProject.value.name);+ } else {+ list = databaseV1Store.databaseListByUser(currentUserV1.value);+ }+ list = list.filter(+ (db) =>+ db.syncState == State.ACTIVE && db.project !== DEFAULT_PROJECT_V1_NAME+ );+ return list;+});++const filteredDatabaseList = computed(() => {+ let list = [...rawDatabaseList.value];++ list = list.filter((db) => {+ if (selectedEnvironment.value !== `${UNKNOWN_ID}`) {+ return (+ extractEnvironmentResourceName(db.effectiveEnvironment) ===+ selectedEnvironment.value+ );+ }+ if (selectedInstance.value !== `${UNKNOWN_ID}`) {+ return (+ extractInstanceResourceName(db.instance) === selectedInstance.value+ );+ }+ return filterDatabaseV1ByKeyword(db, state.params.query.trim(), [+ "name",+ "environment",+ "instance",+ "project",+ ]);+ });++ const labels = state.selectedLabels;+ if (labels.length > 0) {+ list = list.filter((db) => {+ return labels.some((kv) => db.labels[kv.key] === kv.value);+ });+ }++ return sortDatabaseV1List(list);+});++const selectableDatabaseList = computed(() => {+ return filteredDatabaseList.value;+});++const handleSelectedDatabaseChange = (database: ComposedDatabase) => {+ state.selectedDatabaseUid = database.uid;+};++const isDatabaseSelected = (database: ComposedDatabase): boolean => {+ return state.selectedDatabaseUid === database.uid;+};++const navigateToIssuePage = async () => {+ if (!state.selectedDatabaseUid) {+ return;+ }++ const selectedDatabase = selectableDatabaseList.value.find(+ (db) => db.uid === state.selectedDatabaseUid+ ) as ComposedDatabase;++ const project = selectedDatabase?.projectEntity;+ const issueType = "bb.issue.database.data.export";+ const query: Record<string, any> = {+ template: issueType,+ name: generateIssueName(issueType, [selectedDatabase.databaseName]),+ project: project.uid,+ databaseList: state.selectedDatabaseUid,+ };+ router.push({+ name: PROJECT_V1_ROUTE_ISSUE_DETAIL,+ params: {+ projectId: extractProjectResourceName(project.name),+ issueSlug: "create",+ },+ query,+ });+};++const cancel = () => {+ emit("dismiss");+};++const supportOptionIdList = computed((): SearchScopeId[] => {+ return ["project", "instance", "environment"];+});+</script>diff --git a/frontend/src/components/DataExportPrepForm/index.ts b/frontend/src/components/DataExportPrepForm/index.tsnew file mode 100644index 0000000000..a9bcbec805--- /dev/null+++ b/frontend/src/components/DataExportPrepForm/index.ts@@ -0,0 +1,3 @@+import DataExportPrepForm from "./DataExportPrepForm.vue";++export default DataExportPrepForm;diff --git a/frontend/src/components/IssueV1/components/IssueTableV1.vue b/frontend/src/components/IssueV1/components/IssueTableV1.vueindex b734e067d5..b1c143bb6b 100644--- a/frontend/src/components/IssueV1/components/IssueTableV1.vue+++ b/frontend/src/components/IssueV1/components/IssueTableV1.vue@@ -8,6 +8,7 @@</div><div ref="tableRef"><NDataTable+ size="small":columns="columnList":data="issueList":striped="true"@@ -77,6 +78,7 @@ const columnList = computed((): DataTableColumn<ComposedIssue>[] => {},};},+ hide: !props.showSelection,},{type: "expand",@@ -189,12 +191,13 @@ interface LocalState {const props = withDefaults(defineProps<{- title?: string;issueList: ComposedIssue[];+ bordered: boolean;+ title?: string;mode?: Mode;highlightText?: string;loading?: boolean;- bordered: boolean;+ showSelection?: boolean;}>(),{title: "",@@ -202,6 +205,7 @@ const props = withDefaults(highlightText: "",loading: true,bordered: false,+ showSelection: true,});@@ -370,10 +374,3 @@ const isIssueExpanded = (issue: ComposedIssue): boolean => {return sections.some((item) => item.highlight);};</script>--<style lang="postcss" scoped>-.issue-table-list :deep(.n-data-table-td),-.issue-table-list :deep(.n-data-table-th) {- @apply !py-1.5;-}-</style>diff --git a/frontend/src/components/Project/ProjectIssuesPanel.vue b/frontend/src/components/Project/ProjectIssuesPanel.vueindex df6b62b82a..53a96166a4 100644--- a/frontend/src/components/Project/ProjectIssuesPanel.vue+++ b/frontend/src/components/Project/ProjectIssuesPanel.vue@@ -106,7 +106,6 @@ type TabValue = (typeof TABS)[number];interface LocalState {params: SearchParams;- isFetchingActivityList: boolean;advanced: boolean;loading: boolean;loadingMore: boolean;@@ -244,7 +243,6 @@ const initializeSearchParamsFromQueryOrLocalStorage = () => {};const state = reactive<LocalState>({- isFetchingActivityList: false,...initializeSearchParamsFromQueryOrLocalStorage(),loading: false,loadingMore: false,diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 3f64191739..1731491416 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -1176,6 +1176,7 @@"missing-sql-statement": "SQL statement missing. To apply this change to all tasks, click the @:{'issue.apply-to-other-tasks'} button.","task-summary-tooltip": "{failed} task failed | {failed} tasks failed","data-export": {+ "title": "Data Export","options": "Options","format": "Format","encrypt": "Encrypt",diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex ddb87f9686..4bf10b5a70 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -1176,6 +1176,7 @@"missing-sql-statement": "Sentencia SQL faltante. Para aplicar este cambio a todas las tareas, haz clic en el botón '@:{'issue.apply-to-other-tasks'}'.","task-summary-tooltip": "{failed} tarea fallida | \n{failed} tareas fallidas","data-export": {+ "title": "Exportación de Datos","options": "Opciones de exportación","format": "Formato","encrypt": "Cifrar",diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex 784891f09b..1d503a51f7 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -1176,6 +1176,7 @@"missing-sql-statement": "SQLステートメントが見つかりません。この変更をすべてのタスクに適用するには、「@:{'issue.apply-to-other-tasks'}」ボタンをクリックしてください。","task-summary-tooltip": "{failed} タスクが失敗しました | \n{failed} 個のタスクが失敗しました","data-export": {+ "title": "データエクスポート","options": "エクスポートオプション","format": "フォーマット","encrypt": "暗号化",diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.jsonindex 96cb28233a..7ba026bc3a 100644--- a/frontend/src/locales/vi-VN.json+++ b/frontend/src/locales/vi-VN.json@@ -1176,6 +1176,7 @@"missing-sql-statement": "Câu lệnh SQL không tồn tại. Để áp dụng thay đổi này cho tất cả các nhiệm vụ, nhấn vào nút '@:{'issue.apply-to-other-tasks'}'.","task-summary-tooltip": "nhiệm vụ {failed} không thành công | \n{failed} nhiệm vụ không thành công","data-export": {+ "title": "Xuất Dữ Liệu","options": "Tùy chọn xuất","format": "Định dạng","encrypt": "Mã hóa",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 8f0ec5a453..1f168e2d01 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -1176,6 +1176,7 @@"missing-sql-statement": "SQL 语句缺失。要将此更改应用于所有任务,请单击 “@:{'issue.apply-to-other-tasks'}” 按钮。","task-summary-tooltip": "{failed} 个任务失败","data-export": {+ "title": "数据导出","options": "配置项","format": "导出格式","encrypt": "加密",diff --git a/frontend/src/utils/issue/index.ts b/frontend/src/utils/issue/index.tsindex c36728ed5d..2815807cae 100644--- a/frontend/src/utils/issue/index.ts+++ b/frontend/src/utils/issue/index.ts@@ -1,7 +1,10 @@import dayjs from "dayjs";export const generateIssueName = (- type: "bb.issue.database.schema.update" | "bb.issue.database.data.update",+ type:+ | "bb.issue.database.schema.update"+ | "bb.issue.database.data.update"+ | "bb.issue.database.data.export",databaseNameList: string[],isOnlineMode = false) => {@@ -16,7 +19,11 @@ export const generateIssueName = (issueNameParts.push("Online schema change");} else {issueNameParts.push(- type === "bb.issue.database.schema.update" ? `Edit schema` : `Change data`+ type === "bb.issue.database.schema.update"+ ? `Edit schema`+ : type === "bb.issue.database.data.update"+ ? `Change data`+ : "Export data");}const datetime = dayjs().format("@MM-DD HH:mm");diff --git a/frontend/src/views/ExportCenter/index.vue b/frontend/src/views/ExportCenter/index.vueindex c89792cf6d..ac0826333d 100644--- a/frontend/src/views/ExportCenter/index.vue+++ b/frontend/src/views/ExportCenter/index.vue@@ -10,249 +10,107 @@:placeholder="''":support-option-id-list="supportOptionIdList"/>- <NButton- v-if="filterIssueId !== String(UNKNOWN_ID)"- @click="clearFilterIssueId"- >- <span>#{{ filterIssueId }}</span>- <heroicons:x-mark class="w-4 h-4 ml-1 -mr-1.5" />- </NButton></div>- <NButton type="primary" @click="handleRequestExportClick">- <FeatureBadge- feature="bb.feature.access-control"- custom-class="text-white pointer-events-none mr-2"- />+ <NButton type="primary" @click="state.showRequestExportPanel = true">{{ $t("quick-action.request-export-data") }}</NButton></div>- <div class="w-full mt-4">- <ExportRecordTable :export-records="filterExportRecords" />++ <div class="relative w-full mt-4 min-h-[20rem]">+ <PagedIssueTableV1+ v-model:loading="state.loading"+ v-model:loading-more="state.loadingMore"+ :session-key="'export-center'"+ :issue-filter="mergedIssueFilter"+ :ui-issue-filter="mergedUIIssueFilter"+ :page-size="50"+ >+ <template #table="{ issueList, loading }">+ <!-- TODO(steven): Implement data export issue's specific data table -->+ <IssueTableV1+ mode="PROJECT"+ :bordered="true"+ :loading="loading"+ :issue-list="issueList"+ :highlight-text="state.params.query"+ :show-selection="false"+ />+ </template>+ </PagedIssueTableV1></div></div>- <RequestExportPanel- v-if="state.showRequestExportPanel"- :project-id="selectedProject?.uid"- :database-id="selectedDatabase?.uid"- :redirect-to-issue-page="true"- :statement-only="true"+ <Drawer+ :auto-focus="true"+ :show="state.showRequestExportPanel"@close="state.showRequestExportPanel = false"- />-- <FeatureModal- feature="bb.feature.access-control"- :open="state.showFeatureModal"- @cancel="state.showFeatureModal = false"- />+ >+ <DataExportPrepForm @dismiss="state.showRequestExportPanel = false" />+ </Drawer></template><script lang="ts" setup>import { NButton } from "naive-ui";-import { computed, reactive, watchEffect } from "vue";-import { useRoute, useRouter } from "vue-router";-import RequestExportPanel from "@/components/Issue/panel/RequestExportPanel/index.vue";-import { getExpiredDateTime } from "@/components/ProjectMember/utils";+import { computed, reactive } from "vue";+import DataExportPrepForm from "@/components/DataExportPrepForm";+import IssueTableV1 from "@/components/IssueV1/components/IssueTableV1.vue";+import PagedIssueTableV1 from "@/components/IssueV1/components/PagedIssueTableV1.vue";+import { Drawer } from "@/components/v2";+import { useCurrentUserV1 } from "@/store";import {- featureToRef,- useCurrentUserV1,- useDatabaseV1Store,- useInstanceV1Store,- useProjectIamPolicyStore,- useProjectV1List,- useProjectV1Store,-} from "@/store";-import { UNKNOWN_ID, PresetRoleType } from "@/types";-import type { SearchParams, SearchScopeId } from "@/utils";-import { convertFromExpr } from "@/utils/issue/cel";-import ExportRecordTable from "./ExportRecordTable.vue";+ buildIssueFilterBySearchParams,+ buildUIIssueFilterBySearchParams,+ type SearchParams,+ type SearchScopeId,+} from "@/utils";import type { ExportRecord } from "./types";interface LocalState {exportRecords: ExportRecord[];showRequestExportPanel: boolean;- showFeatureModal: boolean;params: SearchParams;+ loading: boolean;+ loadingMore: boolean;}-const issueDescriptionRegexp = /^#(\d+)$/;--const route = useRoute();-const router = useRouter();const currentUser = useCurrentUserV1();-const projectIamPolicyStore = useProjectIamPolicyStore();-const databaseStore = useDatabaseV1Store();-const projectStore = useProjectV1Store();-const instanceStore = useInstanceV1Store();-const { projectList } = useProjectV1List();const state = reactive<LocalState>({exportRecords: [],showRequestExportPanel: false,- showFeatureModal: false,params: {query: "",scopes: [],},-});-const hasDataAccessControlFeature = featureToRef("bb.feature.access-control");--const selectedProject = computed(() => {- const project = state.params.scopes.find(- (scope) => scope.id === "project"- )?.value;- if (!project) {- return;- }- return projectStore.getProjectByName(`projects/${project}`);-});--const selectedInstance = computed(() => {- const instance = state.params.scopes.find(- (scope) => scope.id === "instance"- )?.value;- if (!instance) {- return;- }- return instanceStore.getInstanceByName(`instances/${instance}`);+ loading: false,+ loadingMore: false,});-const selectedDatabase = computed(() => {- const database = state.params.scopes.find(- (scope) => scope.id === "database"- )?.value;- if (!database) {- return;- }- const uid = database.split("-").slice(-1)[0];- return databaseStore.getDatabaseByUID(uid);+const dataExportIssueSearchParams = computed(() => {+ return {+ query: state.params.query,+ scopes: [+ ...state.params.scopes,+ // Default scopes with type and creator.+ {+ id: "type",+ value: "DATA_EXPORT",+ },+ {+ id: "creator",+ value: currentUser.value.email,+ },+ ],+ } as SearchParams;});-const filterIssueId = computed(() => {- const hash = route.hash.replace(/^#+/g, "");- const maybeIssueId = parseInt(hash, 10);- if (!Number.isNaN(maybeIssueId) && maybeIssueId > 0) {- return String(maybeIssueId);- }- return String(UNKNOWN_ID);+const mergedIssueFilter = computed(() => {+ return buildIssueFilterBySearchParams(dataExportIssueSearchParams.value);});-const filterExportRecords = computed(() => {- return state.exportRecords.filter((record) => {- if (filterIssueId.value !== String(UNKNOWN_ID)) {- if (record.issueId !== filterIssueId.value) {- return false;- }- }-- if (selectedProject.value) {- if (record.database.project !== selectedProject.value.name) {- return false;- }- }- if (selectedInstance.value) {- if (record.database.instance !== selectedInstance.value.name) {- return false;- }- }- if (selectedDatabase.value) {- if (record.database.name !== selectedDatabase.value.name) {- return false;- }- }- return true;- });-});--watchEffect(async () => {- const projectNameList = projectList.value.map((project) => project.name);- const iamPolicyList =- await projectIamPolicyStore.batchGetOrFetchProjectIamPolicy(- projectNameList,- true /* skipCache */- );-- const tempExportRecords: ExportRecord[] = [];- for (const iamPolicy of iamPolicyList) {- const bindings = iamPolicy.bindings.filter(- (binding) =>- binding.role === PresetRoleType.PROJECT_EXPORTER &&- binding.members.includes(`user:${currentUser.value.email}`)- );- for (const binding of bindings) {- if (!binding.parsedExpr?.expr) {- continue;- }- // Skip the expired export record.- const expiredDateTime = getExpiredDateTime(binding);- if (- expiredDateTime &&- new Date().getTime() >= expiredDateTime.getTime()- ) {- continue;- }- const conditionExpr = convertFromExpr(binding.parsedExpr.expr);- // Only show the export record with statement condition in export center.- if (!conditionExpr.statement || conditionExpr.statement === "") {- continue;- }- if (- !conditionExpr.databaseResources ||- conditionExpr.databaseResources.length !== 1- ) {- continue;- }-- const databaseResource = conditionExpr.databaseResources[0];- const description = binding.condition?.description || "";- // TODO: Here issueDescription looks like "#{uid}" so we don't have any parent- // project info here.- // To migrate this, we need to DML the description and re-write the issue- // id extraction logic below.- const issueId = description.match(issueDescriptionRegexp)?.[1];- const database = await databaseStore.getOrFetchDatabaseByName(- databaseResource.databaseName- );- let statement = conditionExpr.statement || "";- // NOTE: concat schema and table name to statement for table level export.- // Maybe we need to move this into backend later.- if (statement === "" && databaseResource.table) {- const names = [];- if (databaseResource.schema) {- names.push(databaseResource.schema);- }- names.push(databaseResource.table);- statement = `SELECT * FROM ${names.join(".")};`;- }-- tempExportRecords.push({- databaseResource,- database,- statement,- expiration: conditionExpr.expiredTime || "",- maxRowCount: conditionExpr.rowLimit || 0,- exportFormat: (conditionExpr.exportFormat as any) || "JSON",- issueId: issueId || String(UNKNOWN_ID),- });- }- }- state.exportRecords = tempExportRecords;+const mergedUIIssueFilter = computed(() => {+ return buildUIIssueFilterBySearchParams(dataExportIssueSearchParams.value);});-const handleRequestExportClick = () => {- if (!hasDataAccessControlFeature.value) {- state.showFeatureModal = true;- return;- }- state.showRequestExportPanel = true;-};--const clearFilterIssueId = () => {- router.replace({- ...route,- hash: "",- });-};-const supportOptionIdList = computed((): SearchScopeId[] => ["project","instance",