Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

refactor: defer rollout creation for export plans until user initiates export (#18691)

boojack69db83219a95
diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/Actions.vue b/frontend/src/components/Plan/components/HeaderSection/Actions/Actions.vue
index 05cd2c613d..f543892657 100644
--- a/frontend/src/components/Plan/components/HeaderSection/Actions/Actions.vue
+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/Actions.vue
@@ -36,22 +36,15 @@
@execute="handlePerformAction"
/>
- <!-- Rollout Action Panel -->
- <template v-if="rollout && rolloutStage">
- <TaskRolloutActionPanel
- :show="Boolean(pendingRolloutAction)"
- :action="
- pendingRolloutAction === 'ROLLOUT_START'
- ? 'RUN'
- : pendingRolloutAction === 'ROLLOUT_CANCEL'
- ? 'CANCEL'
- : 'RUN'
- "
- :target="{ type: 'tasks', stage: rolloutStage }"
- @close="pendingRolloutAction = undefined"
- @confirm="handleRolloutActionConfirm"
- />
- </template>
+ <!-- Rollout Action Panel (only when rollout exists) -->
+ <TaskRolloutActionPanel
+ v-if="pendingRolloutAction && rolloutStage"
+ :show="true"
+ :action="pendingRolloutAction === 'ROLLOUT_CANCEL' ? 'CANCEL' : 'RUN'"
+ :target="{ type: 'tasks', stage: rolloutStage }"
+ @close="pendingRolloutAction = undefined"
+ @confirm="handleRolloutActionConfirm"
+ />
<!-- Rollout Create Panel -->
<RolloutCreatePanel
@@ -85,8 +78,8 @@ import {
IssueStatus,
} from "@/types/proto-es/v1/issue_service_pb";
import {
+ BatchRunTasksRequestSchema,
CreateRolloutRequestSchema,
- Task_Type,
} from "@/types/proto-es/v1/rollout_service_pb";
import {
extractPlanUIDFromRolloutName,
@@ -142,17 +135,9 @@ const hasRolloutCreationWarnings = computed(
() => context.value.rolloutCreationWarnings.hasAny
);
-// Get the stage that contains database creation or export tasks
-const rolloutStage = computed(() => {
- if (!rollout.value) return undefined;
- return rollout.value.stages.find((stage) =>
- stage.tasks.some(
- (task) =>
- task.type === Task_Type.DATABASE_CREATE ||
- task.type === Task_Type.DATABASE_EXPORT
- )
- );
-});
+// Get the first stage for database creation/export rollouts
+// (the panel handles all stages internally for these task types)
+const rolloutStage = computed(() => rollout.value?.stages[0]);
const handlePerformAction = async (action: UnifiedAction) => {
switch (action) {
@@ -176,6 +161,13 @@ const handlePerformAction = async (action: UnifiedAction) => {
}
break;
case "ROLLOUT_START":
+ // For export/create plans without rollout, create and run all tasks
+ if (context.value.isExportPlan && !rollout.value) {
+ await handleCreateRollout({ runAllTasks: true });
+ return;
+ }
+ pendingRolloutAction.value = action as RolloutAction;
+ break;
case "ROLLOUT_CANCEL":
pendingRolloutAction.value = action as RolloutAction;
break;
@@ -265,7 +257,8 @@ const handlePlanStateChange = async (action: "PLAN_CLOSE" | "PLAN_REOPEN") => {
});
};
-const handleCreateRollout = async () => {
+// Create rollout and optionally run all tasks (for export plans)
+const handleCreateRollout = async (options?: { runAllTasks?: boolean }) => {
if (creatingRollout.value) return;
creatingRollout.value = true;
@@ -276,19 +269,32 @@ const handleCreateRollout = async () => {
const createdRollout =
await rolloutServiceClientConnect.createRollout(request);
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("common.created"),
- });
-
- router.push({
- name: PROJECT_V1_ROUTE_PLAN_ROLLOUT,
- params: {
- projectId: extractProjectResourceName(project.value.name),
- planId: extractPlanUIDFromRolloutName(createdRollout.name),
- },
- });
+ if (options?.runAllTasks) {
+ // Run all tasks in each stage (for export/create plans)
+ for (const stage of createdRollout.stages) {
+ const runRequest = create(BatchRunTasksRequestSchema, {
+ parent: stage.name,
+ tasks: stage.tasks.map((task) => task.name),
+ });
+ await rolloutServiceClientConnect.batchRunTasks(runRequest);
+ }
+ await resourcePoller.refreshResources();
+ events.emit("status-changed", { eager: true });
+ } else {
+ // Navigate to rollout page
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("common.created"),
+ });
+ router.push({
+ name: PROJECT_V1_ROUTE_PLAN_ROLLOUT,
+ params: {
+ projectId: extractProjectResourceName(project.value.name),
+ planId: extractPlanUIDFromRolloutName(createdRollout.name),
+ },
+ });
+ }
} catch (error) {
pushNotification({
module: "bytebase",
diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateButton.vue b/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateButton.vue
index a4e3c147f2..6831596f17 100644
--- a/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateButton.vue
+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateButton.vue
@@ -30,11 +30,7 @@ import {
useSpecsValidation,
} from "@/components/Plan/components/common";
import { getLocalSheetByName, usePlanContext } from "@/components/Plan/logic";
-import {
- issueServiceClientConnect,
- planServiceClientConnect,
- rolloutServiceClientConnect,
-} from "@/grpcweb";
+import { issueServiceClientConnect, planServiceClientConnect } from "@/grpcweb";
import {
PROJECT_V1_ROUTE_ISSUE_DETAIL_V1,
PROJECT_V1_ROUTE_PLAN_DETAIL,
@@ -56,7 +52,6 @@ import {
type Plan_ChangeDatabaseConfig,
type Plan_ExportDataConfig,
} from "@/types/proto-es/v1/plan_service_pb";
-import { CreateRolloutRequestSchema } from "@/types/proto-es/v1/rollout_service_pb";
import type { Sheet } from "@/types/proto-es/v1/sheet_service_pb";
import {
extractIssueUID,
@@ -144,7 +139,7 @@ const doCreatePlan = async () => {
}
};
-// Create data export issue (plan + issue + rollout)
+// Create data export issue (plan + issue, rollout is created later via EXPORT action)
const doCreateDataExportIssue = async () => {
// Create sheets first
await createSheets();
@@ -174,12 +169,6 @@ const doCreateDataExportIssue = async () => {
const createdIssue =
await issueServiceClientConnect.createIssue(issueRequest);
- // Create the rollout
- const rolloutRequest = create(CreateRolloutRequestSchema, {
- parent: createdPlan.name,
- });
- await rolloutServiceClientConnect.createRollout(rolloutRequest);
-
// Redirect to issue detail page
nextTick(() => {
router.replace({
diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/registry/actions/issue.ts b/frontend/src/components/Plan/components/HeaderSection/Actions/registry/actions/issue.ts
index 9a8afab8f5..ebb87608cc 100644
--- a/frontend/src/components/Plan/components/HeaderSection/Actions/registry/actions/issue.ts
+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/registry/actions/issue.ts
@@ -71,13 +71,18 @@ export const ISSUE_STATUS_RESOLVE: ActionDefinition = {
category: "primary",
priority: 50,
- isVisible: (ctx) =>
- ctx.issueStatus === IssueStatus.OPEN &&
- (ctx.approvalStatus === Issue_ApprovalStatus.APPROVED ||
- ctx.approvalStatus === Issue_ApprovalStatus.SKIPPED) &&
- ctx.allTasksFinished &&
- ctx.plan.hasRollout &&
- ctx.permissions.updateIssue,
+ isVisible: (ctx) => {
+ // Export plans auto-resolve when export completes, never show manual resolve
+ if (ctx.isExportPlan) return false;
+ return (
+ ctx.issueStatus === IssueStatus.OPEN &&
+ (ctx.approvalStatus === Issue_ApprovalStatus.APPROVED ||
+ ctx.approvalStatus === Issue_ApprovalStatus.SKIPPED) &&
+ ctx.allTasksFinished &&
+ ctx.plan.hasRollout &&
+ ctx.permissions.updateIssue
+ );
+ },
isDisabled: () => false,
disabledReason: () => undefined,
diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/registry/actions/rollout.ts b/frontend/src/components/Plan/components/HeaderSection/Actions/registry/actions/rollout.ts
index f0db932188..50e41ea2e9 100644
--- a/frontend/src/components/Plan/components/HeaderSection/Actions/registry/actions/rollout.ts
+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/registry/actions/rollout.ts
@@ -11,6 +11,8 @@ export const ROLLOUT_CREATE: ActionDefinition = {
priority: 55,
isVisible: (ctx) => {
+ // Export plans use ROLLOUT_START to create rollout and run tasks together
+ if (ctx.isExportPlan) return false;
if (ctx.isIssueOnly) return false;
if (ctx.plan.hasRollout) return false;
if (!ctx.issue) return false;
@@ -38,6 +40,14 @@ export const ROLLOUT_START: ActionDefinition = {
priority: 60,
isVisible: (ctx) => {
+ // Export plans: rollout is created on-demand when user clicks Export button
+ if (ctx.isExportPlan) {
+ if (!ctx.issue || !ctx.issueApproved) return false;
+ // Show if no rollout yet (will create it) or has startable tasks
+ if (!ctx.rollout) return ctx.permissions.runTasks;
+ return ctx.hasStartableTasks && ctx.permissions.runTasks;
+ }
+ // Regular plans: rollout must already exist
if (!ctx.rollout) return false;
if (!ctx.issueApproved) return false;
if (!ctx.hasDatabaseCreateOrExportTasks) return false;
diff --git a/frontend/src/components/Plan/components/IssueReviewView/DatabaseExportView.vue b/frontend/src/components/Plan/components/IssueReviewView/DatabaseExportView.vue
index f4061a29e1..8dfeb69850 100644
--- a/frontend/src/components/Plan/components/IssueReviewView/DatabaseExportView.vue
+++ b/frontend/src/components/Plan/components/IssueReviewView/DatabaseExportView.vue
@@ -1,55 +1,28 @@
<template>
<div class="w-full flex flex-col gap-y-4">
- <!-- Tasks Section -->
- <TasksSection />
+ <!-- Targets Section (before rollout) or Tasks Section (after rollout) -->
+ <TasksSection v-if="rollout" />
+ <TargetsSection v-else />
- <!-- Execution History Section -->
- <ExecutionHistorySection v-if="taskRuns.length > 0" />
+ <!-- Execution History Section (only show when rollout exists and has task runs) -->
+ <ExecutionHistorySection v-if="rollout && taskRuns.length > 0" />
<LimitsSection />
- <!-- Export Options Section -->
<OptionsSection />
-
- <!-- SQL Statement Section -->
<StatementSection />
</div>
</template>
<script lang="ts" setup>
-import { computed, watchEffect } from "vue";
-import { useDatabaseV1Store, useSheetV1Store } from "@/store";
-import type { Plan_ExportDataConfig } from "@/types/proto-es/v1/plan_service_pb";
-import { usePlanContextWithRollout } from "../../logic";
-import { useSelectedSpec } from "../SpecDetailView/context";
+import { usePlanContext } from "../../logic";
import StatementSection from "../StatementSection";
import {
ExecutionHistorySection,
LimitsSection,
OptionsSection,
+ TargetsSection,
TasksSection,
} from "./DatabaseExportView";
-const databaseStore = useDatabaseV1Store();
-const sheetStore = useSheetV1Store();
-
-const { selectedSpec } = useSelectedSpec();
-const { taskRuns } = usePlanContextWithRollout();
-
-const exportDataConfig = computed(() => {
- return selectedSpec.value.config.value as Plan_ExportDataConfig;
-});
-
-// Fetch target databases
-watchEffect(() => {
- exportDataConfig.value?.targets?.forEach((target) => {
- databaseStore.getOrFetchDatabaseByName(target);
- });
-});
-
-// Fetch sheet for statement display
-watchEffect(() => {
- if (exportDataConfig.value?.sheet) {
- sheetStore.getOrFetchSheetByName(exportDataConfig.value.sheet);
- }
-});
+const { rollout, taskRuns } = usePlanContext();
</script>
diff --git a/frontend/src/components/Plan/components/IssueReviewView/DatabaseExportView/ExecutionHistorySection.vue b/frontend/src/components/Plan/components/IssueReviewView/DatabaseExportView/ExecutionHistorySection.vue
index c16e92188d..745af74f5c 100644
--- a/frontend/src/components/Plan/components/IssueReviewView/DatabaseExportView/ExecutionHistorySection.vue
+++ b/frontend/src/components/Plan/components/IssueReviewView/DatabaseExportView/ExecutionHistorySection.vue
@@ -26,10 +26,9 @@ import { computed } from "vue";
import TaskRunTable from "@/components/RolloutV1/components/TaskRunTable.vue";
import type { TaskRun } from "@/types/proto-es/v1/rollout_service_pb";
import { extractTaskUID } from "@/utils";
-import { usePlanContext, usePlanContextWithRollout } from "../../../logic";
+import { usePlanContext } from "../../../logic";
-const { plan, rollout } = usePlanContext();
-const { taskRuns } = usePlanContextWithRollout();
+const { plan, rollout, taskRuns } = usePlanContext();
// Get the export data spec
const exportDataSpec = computed(() => {
@@ -53,9 +52,9 @@ const exportTasks = computed(() => {
return tasks;
});
-// Get all task runs for export tasks
+// Get all task runs for export tasks (empty if no rollout)
const allTaskRuns = computed((): TaskRun[] => {
- if (exportTasks.value.length === 0) return [];
+ if (!rollout.value || exportTasks.value.length === 0) return [];
const exportTaskUIDs = new Set(
exportTasks.value.map((task) => extractTaskUID(task.name))
diff --git a/frontend/src/components/Plan/components/IssueReviewView/DatabaseExportView/TargetsSection.vue b/frontend/src/components/Plan/components/IssueReviewView/DatabaseExportView/TargetsSection.vue
new file mode 100644
index 0000000000..1f1b312009
--- /dev/null
+++ b/frontend/src/components/Plan/components/IssueReviewView/DatabaseExportView/TargetsSection.vue
@@ -0,0 +1,71 @@
+<template>
+ <div class="flex flex-col gap-y-2">
+ <template v-if="targets.length > 0">
+ <h3 class="text-base font-medium">
+ {{ $t("plan.targets.title") }}
+ </h3>
+ <div class="flex flex-wrap gap-2">
+ <div
+ v-for="target in targets"
+ :key="target"
+ class="inline-flex items-center gap-2 px-2 py-1.5 border rounded-sm min-w-0"
+ >
+ <template v-if="isValidDatabaseName(target)">
+ <DatabaseDisplay
+ :database="target"
+ :show-environment="true"
+ size="medium"
+ class="flex-1 min-w-0"
+ />
+ </template>
+ <template v-else-if="isValidDatabaseGroupName(target)">
+ <DatabaseGroupTargetDisplay :target="target" class="px-1 py-1" />
+ </template>
+ <template v-else>
+ <span class="text-sm">{{ target }}</span>
+ </template>
+ </div>
+ </div>
+ </template>
+ <div v-else class="text-center text-control-light py-8">
+ {{ $t("common.no-data") }}
+ </div>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { computed, watchEffect } from "vue";
+import DatabaseDisplay from "@/components/Plan/components/common/DatabaseDisplay.vue";
+import DatabaseGroupTargetDisplay from "@/components/Plan/components/SpecDetailView/DatabaseGroupTargetDisplay.vue";
+import { useDatabaseV1Store, useDBGroupStore } from "@/store";
+import { isValidDatabaseGroupName, isValidDatabaseName } from "@/types";
+import { DatabaseGroupView } from "@/types/proto-es/v1/database_group_service_pb";
+import { usePlanContext } from "../../../logic";
+
+const { plan } = usePlanContext();
+const dbStore = useDatabaseV1Store();
+const dbGroupStore = useDBGroupStore();
+
+const targets = computed(() => {
+ const exportDataSpec = plan.value.specs.find(
+ (spec) => spec.config?.case === "exportDataConfig"
+ );
+ if (exportDataSpec?.config.case === "exportDataConfig") {
+ return exportDataSpec.config.value.targets || [];
+ }
+ return [];
+});
+
+// Fetch target data
+watchEffect(() => {
+ for (const target of targets.value) {
+ if (isValidDatabaseName(target)) {
+ dbStore.getOrFetchDatabaseByName(target);
+ } else if (isValidDatabaseGroupName(target)) {
+ dbGroupStore.getOrFetchDBGroupByName(target, {
+ view: DatabaseGroupView.FULL,
+ });
+ }
+ }
+});
+</script>
diff --git a/frontend/src/components/Plan/components/IssueReviewView/DatabaseExportView/TasksSection.vue b/frontend/src/components/Plan/components/IssueReviewView/DatabaseExportView/TasksSection.vue
index e88c8e1292..8dbf78a86b 100644
--- a/frontend/src/components/Plan/components/IssueReviewView/DatabaseExportView/TasksSection.vue
+++ b/frontend/src/components/Plan/components/IssueReviewView/DatabaseExportView/TasksSection.vue
@@ -1,78 +1,57 @@
<template>
- <!-- Tasks Display -->
<div class="flex flex-col gap-y-2">
- <!-- Task status summary with title -->
- <div
- v-if="exportTasks.length > 0"
- class="flex items-center justify-between"
- >
- <div class="flex items-center gap-2">
- <h3 class="text-base font-medium">
- {{ $t("common.task", exportTasks.length) }}
- </h3>
- </div>
- </div>
-
- <!-- Task status display -->
- <div v-if="exportTasks.length > 0" class="flex flex-wrap gap-2">
- <div
- v-for="task in exportTasks"
- :key="task.name"
- class="inline-flex items-center gap-2 px-2 py-1.5 border rounded-sm transition-colors min-w-0"
- >
- <!-- Task Status -->
- <div class="shrink-0">
- <TaskStatus :status="task.status" size="tiny" />
- </div>
-
- <!-- Database Display -->
- <div class="flex-1 min-w-0">
+ <template v-if="tasks.length > 0">
+ <h3 class="text-base font-medium">
+ {{ $t("common.task", tasks.length) }}
+ </h3>
+ <div class="flex flex-wrap gap-2">
+ <div
+ v-for="task in tasks"
+ :key="task.name"
+ class="inline-flex items-center gap-2 px-2 py-1.5 border rounded-sm min-w-0"
+ >
+ <TaskStatus :status="task.status" size="tiny" class="shrink-0" />
<DatabaseDisplay
:database="task.target"
:show-environment="true"
size="medium"
+ class="flex-1 min-w-0"
/>
</div>
</div>
- </div>
-
- <!-- No tasks message -->
- <div
- v-else-if="exportTasks.length === 0"
- class="text-center text-control-light py-8"
- >
+ </template>
+ <div v-else class="text-center text-control-light py-8">
{{ $t("common.no-data") }}
</div>
</div>
</template>
<script lang="ts" setup>
-import { computed } from "vue";
+import { computed, watchEffect } from "vue";
import DatabaseDisplay from "@/components/Plan/components/common/DatabaseDisplay.vue";
import TaskStatus from "@/components/Rollout/kits/TaskStatus.vue";
-import { usePlanContext } from "../../../logic";
+import { useDatabaseV1Store } from "@/store";
+import { usePlanContextWithRollout } from "../../../logic";
-const { plan, rollout } = usePlanContext();
+const { plan, rollout } = usePlanContextWithRollout();
+const dbStore = useDatabaseV1Store();
-// Get the export data spec
-const exportDataSpec = computed(() => {
- return plan.value.specs.find(
+const tasks = computed(() => {
+ const exportDataSpec = plan.value.specs.find(
(spec) => spec.config?.case === "exportDataConfig"
);
-});
+ if (!exportDataSpec) return [];
-// Find export tasks related to this spec
-const exportTasks = computed(() => {
- if (!rollout.value || !exportDataSpec.value) return [];
+ return rollout.value.stages
+ .flatMap((stage) => stage.tasks)
+ .filter((task) => task.specId === exportDataSpec.id);
+});
- const tasks = [];
- for (const stage of rollout.value.stages) {
- for (const task of stage.tasks) {
- if (task.specId === exportDataSpec.value.id) {
- tasks.push(task);
- }
- }
+// Fetch task target databases
+watchEffect(() => {
+ const targets = tasks.value.map((task) => task.target);
+ if (targets.length > 0) {
+ dbStore.batchGetOrFetchDatabases(targets);
}
- return tasks;
});
</script>
diff --git a/frontend/src/components/Plan/components/IssueReviewView/DatabaseExportView/index.ts b/frontend/src/components/Plan/components/IssueReviewView/DatabaseExportView/index.ts
index 90edb2e1e8..2e391fd817 100644
--- a/frontend/src/components/Plan/components/IssueReviewView/DatabaseExportView/index.ts
+++ b/frontend/src/components/Plan/components/IssueReviewView/DatabaseExportView/index.ts
@@ -1,4 +1,5 @@
-export { default as TasksSection } from "./TasksSection.vue";
-export { default as OptionsSection } from "./OptionsSection.vue";
-export { default as LimitsSection } from "./LimitsSection.vue";
export { default as ExecutionHistorySection } from "./ExecutionHistorySection.vue";
+export { default as LimitsSection } from "./LimitsSection.vue";
+export { default as OptionsSection } from "./OptionsSection.vue";
+export { default as TargetsSection } from "./TargetsSection.vue";
+export { default as TasksSection } from "./TasksSection.vue";
diff --git a/frontend/src/components/Plan/components/IssueReviewView/Sidebar/Sidebar.vue b/frontend/src/components/Plan/components/IssueReviewView/Sidebar/Sidebar.vue
index 699580dec3..39f792f318 100644
--- a/frontend/src/components/Plan/components/IssueReviewView/Sidebar/Sidebar.vue
+++ b/frontend/src/components/Plan/components/IssueReviewView/Sidebar/Sidebar.vue
@@ -1,6 +1,6 @@
<template>
<div class="w-full flex flex-col p-4 gap-4">
- <DatabaseChangeSection />
+ <DatabaseChangeSection v-if="isDatabaseChangePlan" />
<IssueStatusSection v-if="issue.approvalTemplate" :issue="issue" />
@@ -39,7 +39,11 @@ import DatabaseChangeSection from "./DatabaseChangeSection.vue";
import IssueStatusSection from "./IssueStatusSection.vue";
const { t } = useI18n();
-const { issue } = usePlanContextWithIssue();
+const { plan, issue } = usePlanContextWithIssue();
+
+const isDatabaseChangePlan = computed(() =>
+ plan.value.specs.some((spec) => spec.config?.case === "changeDatabaseConfig")
+);
const currentUser = useCurrentUserV1();
const { project } = useCurrentProjectV1();
const { refreshResources } = useResourcePoller();
diff --git a/frontend/src/components/Plan/components/SpecDetailView/DatabaseGroupTargetDisplay.vue b/frontend/src/components/Plan/components/SpecDetailView/DatabaseGroupTargetDisplay.vue
index 4c0f790cea..4a06ac15eb 100644
--- a/frontend/src/components/Plan/components/SpecDetailView/DatabaseGroupTargetDisplay.vue
+++ b/frontend/src/components/Plan/components/SpecDetailView/DatabaseGroupTargetDisplay.vue
@@ -70,7 +70,11 @@ import { useRouter } from "vue-router";
import DatabaseGroupIcon from "@/components/DatabaseGroupIcon.vue";
import DatabaseGroupName from "@/components/v2/Model/DatabaseGroupName.vue";
import { PROJECT_V1_ROUTE_DATABASE_GROUP_DETAIL } from "@/router/dashboard/projectV1";
-import { getProjectNameAndDatabaseGroupName, useDBGroupStore } from "@/store";
+import {
+ getProjectNameAndDatabaseGroupName,
+ useDatabaseV1Store,
+ useDBGroupStore,
+} from "@/store";
import { isValidDatabaseGroupName } from "@/types";
import { DatabaseGroupView } from "@/types/proto-es/v1/database_group_service_pb";
import DatabaseDisplay from "../common/DatabaseDisplay.vue";
@@ -89,6 +93,7 @@ const props = withDefaults(
const router = useRouter();
const dbGroupStore = useDBGroupStore();
+const dbStore = useDatabaseV1Store();
const databases = ref<string[]>([]);
@@ -99,7 +104,14 @@ watchEffect(async () => {
view: DatabaseGroupView.FULL,
silent: true,
});
- databases.value = dbGroup.matchedDatabases?.map((db) => db.name) ?? [];
+ const matchedDatabases =
+ dbGroup.matchedDatabases?.map((db) => db.name) ?? [];
+ databases.value = matchedDatabases;
+
+ // Fetch matched databases so DatabaseDisplay can show environment
+ if (matchedDatabases.length > 0) {
+ await dbStore.batchGetOrFetchDatabases(matchedDatabases);
+ }
} catch {
databases.value = [];
}
diff --git a/frontend/src/components/Plan/logic/poller/poller.ts b/frontend/src/components/Plan/logic/poller/poller.ts
index 079224d829..a8132948c4 100644
--- a/frontend/src/components/Plan/logic/poller/poller.ts
+++ b/frontend/src/components/Plan/logic/poller/poller.ts
@@ -101,7 +101,8 @@ export const provideResourcePoller = () => {
},
},
rollout: {
- canRefresh: () => !!plan.value?.name && !!rollout,
+ canRefresh: () =>
+ !!plan.value?.name && !!rollout && !!plan.value.hasRollout,
refresh: () => {
const rolloutName = getRolloutFromPlan(plan.value.name);
return refreshRollout(rolloutName, project.value, rollout);
@@ -329,21 +330,22 @@ export const provideResourcePoller = () => {
{ deep: true }
);
- // Watch for plan issue/rollout changes on plan pages
+ // Watch for plan issue/rollout changes on plan and issue pages
watch(
() => ({ issue: plan.value?.issue, hasRollout: plan.value?.hasRollout }),
async (newValues, oldValues) => {
const routeName = route.name as string;
- const isPlanRoute = includes(
+ const isRelevantRoute = includes(
[
PROJECT_V1_ROUTE_PLAN_DETAIL,
PROJECT_V1_ROUTE_PLAN_DETAIL_SPECS,
PROJECT_V1_ROUTE_PLAN_DETAIL_SPEC_DETAIL,
+ PROJECT_V1_ROUTE_ISSUE_DETAIL_V1,
],
routeName
);
- if (!isPlanRoute) return;
+ if (!isRelevantRoute) return;
const issueAdded = !oldValues?.issue && newValues.issue;
const rolloutAdded = !oldValues?.hasRollout && newValues.hasRollout;
diff --git a/frontend/src/components/RolloutV1/components/TaskRolloutActionPanel.vue b/frontend/src/components/RolloutV1/components/TaskRolloutActionPanel.vue
index a79ba1b2fd..4577c89ea1 100644
--- a/frontend/src/components/RolloutV1/components/TaskRolloutActionPanel.vue
+++ b/frontend/src/components/RolloutV1/components/TaskRolloutActionPanel.vue
@@ -60,7 +60,9 @@
</label>
<EnvironmentV1Name
:environment="
- environmentStore.getEnvironmentByName(targetStage.environment)
+ environmentStore.getEnvironmentByName(
+ target.stage?.environment ?? ''
+ )
"
:link="false"
/>
@@ -75,7 +77,11 @@
}}</span>
<span
class="opacity-80"
- v-if="eligibleTasks.length > 1 && shouldShowStageInfo"
+ v-if="
+ eligibleTasks.length > 1 &&
+ shouldShowStageInfo &&
+ target.stage
+ "
>
({{
eligibleTasks.length === target.stage.tasks.length
@@ -273,8 +279,8 @@ import {
} from "@/store";
import {
getProjectIdPlanUidStageUidTaskUidFromRolloutName,
+ planNamePrefix,
projectNamePrefix,
- rolloutNamePrefix,
stageNamePrefix,
userNamePrefix,
} from "@/store/modules/v1/common";
@@ -306,7 +312,8 @@ import { canRolloutTasks } from "./taskPermissions";
// 1 hour in milliseconds
const DEFAULT_RUN_DELAY_MS = 60 * 60 * 1000;
-export type TargetType = { type: "tasks"; tasks?: Task[]; stage: Stage };
+// Stage is optional - only needed for regular rollouts, not database create/export
+export type TargetType = { type: "tasks"; tasks?: Task[]; stage?: Stage };
const props = defineProps<{
show: boolean;
@@ -314,6 +321,15 @@ const props = defineProps<{
target: TargetType;
}>();
+// Task status filters for each action type
+const isRunnable = (task: Task) =>
+ task.status === Task_Status.NOT_STARTED ||
+ task.status === Task_Status.FAILED ||
+ task.status === Task_Status.CANCELED;
+
+const isCancellable = (task: Task) =>
+ task.status === Task_Status.PENDING || task.status === Task_Status.RUNNING;
+
const emit = defineEmits<{
(event: "close"): void;
(event: "confirm"): void;
@@ -337,11 +353,9 @@ watch(
() => props.show,
(show) => {
if (show) {
- // Check permission when panel opens
- canRolloutPermission.value = canRolloutTasks(
- props.target.stage.tasks || [],
- issue.value
- );
+ // Check permission when panel opens - use provided tasks or stage tasks
+ const tasks = props.target.tasks ?? props.target.stage?.tasks ?? [];
+ canRolloutPermission.value = canRolloutTasks(tasks, issue.value);
}
},
{ immediate: true }
@@ -496,7 +510,7 @@ const validationWarnings = computed(() => {
// Automatic rollout info (always show as warning for non-export tasks with no task runs)
if (
isAutomaticRollout.value &&
- !isDatabaseExportTask.value &&
+ rolloutType.value !== "DATABASE_EXPORT" &&
!hasTaskRuns.value
) {
warnings.push(t("rollout.automatic-rollout.description"));
@@ -517,154 +531,87 @@ const shouldShowBypassOption = computed(() => {
);
});
-// Extract stage from target
-const targetStage = computed(() => {
- return props.target.stage;
+// All tasks from rollout
+const allRolloutTasks = computed(() =>
+ flatten(rollout.value.stages.map((stage) => stage.tasks))
+);
+
+// Detect rollout type based on tasks
+const rolloutType = computed(() => {
+ const tasks = allRolloutTasks.value;
+ if (tasks.every((task) => task.type === Task_Type.DATABASE_CREATE)) {
+ return "DATABASE_CREATE";
+ }
+ if (tasks.every((task) => task.type === Task_Type.DATABASE_EXPORT)) {
+ return "DATABASE_EXPORT";
+ }
+ return "DATABASE_CHANGE";
+});
+
+const isDatabaseCreateOrExport = computed(
+ () =>
+ rolloutType.value === "DATABASE_CREATE" ||
+ rolloutType.value === "DATABASE_EXPORT"
+);
+
+// Get eligible tasks based on action type
+const eligibleTasks = computed(() => {
+ // For database create/export, use all rollout tasks; otherwise use stage tasks
+ const tasks = isDatabaseCreateOrExport.value
+ ? allRolloutTasks.value
+ : (props.target.tasks ?? props.target.stage?.tasks ?? []);
+
+ // Filter by action type (RUN and SKIP use same filter)
+ if (props.action === "RUN" || props.action === "SKIP") {
+ return tasks.filter(isRunnable);
+ }
+ if (props.action === "CANCEL") {
+ return tasks.filter(isCancellable);
+ }
+ return tasks;
+});
+
+const title = computed(() => {
+ const n = eligibleTasks.value.length;
+ if (props.action === "RUN") return t("task.run-task", { n });
+ if (props.action === "SKIP") return t("task.skip-task", { n });
+ if (props.action === "CANCEL") return t("task.cancel-task", { n });
+ return "";
});
// Get rollout policy for target stage environment
const { policy: rolloutPolicy } = usePolicyByParentAndType(
computed(() => ({
- parentPath: targetStage.value?.environment || "",
+ parentPath: props.target.stage?.environment || "",
policyType: PolicyType.ROLLOUT_POLICY,
}))
);
-// Check if target stage has automatic rollout policy
-const isAutomaticRollout = computed(() => {
- return (
+const isAutomaticRollout = computed(
+ () =>
rolloutPolicy.value?.enforce &&
rolloutPolicy.value.policy?.case === "rolloutPolicy" &&
rolloutPolicy.value.policy.value.automatic
- );
-});
+);
-// Check if any of the eligible tasks have task runs
-const hasTaskRuns = computed(() => {
- return eligibleTasks.value.some((task) =>
+const hasTaskRuns = computed(() =>
+ eligibleTasks.value.some((task) =>
taskRuns.value.some((taskRun) => taskRun.name.startsWith(`${task.name}/`))
- );
-});
-
-// Extract tasks if provided directly
-const targetTasks = computed(() => {
- if (props.target.type === "tasks") {
- return props.target.tasks;
- }
- return undefined;
-});
-
-const title = computed(() => {
- switch (props.action) {
- case "RUN":
- return t("task.run-task", { n: eligibleTasks.value.length });
- case "SKIP":
- return t("task.skip-task", { n: eligibleTasks.value.length });
- case "CANCEL":
- return t("task.cancel-task", { n: eligibleTasks.value.length });
- default:
- return "";
- }
-});
-
-// Get eligible tasks based on action type and target
-const eligibleTasks = computed(() => {
- // For database create/export tasks, get all relevant tasks from all stages
- if (isDatabaseCreationOrExportTask.value) {
- const allTasks = flatten(rollout.value.stages.map((stage) => stage.tasks));
- // Apply action-based filtering
- if (props.action === "RUN") {
- return allTasks.filter(
- (task) =>
- task.status === Task_Status.NOT_STARTED ||
- task.status === Task_Status.CANCELED ||
- task.status === Task_Status.FAILED
- );
- } else if (props.action === "SKIP") {
- return allTasks.filter(
- (task) =>
- task.status === Task_Status.NOT_STARTED ||
- task.status === Task_Status.FAILED ||
- task.status === Task_Status.CANCELED
- );
- } else if (props.action === "CANCEL") {
- return allTasks.filter(
- (task) =>
- task.status === Task_Status.PENDING ||
- task.status === Task_Status.RUNNING
- );
- }
- return allTasks;
- }
-
- // If specific tasks are provided, use them
- if (
- props.target.type === "tasks" &&
- targetTasks.value &&
- targetTasks.value.length > 0
- ) {
- return targetTasks.value;
- }
-
- // Otherwise filter from stage tasks based on action
- const stageTasks = targetStage.value.tasks || [];
-
- if (props.action === "RUN") {
- return stageTasks.filter(
- (task) =>
- task.status === Task_Status.NOT_STARTED ||
- task.status === Task_Status.FAILED ||
- task.status === Task_Status.CANCELED
- );
- } else if (props.action === "SKIP") {
- return stageTasks.filter(
- (task) =>
- task.status === Task_Status.NOT_STARTED ||
- task.status === Task_Status.FAILED ||
- task.status === Task_Status.CANCELED
- );
- } else if (props.action === "CANCEL") {
- return stageTasks.filter(
- (task) =>
- task.status === Task_Status.PENDING ||
- task.status === Task_Status.RUNNING
- );
- }
-
- return [];
-});
+ )
+);
-// Virtual scroll configuration
+// Virtual scroll for large task lists
const useVirtualScroll = computed(() => eligibleTasks.value.length > 50);
-const itemHeight = computed(() => 32); // Height of each task item in pixels
-
-const showScheduledTimePicker = computed(() => {
- return props.action === "RUN";
-});
-
-// Check if any of the eligible tasks are database creation tasks
-const isDatabaseCreationTask = computed(() => {
- const allTasks = flatten(rollout.value.stages.map((stage) => stage.tasks));
- return allTasks.every((task) => task.type === Task_Type.DATABASE_CREATE);
-});
+const itemHeight = 32;
-// Check if any of the eligible tasks are database export tasks
-const isDatabaseExportTask = computed(() => {
- const allTasks = flatten(rollout.value.stages.map((stage) => stage.tasks));
- return allTasks.every((task) => task.type === Task_Type.DATABASE_EXPORT);
-});
-
-// Check if any of the eligible tasks are database creation or export tasks
-const isDatabaseCreationOrExportTask = computed(() => {
- return isDatabaseCreationTask.value || isDatabaseExportTask.value;
-});
+const showScheduledTimePicker = computed(() => props.action === "RUN");
-const shouldShowStageInfo = computed(
- () => !isDatabaseCreationOrExportTask.value
+// UI visibility flags
+const shouldShowStageInfo = computed(() => !isDatabaseCreateOrExport.value);
+const shouldShowTaskInfo = computed(
+ () => rolloutType.value !== "DATABASE_CREATE"
);
-const shouldShowTaskInfo = computed(() => !isDatabaseCreationTask.value);
-
// Handle execution mode change (immediate vs scheduled)
const handleExecutionModeChange = (value: string) => {
if (value === "immediate") {
@@ -699,65 +646,55 @@ const addRunTimeToRequest = (request: BatchRunTasksRequest) => {
}
};
+// Execute batch operation for tasks grouped by stage
+const executeBatchByStage = async (
+ operation: (parent: string, tasks: Task[]) => Promise<void>
+) => {
+ if (!rollout.value) return;
+
+ if (isDatabaseCreateOrExport.value) {
+ // For database create/export, group tasks by stage
+ const tasksByStage = groupTasksByStage(eligibleTasks.value);
+ for (const [stageId, stageTasks] of tasksByStage) {
+ await operation(`${rollout.value.name}/stages/${stageId}`, stageTasks);
+ }
+ } else if (props.target.stage) {
+ // For regular rollouts, use the single stage
+ await operation(props.target.stage.name, eligibleTasks.value);
+ }
+};
+
const handleConfirm = async () => {
if (loading.value) return;
loading.value = true;
try {
if (props.action === "RUN") {
- // For export tasks, group by stage/environment and make separate batch calls
- if (isDatabaseExportTask.value) {
- const tasksByStage = groupTasksByStage(eligibleTasks.value);
-
- // Make batch run calls for each stage/environment
- for (const [stageId, stageTasks] of tasksByStage) {
- const request = create(BatchRunTasksRequestSchema, {
- parent: `${rollout.value.name}/stages/${stageId}`,
- tasks: stageTasks.map((task) => task.name),
- });
- addRunTimeToRequest(request);
- await rolloutServiceClientConnect.batchRunTasks(request);
- }
- } else {
- // For non-export tasks, use the original logic
+ await executeBatchByStage(async (parent, tasks) => {
const request = create(BatchRunTasksRequestSchema, {
- parent: targetStage.value.name,
- tasks: eligibleTasks.value.map((task) => task.name),
+ parent,
+ tasks: tasks.map((task) => task.name),
});
addRunTimeToRequest(request);
await rolloutServiceClientConnect.batchRunTasks(request);
- }
+ });
// Track prior backup telemetry (async, non-blocking)
trackPriorBackupOnTaskRun(
eligibleTasks.value,
plan.value,
projectOfPlan(plan.value),
- targetStage.value.environment
+ props.target.stage?.environment ?? ""
);
} else if (props.action === "SKIP") {
- // For export tasks, group by stage/environment and make separate batch calls
- if (isDatabaseExportTask.value) {
- const tasksByStage = groupTasksByStage(eligibleTasks.value);
-
- // Make batch skip calls for each stage/environment
- for (const [stageId, stageTasks] of tasksByStage) {
- const request = create(BatchSkipTasksRequestSchema, {
- parent: `${rollout.value.name}/stages/${stageId}`,
- tasks: stageTasks.map((task) => task.name),
- reason: comment.value,
- });
- await rolloutServiceClientConnect.batchSkipTasks(request);
- }
- } else {
- // For non-export tasks, use the original logic
+ await executeBatchByStage(async (parent, tasks) => {
const request = create(BatchSkipTasksRequestSchema, {
- parent: targetStage.value.name,
- tasks: eligibleTasks.value.map((task) => task.name),
+ parent,
+ tasks: tasks.map((task) => task.name),
reason: comment.value,
});
await rolloutServiceClientConnect.batchSkipTasks(request);
- }
+ });
} else if (props.action === "CANCEL") {
await cancelTasks();
}
@@ -803,7 +740,7 @@ const cancelTasks = async () => {
const [projectId, planId, stageId] =
getProjectIdPlanUidStageUidTaskUidFromRolloutName(task.name);
if (projectId && planId && stageId) {
- const stageName = `${projectNamePrefix}${projectId}/${rolloutNamePrefix}${planId}/${stageNamePrefix}${stageId}`;
+ const stageName = `${projectNamePrefix}${projectId}/${planNamePrefix}${planId}/${"rollout"}/${stageNamePrefix}${stageId}`;
if (!tasksByStage.has(stageName)) {
tasksByStage.set(stageName, []);
}