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(plan): scope plan check UI to spec and consolidate status logic (#19874)
boojack61783474da49
diff --git a/frontend/src/components/Plan/components/ChecksView/ChecksDrawer.vue b/frontend/src/components/Plan/components/ChecksView/ChecksDrawer.vueindex a0e7ba2079..29163677ba 100644--- a/frontend/src/components/Plan/components/ChecksView/ChecksDrawer.vue+++ b/frontend/src/components/Plan/components/ChecksView/ChecksDrawer.vue@@ -6,7 +6,7 @@><ChecksView:default-status="status"- :plan-check-runs="planCheckRuns"+ :plan-check-runs="resolvedPlanCheckRuns":is-loading="isLoading"/></DrawerContent>@@ -14,18 +14,24 @@</template><script setup lang="ts">-import { ref } from "vue";+import { computed, ref } from "vue";import { Drawer, DrawerContent } from "@/components/v2";+import type { PlanCheckRun } from "@/types/proto-es/v1/plan_service_pb";import type { Advice_Level } from "@/types/proto-es/v1/sql_service_pb";import { usePlanContext } from "../../logic";import { useResourcePoller } from "../../logic/poller";import ChecksView from "./ChecksView.vue";-defineProps<{+const props = defineProps<{status: Advice_Level;+ planCheckRuns?: PlanCheckRun[];}>();-const { planCheckRuns } = usePlanContext();+const { planCheckRuns: contextPlanCheckRuns } = usePlanContext();++const resolvedPlanCheckRuns = computed(() => {+ return props.planCheckRuns ?? contextPlanCheckRuns.value;+});const { refreshResources } = useResourcePoller();const isLoading = ref(true);diff --git a/frontend/src/components/Plan/components/ChecksView/ChecksView.vue b/frontend/src/components/Plan/components/ChecksView/ChecksView.vueindex 6ba83cad66..b94ae56254 100644--- a/frontend/src/components/Plan/components/ChecksView/ChecksView.vue+++ b/frontend/src/components/Plan/components/ChecksView/ChecksView.vue@@ -167,6 +167,7 @@ import {PlanCheckRun_Status,} from "@/types/proto-es/v1/plan_service_pb";import { Advice_Level } from "@/types/proto-es/v1/sql_service_pb";+import { computePlanCheckStatusSummary } from "../../logic/plan-check-status";import CheckResultItem from "../common/CheckResultItem.vue";import DatabaseDisplay from "../common/DatabaseDisplay.vue";@@ -200,36 +201,20 @@ const hasFilters = computed(() => {return selectedStatus.value !== undefined;});-// Calculate status summary from plan check runs-const statusSummary = computed(() => {- const summary = { error: 0, warning: 0, success: 0 };+// Summary depends only on `planCheckRuns` (not status filter) so toggling the filter does not rescan for counts.+const planCheckSummary = computed(() =>+ computePlanCheckStatusSummary(props.planCheckRuns)+);- for (const checkRun of props.planCheckRuns) {- // Count failed plan check runs as errors- if (checkRun.status === PlanCheckRun_Status.FAILED) {- summary.error++;- }-- for (const result of checkRun.results) {- if (result.status === Advice_Level.ERROR) {- summary.error++;- } else if (result.status === Advice_Level.WARNING) {- summary.warning++;- } else if (result.status === Advice_Level.SUCCESS) {- summary.success++;- }- }- }-- return summary;-});+const statusSummary = computed(() => ({+ error: planCheckSummary.value.error,+ warning: planCheckSummary.value.warning,+ success: planCheckSummary.value.success,+}));const hasAnyStatus = computed(() => {- return (- statusSummary.value.error > 0 ||- statusSummary.value.warning > 0 ||- statusSummary.value.success > 0- );+ const s = planCheckSummary.value;+ return s.error > 0 || s.warning > 0 || s.success > 0;});const toggleSelectedStatus = (status: Advice_Level) => {@@ -248,7 +233,7 @@ const getItemClass = (status: Advice_Level) => {: "px-2 py-1";};-// Group results by type and target+// O(total results); pagination only slices `groups` — very large `results` may need future virtualization.const filteredResultGroups = computed(() => {const groups: ResultGroup[] = [];const groupMap = new Map<string, ResultGroup>();diff --git a/frontend/src/components/Plan/components/PlanCheckRunStatusIcon.vue b/frontend/src/components/Plan/components/PlanCheckRunStatusIcon.vueindex 69d8e0af54..f591b3162d 100644--- a/frontend/src/components/Plan/components/PlanCheckRunStatusIcon.vue+++ b/frontend/src/components/Plan/components/PlanCheckRunStatusIcon.vue@@ -25,11 +25,11 @@<script lang="ts" setup>import type { PropType } from "vue";import { computed } from "vue";-import type { Plan } from "@/types/proto-es/v1/plan_service_pb";+import type { Plan, PlanCheckRun } from "@/types/proto-es/v1/plan_service_pb";import { Advice_Level } from "@/types/proto-es/v1/sql_service_pb";import CheckIcon from "~icons/heroicons-solid/check";import XIcon from "~icons/heroicons-solid/x";-import { usePlanCheckStatus } from "../logic";+import { useResolvedPlanCheckStatus } from "../logic";export type SizeType = "small" | "normal";@@ -38,17 +38,26 @@ const props = defineProps({required: true,type: Object as PropType<Plan>,},+ planCheckRuns: {+ type: Array as PropType<PlanCheckRun[] | undefined>,+ default: undefined,+ },size: {type: String as PropType<SizeType>,default: "normal",},});+const planCheckRunsRef = computed(() => props.planCheckRuns);+const {- getOverallStatus: planCheckRunStatus,+ overallAdviceLevel: planCheckRunStatus,hasAnyStatus: hasAnyChecks,hasRunning: hasRunningChecks,-} = usePlanCheckStatus(computed(() => props.plan));+} = useResolvedPlanCheckStatus(+ computed(() => props.plan),+ planCheckRunsRef+);const iconClass = () => {const sizeClass = props.size === "normal" ? "w-4 h-4" : "w-3.5 h-3.5";diff --git a/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckSection.vue b/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckSection.vueindex e353247372..dbec72ab28 100644--- a/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckSection.vue+++ b/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckSection.vue@@ -33,6 +33,7 @@<div class="flex items-center flex-wrap gap-2 min-w-0"><PlanCheckStatusCount:plan="plan"+ :plan-check-runs="checksOfSelectedSpec":show-label="true"clickable@click="openChecksDrawer($event)"@@ -64,6 +65,7 @@<ChecksDrawerv-model:show="showChecksDrawer":status="selectedResultStatus"+ :plan-check-runs="checksOfSelectedSpec"/></div></template>diff --git a/frontend/src/components/Plan/components/PlanCheckStatusCount.vue b/frontend/src/components/Plan/components/PlanCheckStatusCount.vueindex 78637d7426..77ef989ecc 100644--- a/frontend/src/components/Plan/components/PlanCheckStatusCount.vue+++ b/frontend/src/components/Plan/components/PlanCheckStatusCount.vue@@ -1,7 +1,11 @@<template><div class="flex items-center gap-2" v-if="hasAnyStatus"><template v-if="displayMode === 'icon'">- <PlanCheckRunStatusIcon :plan="plan" :size="size" />+ <PlanCheckRunStatusIcon+ :plan="plan"+ :plan-check-runs="planCheckRuns"+ :size="size"+ /></template><!-- Default display mode: show all status counts with icons --><template v-else>@@ -56,9 +60,9 @@ import {XCircleIcon,} from "lucide-vue-next";import { computed, type PropType } from "vue";-import type { Plan } from "@/types/proto-es/v1/plan_service_pb";+import type { Plan, PlanCheckRun } from "@/types/proto-es/v1/plan_service_pb";import { Advice_Level } from "@/types/proto-es/v1/sql_service_pb";-import { usePlanCheckStatus } from "../logic";+import { useResolvedPlanCheckStatus } from "../logic";import PlanCheckRunStatusIcon from "./PlanCheckRunStatusIcon.vue";type DisplayMode = "icon" | "default";@@ -89,14 +93,21 @@ const props = defineProps({type: Number as PropType<Advice_Level | undefined>,default: undefined,},+ planCheckRuns: {+ type: Array as PropType<PlanCheckRun[] | undefined>,+ default: undefined,+ },});const emit = defineEmits<{click: [status: Advice_Level];}>();-const { statusSummary, hasAnyStatus } = usePlanCheckStatus(- computed(() => props.plan)+const planCheckRunsRef = computed(() => props.planCheckRuns);++const { statusSummary, hasAnyStatus } = useResolvedPlanCheckStatus(+ computed(() => props.plan),+ planCheckRunsRef);const iconSizeClass = computed(() => {diff --git a/frontend/src/components/Plan/components/SpecDetailView/SpecListSection.vue b/frontend/src/components/Plan/components/SpecDetailView/SpecListSection.vueindex 5d36db2b08..dc2eb50b6c 100644--- a/frontend/src/components/Plan/components/SpecDetailView/SpecListSection.vue+++ b/frontend/src/components/Plan/components/SpecDetailView/SpecListSection.vue@@ -1,5 +1,5 @@<template>- <div class="flex items-center pt-3">+ <div class="flex items-center pt-2"><NTabs:key="`${plan.specs.length}-${selectedSpec.id}`":value="selectedSpec.id"diff --git a/frontend/src/components/Plan/components/SpecDetailView/TargetListSection.vue b/frontend/src/components/Plan/components/SpecDetailView/TargetListSection.vueindex 9578658605..bcdcf76bde 100644--- a/frontend/src/components/Plan/components/SpecDetailView/TargetListSection.vue+++ b/frontend/src/components/Plan/components/SpecDetailView/TargetListSection.vue@@ -35,8 +35,17 @@:key="target"class="inline-flex items-center gap-x-1 px-2 py-1 border rounded-lg cursor-default">- <DatabaseDisplay v-if="isValidDatabaseName(target)" :database="target" size="small" show-environment />- <DatabaseGroupTargetDisplay v-else-if="isValidDatabaseGroupName(target)" :target="target" class="py-1" />+ <DatabaseDisplay+ v-if="isValidDatabaseName(target)"+ :database="target"+ size="medium"+ show-environment+ />+ <DatabaseGroupTargetDisplay+ v-else-if="isValidDatabaseGroupName(target)"+ :target="target"+ class="py-1"+ /><span v-else class="text-sm text-control-placeholder">{{ target }}</span></div><NButtondiff --git a/frontend/src/components/Plan/components/StatementSection/useSQLAdviceMarkers.ts b/frontend/src/components/Plan/components/StatementSection/useSQLAdviceMarkers.tsindex fb989dbffd..671ce15068 100644--- a/frontend/src/components/Plan/components/StatementSection/useSQLAdviceMarkers.ts+++ b/frontend/src/components/Plan/components/StatementSection/useSQLAdviceMarkers.ts@@ -59,7 +59,7 @@ const getLatestAdviceOptions = (if (!latest) {return [];}- // Filter results by type+ // O(n) over this run's results (consolidated model: one run, possibly many rows).const resultList = latest.results.filter((result) => result.type === resultType);diff --git a/frontend/src/components/Plan/logic/index.ts b/frontend/src/components/Plan/logic/index.tsindex 42758f5385..268e07e985 100644--- a/frontend/src/components/Plan/logic/index.ts+++ b/frontend/src/components/Plan/logic/index.ts@@ -4,6 +4,8 @@ export * from "./plan";export * from "./initialize";export * from "./sheet";export * from "./plan-check";+export * from "./plan-check-status";+export * from "./useResolvedPlanCheckStatus";export * from "./utils";export * from "./sidebar";export * from "./usePlanCheckStatus";diff --git a/frontend/src/components/Plan/logic/plan-check-status.ts b/frontend/src/components/Plan/logic/plan-check-status.tsnew file mode 100644index 0000000000..9211f83221--- /dev/null+++ b/frontend/src/components/Plan/logic/plan-check-status.ts@@ -0,0 +1,77 @@+import {+ type PlanCheckRun,+ PlanCheckRun_Status,+} from "@/types/proto-es/v1/plan_service_pb";+import { Advice_Level } from "@/types/proto-es/v1/sql_service_pb";++/**+ * Counts derived from `PlanCheckRun[]` (same shape as API `planCheckRunStatusCount` aggregates).+ *+ * Cost is O(total `results` across runs). The API returns one consolidated run per plan+ * (`refreshPlanCheckRuns` stores `[response]`), so the dominant size is `run.results.length`,+ * not the number of runs.+ */+export interface PlanCheckStatusSummary {+ running: number;+ success: number;+ warning: number;+ error: number;+ total: number;+}++export const EMPTY_PLAN_CHECK_STATUS_SUMMARY: PlanCheckStatusSummary = {+ running: 0,+ success: 0,+ warning: 0,+ error: 0,+ total: 0,+};++/**+ * Counts advice rows plus run-level RUNNING / FAILED, matching ChecksView grouping logic.+ */+export function computePlanCheckStatusSummary(+ runs: PlanCheckRun[]+): PlanCheckStatusSummary {+ let running = 0;+ let success = 0;+ let warning = 0;+ let error = 0;++ for (const checkRun of runs) {+ if (checkRun.status === PlanCheckRun_Status.RUNNING) {+ running++;+ }+ if (checkRun.status === PlanCheckRun_Status.FAILED) {+ error++;+ }+ for (const result of checkRun.results) {+ if (result.status === Advice_Level.ERROR) {+ error++;+ } else if (result.status === Advice_Level.WARNING) {+ warning++;+ } else if (result.status === Advice_Level.SUCCESS) {+ success++;+ }+ }+ }++ const total = running + success + warning + error;+ return { running, success, warning, error, total };+}++/** Worst level for icon / badge emphasis (mirrors `usePlanCheckStatus` plan-level rules). */+export function overallAdviceLevelFromPlanCheckSummary(+ summary: PlanCheckStatusSummary+): Advice_Level {+ if (summary.error > 0) {+ return Advice_Level.ERROR;+ }+ if (summary.warning > 0) {+ return Advice_Level.WARNING;+ }+ if (summary.success > 0) {+ return Advice_Level.SUCCESS;+ }+ return Advice_Level.SUCCESS;+}diff --git a/frontend/src/components/Plan/logic/plan-check.ts b/frontend/src/components/Plan/logic/plan-check.tsindex 92f61ee63d..538543771c 100644--- a/frontend/src/components/Plan/logic/plan-check.ts+++ b/frontend/src/components/Plan/logic/plan-check.ts@@ -2,11 +2,14 @@ import { flatten } from "lodash-es";import { useDBGroupStore } from "@/store";import { isValidDatabaseGroupName, isValidDatabaseName } from "@/types";import { DatabaseGroupView } from "@/types/proto-es/v1/database_group_service_pb";-import type {- Plan_Spec,- PlanCheckRun,+import {+ type Plan_Spec,+ type PlanCheckRun,+ PlanCheckRun_Status,} from "@/types/proto-es/v1/plan_service_pb";+/** Spec targets and slicing consolidated plan check runs per change. Counts: `plan-check-status.ts`. */+export const planSpecHasPlanChecks = (spec: Plan_Spec) => {if (spec.config?.case === "changeDatabaseConfig") {return true;@@ -41,14 +44,45 @@ export const flattenTargetsOfSpec = (spec: Plan_Spec): string[] => {return targets;};+/**+ * Returns plan check runs scoped to `spec`: each run keeps only `results` whose+ * `target` is in this spec’s flattened database list. Handles consolidated+ * in-memory runs (one API row per plan with all databases).+ */export const planCheckRunListForSpec = (planCheckRunList: PlanCheckRun[],spec: Plan_Spec): PlanCheckRun[] => {const targets = flattenTargetsOfSpec(spec);+ if (targets.length === 0) {+ return [];+ }++ // Set lookup: spec can list many DBs; consolidated runs can have huge `results`.+ const targetSet = new Set(targets);++ return planCheckRunList.flatMap((run) => {+ const matchingResults = run.results.filter((result) =>+ targetSet.has(result.target)+ );++ if (matchingResults.length > 0) {+ return [{ ...run, results: matchingResults }];+ }++ // In progress: no per-target rows yet.+ if (+ run.status === PlanCheckRun_Status.RUNNING &&+ run.results.length === 0+ ) {+ return [{ ...run, results: [] }];+ }++ // Run-level failure with no per-target breakdown.+ if (run.status === PlanCheckRun_Status.FAILED && run.results.length === 0) {+ return [{ ...run, results: [] }];+ }- // With consolidated model, filter runs that have results matching our targets- return planCheckRunList.filter((run) => {- return run.results.some((result) => targets.includes(result.target));+ return [];});};diff --git a/frontend/src/components/Plan/logic/poller/utils.ts b/frontend/src/components/Plan/logic/poller/utils.tsindex 5b1a5b931e..498a7cdf38 100644--- a/frontend/src/components/Plan/logic/poller/utils.ts+++ b/frontend/src/components/Plan/logic/poller/utils.ts@@ -42,6 +42,7 @@ export const refreshPlanCheckRuns = async (});try {const response = await planServiceClientConnect.getPlanCheckRun(request);+ // One consolidated run per plan; large payloads are mostly `results[]`.planCheckRuns.value = [response];} catch {// Plan check run might not exist yetdiff --git a/frontend/src/components/Plan/logic/usePlanCheckStatus.ts b/frontend/src/components/Plan/logic/usePlanCheckStatus.tsindex a4d6f562e0..6ba96d14b9 100644--- a/frontend/src/components/Plan/logic/usePlanCheckStatus.ts+++ b/frontend/src/components/Plan/logic/usePlanCheckStatus.ts@@ -4,14 +4,12 @@ import {PlanCheckRun_Status,} from "@/types/proto-es/v1/plan_service_pb";import { Advice_Level } from "@/types/proto-es/v1/sql_service_pb";+import {+ EMPTY_PLAN_CHECK_STATUS_SUMMARY,+ type PlanCheckStatusSummary,+} from "./plan-check-status";-export interface PlanCheckStatusSummary {- running: number;- success: number;- warning: number;- error: number;- total: number;-}+export type { PlanCheckStatusSummary } from "./plan-check-status";export const usePlanCheckStatus = (plan: ComputedRef<Plan | undefined> | Ref<Plan | undefined>@@ -41,7 +39,7 @@ export const usePlanCheckStatus = (const statusSummary = computed<PlanCheckStatusSummary>(() => {if (!plan.value) {- return { running: 0, success: 0, warning: 0, error: 0, total: 0 };+ return { ...EMPTY_PLAN_CHECK_STATUS_SUMMARY };}const statusCount = plan.value.planCheckRunStatusCount || {};diff --git a/frontend/src/components/Plan/logic/useResolvedPlanCheckStatus.ts b/frontend/src/components/Plan/logic/useResolvedPlanCheckStatus.tsnew file mode 100644index 0000000000..d613959a4f--- /dev/null+++ b/frontend/src/components/Plan/logic/useResolvedPlanCheckStatus.ts@@ -0,0 +1,58 @@+import { type ComputedRef, computed, type Ref } from "vue";+import type { Plan, PlanCheckRun } from "@/types/proto-es/v1/plan_service_pb";+import { Advice_Level } from "@/types/proto-es/v1/sql_service_pb";+import {+ computePlanCheckStatusSummary,+ overallAdviceLevelFromPlanCheckSummary,+} from "./plan-check-status";+import { usePlanCheckStatus } from "./usePlanCheckStatus";++/**+ * Resolves plan check counts from either:+ * - explicit `planCheckRuns` (e.g. filtered to the current spec), or+ * - `plan.planCheckRunStatusCount` (API aggregate for the whole plan).+ */+export const useResolvedPlanCheckStatus = (+ plan: ComputedRef<Plan | undefined> | Ref<Plan | undefined>,+ planCheckRunsOpt?:+ | ComputedRef<PlanCheckRun[] | undefined>+ | Ref<PlanCheckRun[] | undefined>+) => {+ const planLevel = usePlanCheckStatus(plan);++ const runBasedSummary = computed(() => {+ const runs = planCheckRunsOpt?.value;+ if (runs === undefined) {+ return undefined;+ }+ return computePlanCheckStatusSummary(runs);+ });++ const statusSummary = computed(() => {+ return runBasedSummary.value ?? planLevel.statusSummary.value;+ });++ const hasAnyStatus = computed(() => statusSummary.value.total > 0);++ const overallAdviceLevel = computed((): Advice_Level => {+ if (runBasedSummary.value !== undefined) {+ return overallAdviceLevelFromPlanCheckSummary(runBasedSummary.value);+ }+ return planLevel.getOverallStatus.value;+ });++ const hasRunning = computed(() => {+ if (runBasedSummary.value !== undefined) {+ return runBasedSummary.value.running > 0;+ }+ return planLevel.hasRunning.value;+ });++ return {+ statusSummary,+ hasAnyStatus,+ overallAdviceLevel,+ hasRunning,+ planLevel,+ };+};