Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: improve export archive task run handling and request parsing (#17461)
boojack02d960eca387
diff --git a/backend/api/v1/sql_service.go b/backend/api/v1/sql_service.goindex 030d33c9f8..52e50037d1 100644--- a/backend/api/v1/sql_service.go+++ b/backend/api/v1/sql_service.go@@ -782,9 +782,16 @@ func (s *SQLService) Export(ctx context.Context, req *connect.Request[v1pb.Expor}func (s *SQLService) doExportFromIssue(ctx context.Context, requestName string) (*v1pb.ExportResponse, error) {- _, rolloutID, _, err := common.GetProjectIDRolloutIDMaybeStageID(requestName)+ // Try to parse as rollout name first (more specific), then fallback to stage name+ var rolloutID int+ var err error+ _, rolloutID, err = common.GetProjectIDRolloutID(requestName)if err != nil {- return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("failed to parse rollout ID: %v", err))+ // If rollout parsing fails, try parsing as stage name+ _, rolloutID, _, err = common.GetProjectIDRolloutIDMaybeStageID(requestName)+ if err != nil {+ return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("failed to parse request name as rollout or stage: %v", err))+ }}rollout, err := s.store.GetRollout(ctx, rolloutID)if err != nil {diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/export/ExportArchiveDownloadAction.vue b/frontend/src/components/Plan/components/HeaderSection/Actions/export/ExportArchiveDownloadAction.vueindex 8b55233409..c26ccfd196 100644--- a/frontend/src/components/Plan/components/HeaderSection/Actions/export/ExportArchiveDownloadAction.vue+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/export/ExportArchiveDownloadAction.vue@@ -1,47 +1,48 @@<template>- <NTooltip- v-if="taskRun?.exportArchiveStatus === TaskRun_ExportArchiveStatus.READY"- >+ <NTooltip><template #trigger><NButtontype="primary":loading="state.isExporting"@click="downloadExportArchive"+ v-if="!isExported"><template #icon><DownloadIcon class="w-5 h-5" /></template>{{ $t("common.download") }}</NButton>+ <div+ v-else+ class="flex flex-row items-center gap-2 text-sm textlabel !leading-8"+ >+ <CalendarXIcon class="w-5 h-auto" />+ {{ $t("issue.data-export.file-expired") }}+ </div></template><span class="text-sm">{{ $t("issue.data-export.download-tooltip") }}</span></NTooltip>- <div- v-else-if="- taskRun?.exportArchiveStatus === TaskRun_ExportArchiveStatus.EXPORTED- "- class="flex flex-row items-center gap-2 text-sm textlabel !leading-8"- >- <CircleCheckBigIcon class="w-5 h-auto" />- {{ $t("issue.data-export.file-downloaded") }}- </div></template><script setup lang="ts">import { create } from "@bufbuild/protobuf";import dayjs from "dayjs";-import { last } from "lodash-es";-import { DownloadIcon, CircleCheckBigIcon } from "lucide-vue-next";+import { first, orderBy } from "lodash-es";+import { DownloadIcon, CalendarXIcon } from "lucide-vue-next";import { NButton, NTooltip } from "naive-ui";import { computed, reactive } from "vue";import { usePlanContext } from "@/components/Plan/logic";import { useSQLStore } from "@/store";import { ExportFormat } from "@/types/proto-es/v1/common_pb";import type { Plan_ExportDataConfig } from "@/types/proto-es/v1/plan_service_pb";-import { TaskRun_ExportArchiveStatus } from "@/types/proto-es/v1/rollout_service_pb";+import {+ TaskRun_ExportArchiveStatus,+ type TaskRun,+} from "@/types/proto-es/v1/rollout_service_pb";import { ExportRequestSchema } from "@/types/proto-es/v1/sql_service_pb";+import { extractTaskRunUID, extractTaskUID } from "@/utils";interface LocalState {isExporting: boolean;@@ -52,27 +53,26 @@ const state = reactive<LocalState>({isExporting: false,});-const taskRun = computed(() => {- if (!rollout.value || !taskRuns.value.length) return undefined;-- // Find export tasks first- const exportTasks = rollout.value.stages+const isExported = computed(() => {+ const exportTaskRuns = rollout.value?.stages.flatMap((stage) => stage.tasks)- .filter((task) => {- // Find tasks that belong to export data specs- const exportSpec = plan.value.specs.find(- (spec) =>- spec.config?.case === "exportDataConfig" && spec.id === task.specId+ .map((task) => {+ const taskRunsForTask = taskRuns.value.filter(+ (taskRun) => extractTaskUID(taskRun.name) === extractTaskUID(task.name));- return !!exportSpec;- });-- // Get task runs for export tasks- const exportTaskRuns = taskRuns.value.filter((taskRun) =>- exportTasks.some((task) => taskRun.name.startsWith(task.name + "/"))+ return first(+ orderBy(+ taskRunsForTask,+ (taskRun) => Number(extractTaskRunUID(taskRun.name)),+ "desc"+ )+ );+ })+ .filter(Boolean) as TaskRun[];+ return exportTaskRuns.every(+ (taskRun) =>+ taskRun.exportArchiveStatus === TaskRun_ExportArchiveStatus.EXPORTED);-- return last(exportTaskRuns);});const exportDataConfig = computed((): Plan_ExportDataConfig | undefined => {@@ -89,7 +89,7 @@ const downloadExportArchive = async () => {try {const content = await useSQLStore().exportData(create(ExportRequestSchema, {- name: rollout.value.name,+ name: `${rollout.value.name}/stages/-`,}));const fileType = getExportFileType(exportDataConfig.value);diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/unified/UnifiedActionGroup.vue b/frontend/src/components/Plan/components/HeaderSection/Actions/unified/UnifiedActionGroup.vueindex 3c7892aa55..3b04f5255a 100644--- a/frontend/src/components/Plan/components/HeaderSection/Actions/unified/UnifiedActionGroup.vue+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/unified/UnifiedActionGroup.vue@@ -36,7 +36,7 @@</template><script setup lang="ts">-import { last } from "lodash-es";+import { first, orderBy } from "lodash-es";import { EllipsisVerticalIcon } from "lucide-vue-next";import { NButton, NDropdown, type DropdownOption } from "naive-ui";import { computed, h } from "vue";@@ -46,9 +46,12 @@ import { DropdownItemWithErrorList } from "@/components/IssueV1/components/commoimport { useCurrentUserV1, extractUserId } from "@/store";import { IssueStatus } from "@/types/proto-es/v1/issue_service_pb";import {- TaskRun_ExportArchiveStatus,Task_Type,+ TaskRun_ExportArchiveStatus,+ TaskRun_Status,+ type TaskRun,} from "@/types/proto-es/v1/rollout_service_pb";+import { extractTaskRunUID, extractTaskUID } from "@/utils";import { usePlanContext } from "../../../../logic";import { ExportArchiveDownloadAction } from "../export";import UnifiedActionButton from "./UnifiedActionButton.vue";@@ -76,41 +79,16 @@ const isExportPlan = computed(() => {);});-// Export download logic-const hasExportDataTask = computed(() => {- return (- rollout.value?.stages.some((stage) =>- stage.tasks.some((task) => task.type === Task_Type.DATABASE_EXPORT)- ) || false- );-});--const taskRun = computed(() => {- if (!rollout.value || !taskRuns.value.length) return undefined;-- // Find export tasks first- const exportTasks = rollout.value.stages- .flatMap((stage) => stage.tasks)- .filter((task) => {- // Find tasks that belong to export data specs- const exportSpec = plan.value.specs.find(- (spec) =>- spec.config?.case === "exportDataConfig" && spec.id === task.specId- );- return !!exportSpec;- });-- // Get task runs for export tasks- const exportTaskRuns = taskRuns.value.filter((taskRun) =>- exportTasks.some((task) => taskRun.name.startsWith(task.name + "/"))- );-- return last(exportTaskRuns);-});-const shouldShowExportDownload = computed(() => {+ const exportTasks =+ rollout.value?.stages+ .flatMap((stage) => stage.tasks)+ .filter((task) => {+ return task.type === Task_Type.DATABASE_EXPORT;+ }) || [];+// Must have export data tasks- if (!hasExportDataTask.value) return false;+ if (exportTasks.length === 0) return false;// Must have an issueif (!issue?.value) return false;@@ -121,13 +99,35 @@ const shouldShowExportDownload = computed(() => {}// Current user must be the issue creator- const currentUserEmail = currentUser.value.email;- const issueCreator = extractUserId(issue.value.creator);- if (currentUserEmail !== issueCreator) return false;+ if (currentUser.value.email !== extractUserId(issue.value.creator)) {+ return false;+ }++ // Get latest task run for each export task+ const exportTaskRuns = exportTasks+ .map((task) => {+ const taskRunsForTask = taskRuns.value.filter(+ (taskRun) => extractTaskUID(taskRun.name) === extractTaskUID(task.name)+ );+ return first(+ orderBy(+ taskRunsForTask,+ (taskRun) => Number(extractTaskRunUID(taskRun.name)),+ "desc"+ )+ );+ })+ .filter(Boolean) as TaskRun[];// Check if export archive is readyif (- taskRun.value?.exportArchiveStatus !== TaskRun_ExportArchiveStatus.READY+ exportTaskRuns.length === 0 ||+ exportTaskRuns.some(+ (taskRun) =>+ taskRun.status !== TaskRun_Status.DONE ||+ (taskRun.exportArchiveStatus !== TaskRun_ExportArchiveStatus.READY &&+ taskRun.exportArchiveStatus !== TaskRun_ExportArchiveStatus.EXPORTED)+ )) {return false;}diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 97d462a03a..f929b02fb6 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -1037,8 +1037,8 @@"data-export": {"options": "Options","format": "Format",- "file-downloaded": "File Downloaded",- "download-tooltip": "Available for 24 hours"+ "download-tooltip": "Available for 24 hours",+ "file-expired": "File Expired"},"task-run": {"logs": "Logs",diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex 33f2f56c8e..8d156e5395 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -1033,8 +1033,8 @@"data-export": {"options": "Opciones de exportación","format": "Formato",- "file-downloaded": "Archivo Descargado",- "download-tooltip": "Disponible por 24 horas"+ "download-tooltip": "Disponible por 24 horas",+ "file-expired": "Archivo expirado"},"task-run": {"logs": "Registros",@@ -2927,4 +2927,4 @@"last-visit": "Última visita","changelog-for-version": "Registro de cambios para {version}"}-}+}\ No newline at end of filediff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex a270e8e7fc..400f434f1c 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -1033,8 +1033,8 @@"data-export": {"options": "設定項目","format": "エクスポート形式",- "file-downloaded": "ダウンロードされたファイル",- "download-tooltip": "24 時間利用可能"+ "download-tooltip": "24 時間利用可能",+ "file-expired": "ファイルの有効期限が切れました"},"task-run": {"logs": "ログ",@@ -2927,4 +2927,4 @@"last-visit": "最終訪問","changelog-for-version": "{version} の変更履歴"}-}+}\ No newline at end of filediff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.jsonindex 9f01b95069..9661f87774 100644--- a/frontend/src/locales/vi-VN.json+++ b/frontend/src/locales/vi-VN.json@@ -1033,8 +1033,8 @@"data-export": {"options": "Tùy chọn","format": "Định dạng",- "file-downloaded": "Tệp đã tải xuống",- "download-tooltip": "Có sẵn trong 24 giờ"+ "download-tooltip": "Có sẵn trong 24 giờ",+ "file-expired": "Tệp đã hết hạn"},"task-run": {"logs": "Nhật ký",@@ -2927,4 +2927,4 @@"last-visit": "Lần truy cập cuối","changelog-for-version": "Nhật ký thay đổi cho phiên bản {version}"}-}+}\ No newline at end of filediff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 2bda4d5f45..5bdf0d9592 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -1033,8 +1033,8 @@"data-export": {"options": "配置项","format": "导出格式",- "file-downloaded": "文件已下载",- "download-tooltip": "24 小时可用"+ "download-tooltip": "24 小时可用",+ "file-expired": "文件已过期"},"task-run": {"logs": "日志",@@ -2927,4 +2927,4 @@"last-visit": "上次访问","changelog-for-version": "{version} 的更新日志"}-}+}\ No newline at end of file