Skip to content

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

chore: add more plan check status checks (#12135)

boojack119b2b468523
diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateIssueButton.vue b/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateIssueButton.vue
index 7dc3d6bfe7..2498248993 100644
--- a/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateIssueButton.vue
+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateIssueButton.vue
@@ -28,19 +28,25 @@
</template>
<script setup lang="ts">
+import { uniqBy } from "lodash-es";
import { NTooltip, NButton } from "naive-ui";
import { zindexable as vZindexable } from "vdirs";
import { computed, nextTick, ref } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import { ErrorList } from "@/components/Plan/components/common";
-import { usePlanContext } from "@/components/Plan/logic";
+import {
+ planCheckRunListForSpec,
+ planCheckRunSummaryForCheckRunList,
+ usePlanContext,
+} from "@/components/Plan/logic";
import { useSQLCheckContext } from "@/components/SQLCheck";
import { issueServiceClient, rolloutServiceClient } from "@/grpcweb";
import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";
import { useCurrentUserV1 } from "@/store";
import { emptyIssue, type ComposedIssue } from "@/types";
import { Issue, IssueStatus, Issue_Type } from "@/types/proto/v1/issue_service";
+import { PlanCheckRun_Result_Status } from "@/types/proto/v1/plan_service";
import {
extractProjectResourceName,
hasProjectPermissionV2,
@@ -54,6 +60,23 @@ const { runSQLCheck } = useSQLCheckContext();
const me = useCurrentUserV1();
const loading = ref(false);
+const planCheckStatus = computed((): PlanCheckRun_Result_Status => {
+ const planCheckList = uniqBy(
+ plan.value.steps.flatMap((step) =>
+ step.specs.flatMap((spec) => planCheckRunListForSpec(plan.value, spec))
+ ),
+ (checkRun) => checkRun.uid
+ );
+ const summary = planCheckRunSummaryForCheckRunList(planCheckList);
+ if (summary.errorCount > 0) {
+ return PlanCheckRun_Result_Status.ERROR;
+ }
+ if (summary.warnCount > 0) {
+ return PlanCheckRun_Result_Status.WARNING;
+ }
+ return PlanCheckRun_Result_Status.SUCCESS;
+});
+
const issueCreateErrorList = computed(() => {
const errorList: string[] = [];
if (
@@ -68,7 +91,13 @@ const issueCreateErrorList = computed(() => {
if (!plan.value.title.trim()) {
errorList.push("Missing issue title");
}
-
+ if (planCheckStatus.value !== PlanCheckRun_Result_Status.SUCCESS) {
+ errorList.push(
+ t(
+ "custom-approval.issue-review.disallow-approve-reason.some-task-checks-didnt-pass"
+ )
+ );
+ }
return errorList;
});
diff --git a/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue b/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue
index 72b02a5f9e..ec7a9683e9 100644
--- a/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue
+++ b/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue
@@ -1,13 +1,34 @@
<template>
<div
- class="px-3 py-2 cursor-pointer border rounded lg:flex-1 flex justify-between items-stretch overflow-hidden gap-x-1"
+ class="px-3 py-2 w-full cursor-pointer border rounded lg:flex-1 flex justify-start items-center overflow-hidden gap-x-1"
:class="specClass"
@click="onClickSpec(spec)"
>
- <div
- v-if="isDatabaseChangeSpec(spec)"
- class="w-full flex items-center gap-2"
+ <NTooltip
+ v-if="
+ planCheckStatus === PlanCheckRun_Result_Status.ERROR ||
+ planCheckStatus === PlanCheckRun_Result_Status.WARNING
+ "
+ trigger="hover"
+ placement="top"
>
+ <template #trigger>
+ <heroicons:exclamation-circle-solid
+ class="w-5 h-5 mr-1"
+ :class="[
+ planCheckStatus === PlanCheckRun_Result_Status.ERROR
+ ? 'text-error hover:text-error-hover'
+ : 'text-warning hover:text-warning-hover',
+ ]"
+ />
+ </template>
+ <span>{{
+ $t(
+ "custom-approval.issue-review.disallow-approve-reason.some-task-checks-didnt-pass"
+ )
+ }}</span>
+ </NTooltip>
+ <div v-if="isDatabaseChangeSpec(spec)" class="flex items-center gap-2">
<InstanceV1Name
:instance="databaseForSpec(plan, spec).instanceEntity"
:link="false"
@@ -19,7 +40,7 @@
</div>
<div
v-else-if="isGroupingChangeSpec(spec) && relatedDatabaseGroup"
- class="w-full flex items-center gap-2"
+ class="flex items-center gap-2"
>
<NTooltip>
<template #trigger><DatabaseGroupIcon class="w-4 h-auto" /></template>
@@ -31,7 +52,7 @@
</div>
<div
v-else-if="isDeploymentConfigChangeSpec(spec)"
- class="w-full flex items-center"
+ class="flex items-center"
>
<TenantIcon class="w-4 h-auto" />
<span class="text-gray-500 text-sm truncate ml-1 mr-2">
@@ -40,9 +61,7 @@
<span class="text-sm">{{ $t("common.deployment-config") }}</span>
</div>
<!-- Fallback -->
- <div v-else class="w-full flex items-center gap-2 text-sm">
- Unknown type
- </div>
+ <div v-else class="flex items-center gap-2 text-sm">Unknown type</div>
</div>
</template>
@@ -53,29 +72,46 @@ import { computed, onMounted } from "vue";
import DatabaseGroupIcon from "@/components/DatabaseGroupIcon.vue";
import TenantIcon from "@/components/TenantIcon.vue";
import { useDBGroupStore } from "@/store";
-import type { Plan_Spec } from "@/types/proto/v1/plan_service";
+import {
+ PlanCheckRun_Result_Status,
+ type Plan_Spec,
+} from "@/types/proto/v1/plan_service";
import {
databaseForSpec,
isDatabaseChangeSpec,
usePlanContext,
isGroupingChangeSpec,
isDeploymentConfigChangeSpec,
+ planCheckRunListForSpec,
+ planCheckRunSummaryForCheckRunList,
} from "../../logic";
const props = defineProps<{
spec: Plan_Spec;
}>();
-const { plan, selectedSpec, events } = usePlanContext();
+const { isCreating, plan, selectedSpec, events } = usePlanContext();
const dbGroupStore = useDBGroupStore();
const project = computed(() => plan.value.projectEntity);
const specClass = computed(() => {
const classes: string[] = [];
- if (isEqual(props.spec, selectedSpec.value)) {
+ const isSelected = isEqual(props.spec, selectedSpec.value);
+ if (isSelected) {
classes.push("border-accent bg-accent bg-opacity-5 shadow");
}
+ if (planCheckStatus.value === PlanCheckRun_Result_Status.WARNING) {
+ classes.push("bg-warning bg-opacity-5");
+ if (isSelected) {
+ classes.push("border-warning");
+ }
+ } else if (planCheckStatus.value === PlanCheckRun_Result_Status.ERROR) {
+ classes.push("bg-error bg-opacity-5");
+ if (isSelected) {
+ classes.push("border-error");
+ }
+ }
return classes;
});
@@ -86,6 +122,21 @@ const relatedDatabaseGroup = computed(() => {
return dbGroupStore.getDBGroupByName(props.spec.changeDatabaseConfig!.target);
});
+const planCheckStatus = computed((): PlanCheckRun_Result_Status => {
+ if (isCreating.value) return PlanCheckRun_Result_Status.STATUS_UNSPECIFIED;
+
+ const summary = planCheckRunSummaryForCheckRunList(
+ planCheckRunListForSpec(plan.value, props.spec)
+ );
+ if (summary.errorCount > 0) {
+ return PlanCheckRun_Result_Status.ERROR;
+ }
+ if (summary.warnCount > 0) {
+ return PlanCheckRun_Result_Status.WARNING;
+ }
+ return PlanCheckRun_Result_Status.SUCCESS;
+});
+
onMounted(async () => {
if (isGroupingChangeSpec(props.spec)) {
await dbGroupStore.getOrFetchDBGroupByName(
diff --git a/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue b/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue
index b4073d00f5..63d4be3da7 100644
--- a/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue
+++ b/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue
@@ -247,7 +247,7 @@ type LocalState = EditState & {
};
const { t } = useI18n();
-const { isCreating, plan, selectedSpec, selectedStep, formatOnSave } =
+const { isCreating, plan, selectedSpec, selectedStep, formatOnSave, events } =
usePlanContext();
const project = computed(() => plan.value.projectEntity);
const dialog = useDialog();
@@ -604,14 +604,12 @@ const updateStatement = async (statement: string) => {
sheet
);
- for (let i = 0; i < specsToPatch.length; i++) {
- const spec = specsToPatch[i];
- let config = undefined;
+ for (const spec of specsToPatch) {
if (spec.changeDatabaseConfig) {
- config = spec.changeDatabaseConfig;
+ spec.changeDatabaseConfig.sheet = createdSheet.name;
+ } else {
+ console.error("Unexpected spec type", spec);
}
- if (!config) continue;
- config.sheet = createdSheet.name;
}
const updatedPlan = await planServiceClient.updatePlan({
@@ -621,6 +619,8 @@ const updateStatement = async (statement: string) => {
Object.assign(plan.value, updatedPlan);
+ events.emit("status-changed", { eager: true });
+
pushNotification({
module: "bytebase",
style: "SUCCESS",
diff --git a/frontend/src/components/Plan/components/StepSection/StepCard.vue b/frontend/src/components/Plan/components/StepSection/StepCard.vue
index 0ba0f0dda1..cd93ab21fc 100644
--- a/frontend/src/components/Plan/components/StepSection/StepCard.vue
+++ b/frontend/src/components/Plan/components/StepSection/StepCard.vue
@@ -1,15 +1,6 @@
<template>
<div class="step" :class="stepClass">
- <div class="text" @click="handleClickStep">
- <div class="text-sm min-w-32 lg:min-w-fit space-x-1 whitespace-nowrap">
- <heroicons:arrow-small-right
- v-if="isSelectedStep"
- class="w-5 h-5 inline-block mb-0.5"
- />
- <span>{{ step.title }} {{ $t("common.stage") }}</span>
- </div>
- </div>
-
+ <ArrowRightIcon v-if="isSelectedStep" class="w-5 h-5 mr-1 inline-block" />
<NTooltip
v-if="isCreating && !validateSpecs()"
trigger="hover"
@@ -17,7 +8,7 @@
>
<template #trigger>
<heroicons:exclamation-circle-solid
- class="w-6 h-6 ml-2 text-error hover:text-error-hover"
+ class="w-6 h-6 mx-1 text-error hover:text-error-hover"
/>
</template>
<span>{{ $t("issue.missing-sql-statement") }}</span>
@@ -33,7 +24,7 @@
>
<template #trigger>
<heroicons:exclamation-circle-solid
- class="w-6 h-6 ml-2"
+ class="w-6 h-6 mx-1"
:class="[
planCheckStatus === PlanCheckRun_Result_Status.ERROR
? 'text-error hover:text-error-hover'
@@ -47,11 +38,17 @@
)
}}</span>
</NTooltip>
+ <div class="text" @click="handleClickStep">
+ <div class="text-sm min-w-32 lg:min-w-fit space-x-1 whitespace-nowrap">
+ <span>{{ step.title }} {{ $t("common.stage") }}</span>
+ </div>
+ </div>
</div>
</template>
<script lang="ts" setup>
import { head, isEqual, uniqBy } from "lodash-es";
+import { ArrowRightIcon } from "lucide-vue-next";
import { NTooltip } from "naive-ui";
import { computed } from "vue";
import {
diff --git a/frontend/src/components/Plan/logic/context.ts b/frontend/src/components/Plan/logic/context.ts
index 782031bac3..0a67c1dc93 100644
--- a/frontend/src/components/Plan/logic/context.ts
+++ b/frontend/src/components/Plan/logic/context.ts
@@ -7,6 +7,7 @@ import type { Plan_Spec, Plan_Step } from "@/types/proto/v1/plan_service";
import type { ComposedPlan } from "@/types/v1/issue/plan";
export type PlanEvents = Emittery<{
+ "status-changed": { eager: boolean };
"select-spec": { spec: Plan_Spec };
}>;
diff --git a/frontend/src/components/Plan/logic/poll.ts b/frontend/src/components/Plan/logic/poll.ts
index 3d44bf1f23..83a5ca8e23 100644
--- a/frontend/src/components/Plan/logic/poll.ts
+++ b/frontend/src/components/Plan/logic/poll.ts
@@ -5,7 +5,7 @@ import { extractProjectResourceName } from "@/utils";
import { usePlanContext } from "./context";
export const usePollPlan = () => {
- const { isCreating, ready, plan } = usePlanContext();
+ const { isCreating, ready, plan, events } = usePlanContext();
const planStore = usePlanStore();
const shouldPollPlan = computed(() => {
@@ -32,6 +32,13 @@ export const usePollPlan = () => {
},
});
+ events.on("status-changed", ({ eager }) => {
+ if (eager) {
+ refreshPlan();
+ poller.restart();
+ }
+ });
+
watch(
shouldPollPlan,
() => {