Skip to content

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

chore: sql check in issue level (#15685)

boojacke1837f3094d2
diff --git a/frontend/src/components/IssueV1/DataExportIssueDetailPage.vue b/frontend/src/components/IssueV1/DataExportIssueDetailPage.vue
index a9dd999ae7..c6d44f56a0 100644
--- a/frontend/src/components/IssueV1/DataExportIssueDetailPage.vue
+++ b/frontend/src/components/IssueV1/DataExportIssueDetailPage.vue
@@ -63,7 +63,6 @@
<script setup lang="ts">
import { ref } from "vue";
import type { Task } from "@/types/proto/v1/rollout_service";
-import { provideSQLCheckContext } from "../SQLCheck";
import { Drawer } from "../v2";
import {
BannerSection,
@@ -80,6 +79,7 @@ import {
DataExportSection,
TaskRunSection,
} from "./components";
+import { provideIssueSQLCheckContext } from "./components/SQLCheckSection/context";
import type {
IssueReviewAction,
IssueStatusAction,
@@ -126,7 +126,7 @@ events.on("perform-task-rollout-action", async ({ action, tasks }) => {
};
});
-provideSQLCheckContext();
+provideIssueSQLCheckContext();
const {
mode: sidebarMode,
diff --git a/frontend/src/components/IssueV1/IssueDetailPage.vue b/frontend/src/components/IssueV1/IssueDetailPage.vue
index 6f91f2f7f0..4d5d38e0f1 100644
--- a/frontend/src/components/IssueV1/IssueDetailPage.vue
+++ b/frontend/src/components/IssueV1/IssueDetailPage.vue
@@ -15,10 +15,10 @@
<TaskRunSection v-if="!isCreating" />
- <SQLCheckSection v-if="isCreating" @update:advices="advices = $event" />
+ <SQLCheckSection v-if="isCreating" />
<PlanCheckSection v-if="!isCreating" />
- <StatementSection :advices="advices" />
+ <StatementSection />
<DescriptionSection />
@@ -71,8 +71,6 @@
<script setup lang="ts">
import { ref } from "vue";
import { type Task } from "@/types/proto/v1/rollout_service";
-import type { Advice } from "@/types/proto/v1/sql_service";
-import { provideSQLCheckContext } from "../SQLCheck";
import { Drawer } from "../v2";
import {
BannerSection,
@@ -90,6 +88,7 @@ import {
SQLCheckSection,
IssueCommentSection,
} from "./components";
+import { provideIssueSQLCheckContext } from "./components/SQLCheckSection/context";
import type {
IssueReviewAction,
IssueStatusAction,
@@ -103,7 +102,6 @@ import {
const containerRef = ref<HTMLElement>();
const { isCreating, events } = useIssueContext();
-const advices = ref<Advice[]>();
const ongoingIssueReviewAction = ref<{
action: IssueReviewAction;
@@ -137,7 +135,7 @@ events.on("perform-task-rollout-action", async ({ action, tasks }) => {
};
});
-provideSQLCheckContext();
+provideIssueSQLCheckContext();
const {
mode: sidebarMode,
diff --git a/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vue b/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vue
index 412e59d16e..3b90ae37c7 100644
--- a/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vue
+++ b/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vue
@@ -25,10 +25,25 @@
class="fixed inset-0 pointer-events-auto flex flex-col items-center justify-center"
@click.stop.prevent
/>
+
+ <SQLCheckPanel
+ v-if="showSQLCheckResultPanel && databaseForTask(issue, selectedTask)"
+ :database="databaseForTask(issue, selectedTask)"
+ :advices="checkResultMap[databaseForTask(issue, selectedTask).name].advices"
+ :affected-rows="
+ checkResultMap[databaseForTask(issue, selectedTask).name].affectedRows
+ "
+ :risk-level="
+ checkResultMap[databaseForTask(issue, selectedTask).name].riskLevel
+ "
+ :confirm="sqlCheckConfirmDialog"
+ :override-title="$t('issue.sql-check.sql-review-violations')"
+ />
</template>
<script setup lang="ts">
import { NTooltip, NButton } from "naive-ui";
+import { v4 as uuidv4 } from "uuid";
import { zindexable as vZindexable } from "vdirs";
import { computed, nextTick, ref, toRaw } from "vue";
import { useI18n } from "vue-i18n";
@@ -45,10 +60,12 @@ import {
useIssueContext,
} from "@/components/IssueV1/logic";
import formatSQL from "@/components/MonacoEditor/sqlFormatter";
-import { useSQLCheckContext } from "@/components/SQLCheck";
+import { SQLCheckPanel } from "@/components/SQLCheck";
+import { STATEMENT_SKIP_CHECK_THRESHOLD } from "@/components/SQLCheck/common";
import {
issueServiceClient,
planServiceClient,
+ releaseServiceClient,
rolloutServiceClient,
} from "@/grpcweb";
import { emitWindowEvent } from "@/plugins";
@@ -59,8 +76,11 @@ import { dialectOfEngineV1, languageOfEngineV1 } from "@/types";
import { Issue } from "@/types/proto/v1/issue_service";
import type { Plan_ExportDataConfig } from "@/types/proto/v1/plan_service";
import { type Plan_ChangeDatabaseConfig } from "@/types/proto/v1/plan_service";
+import { ReleaseFileType } from "@/types/proto/v1/release_service";
import type { Sheet } from "@/types/proto/v1/sheet_service";
+import { Advice_Status } from "@/types/proto/v1/sql_service";
import {
+ defer,
extractIssueUID,
extractProjectResourceName,
extractSheetUID,
@@ -70,16 +90,25 @@ import {
issueV1Slug,
setSheetStatement,
sheetNameOfTaskV1,
+ type Defer,
} from "@/utils";
+import { getTaskChangeType } from "../../../SQLCheckSection/common";
+import { useIssueSQLCheckContext } from "../../../SQLCheckSection/context";
const MAX_FORMATTABLE_STATEMENT_SIZE = 10000; // 10K characters
const { t } = useI18n();
const router = useRouter();
-const { issue, formatOnSave } = useIssueContext();
-const { runSQLCheck } = useSQLCheckContext();
+const { issue, formatOnSave, events, selectedTask } = useIssueContext();
+const {
+ enabled: shouldRunSQLCheck,
+ resultMap: checkResultMap,
+ upsertResult,
+} = useIssueSQLCheckContext();
const sheetStore = useSheetV1Store();
const loading = ref(false);
+const showSQLCheckResultPanel = ref(false);
+const sqlCheckConfirmDialog = ref<Defer<boolean>>();
const issueCreateErrorList = computed(() => {
const errorList: string[] = [];
@@ -124,8 +153,8 @@ const issueCreateErrorList = computed(() => {
const doCreateIssue = async () => {
loading.value = true;
- const check = runSQLCheck.value;
- if (check && !(await check())) {
+ // Run SQL check for issue creation.
+ if (!(await runSQLCheckForIssue())) {
loading.value = false;
return;
}
@@ -289,4 +318,84 @@ const emitIssueCreateWindowEvent = async (issue: ComposedIssue) => {
}
emitWindowEvent("bb.issue-create", eventParams);
};
+
+const runSQLCheckForIssue = async () => {
+ if (!shouldRunSQLCheck.value) {
+ return true;
+ }
+
+ const flattenTasks = flattenTaskV1List(issue.value.rolloutEntity);
+ const statementTargetsMap = new Map<string, string[]>();
+ for (const task of flattenTasks) {
+ const sheetName = sheetNameOfTaskV1(task);
+ let sheet: Sheet | undefined;
+ if (extractSheetUID(sheetName).startsWith("-")) {
+ sheet = getLocalSheetByName(sheetName);
+ } else {
+ sheet = await sheetStore.getOrFetchSheetByName(sheetName);
+ }
+ if (!sheet) continue;
+ const statement = getSheetStatement(sheet);
+ const database = databaseForTask(issue.value, task);
+ if (!statement) {
+ continue;
+ }
+ if (statement.length > STATEMENT_SKIP_CHECK_THRESHOLD) {
+ continue;
+ }
+ statementTargetsMap.set(
+ statement,
+ statementTargetsMap.get(statement)?.concat(database.name) ?? [
+ database.name,
+ ]
+ );
+ }
+ for (const [statement, targets] of statementTargetsMap.entries()) {
+ const result = await releaseServiceClient.checkRelease({
+ parent: issue.value.project,
+ release: {
+ files: [
+ {
+ // Use a random uuid to avoid duplication.
+ version: uuidv4(),
+ type: ReleaseFileType.VERSIONED,
+ statement: statement,
+ changeType: getTaskChangeType(issue.value, flattenTasks[0]),
+ },
+ ],
+ },
+ targets: targets,
+ });
+ for (const r of result?.results || []) {
+ upsertResult(r.target, r);
+ }
+ }
+
+ for (const checkResult of Object.values(checkResultMap.value)) {
+ const hasErrors = checkResult.advices.some((advice) => {
+ return advice.status === Advice_Status.ERROR;
+ });
+ // Focus on the first task with error.
+ if (hasErrors) {
+ loading.value = false;
+ const task = flattenTaskV1List(issue.value.rolloutEntity).find((t) => {
+ return t.target === checkResult.target;
+ });
+ if (task) {
+ events.emit("select-task", { task });
+ const d = defer<boolean>();
+ sqlCheckConfirmDialog.value = d;
+ d.promise.finally(() => {
+ sqlCheckConfirmDialog.value = undefined;
+ showSQLCheckResultPanel.value = false;
+ });
+ showSQLCheckResultPanel.value = true;
+ return await d.promise;
+ }
+ return false;
+ }
+ }
+
+ return true;
+};
</script>
diff --git a/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckBadge.vue b/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckBadge.vue
index 3d03e089da..23729f6422 100644
--- a/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckBadge.vue
+++ b/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckBadge.vue
@@ -41,8 +41,8 @@ import { databaseForTask, useIssueContext } from "../../logic";
import { TaskSpinner } from "../common";
const props = defineProps<{
- isRunning: boolean;
advices: Advice[];
+ isRunning?: boolean;
}>();
defineEmits<{
diff --git a/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckButton.vue b/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckButton.vue
new file mode 100644
index 0000000000..b0f674ec5b
--- /dev/null
+++ b/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckButton.vue
@@ -0,0 +1,200 @@
+<template>
+ <NPopover :disabled="statementErrors.length === 0" to="body">
+ <template #trigger>
+ <NButton
+ style="--n-padding: 0 14px 0 10px"
+ :disabled="statementErrors.length > 0"
+ :style="buttonStyle"
+ tag="div"
+ size="small"
+ @click="handleButtonClick"
+ >
+ <template #icon>
+ <BBSpin v-if="isRunning" :size="20" />
+ <heroicons-outline:play v-else class="w-4 h-4" />
+ </template>
+ <template #default>
+ <template v-if="isRunning">
+ {{ $t("task.checking") }}
+ </template>
+ <template v-else>
+ {{ $t("task.run-checks") }}
+ </template>
+ </template>
+ </NButton>
+ </template>
+ <template #default>
+ <ErrorList :errors="statementErrors" />
+ </template>
+ </NPopover>
+
+ <SQLCheckPanel
+ v-if="checkResult && advices && showDetailPanel"
+ :database="database"
+ :advices="advices"
+ :affected-rows="checkResult.affectedRows"
+ :risk-level="checkResult.riskLevel"
+ :confirm="confirmDialog"
+ :override-title="$t('issue.sql-check.sql-review-violations')"
+ :show-code-location="showCodeLocation"
+ :allow-force-continue="allowForceContinue"
+ @close="onPanelClose"
+ >
+ <template #row-title-extra="{ row }">
+ <slot name="row-title-extra" :row="row" :confirm="confirmDialog" />
+ </template>
+ </SQLCheckPanel>
+</template>
+
+<script lang="ts" setup>
+import { asyncComputed } from "@vueuse/core";
+import { NButton, NPopover } from "naive-ui";
+import { v4 as uuidv4 } from "uuid";
+import { computed, ref, watch } from "vue";
+import { useI18n } from "vue-i18n";
+import { BBSpin } from "@/bbkit";
+import { SQLCheckPanel } from "@/components/SQLCheck";
+import { STATEMENT_SKIP_CHECK_THRESHOLD } from "@/components/SQLCheck/common";
+import ErrorList from "@/components/misc/ErrorList.vue";
+import { releaseServiceClient } from "@/grpcweb";
+import {
+ CheckReleaseResponse,
+ ReleaseFileType,
+} from "@/types/proto/v1/release_service";
+import { Advice, Advice_Status } from "@/types/proto/v1/sql_service";
+import type { Defer, VueStyle } from "@/utils";
+import { defer } from "@/utils";
+import { databaseForTask, useIssueContext } from "../../logic";
+import { useTaskSheet } from "../StatementSection/useTaskSheet";
+import { getTaskChangeType } from "./common";
+import { useIssueSQLCheckContext } from "./context";
+
+withDefaults(
+ defineProps<{
+ buttonStyle?: VueStyle;
+ showCodeLocation?: boolean;
+ }>(),
+ {
+ buttonStyle: undefined,
+ showCodeLocation: undefined,
+ }
+);
+
+const { t } = useI18n();
+const { issue, selectedTask } = useIssueContext();
+const { upsertResult } = useIssueSQLCheckContext();
+const { sheetStatement } = useTaskSheet();
+
+const isRunning = ref(false);
+const showDetailPanel = ref(false);
+const allowForceContinue = ref(true);
+const confirmDialog = ref<Defer<boolean>>();
+const checkResult = ref<CheckReleaseResponse | undefined>();
+
+const advices = computed(() => {
+ return checkResult.value?.results.flatMap((r) => r.advices);
+});
+
+const database = computed(() =>
+ databaseForTask(issue.value, selectedTask.value)
+);
+
+const statement = computed(() => sheetStatement.value);
+
+const changeType = computed(() =>
+ getTaskChangeType(issue.value, selectedTask.value)
+);
+
+const statementErrors = asyncComputed(async () => {
+ if (statement.value.length === 0) {
+ return [t("issue.sql-check.statement-is-required")];
+ }
+ if (new Blob([statement.value]).size > STATEMENT_SKIP_CHECK_THRESHOLD) {
+ return [t("issue.sql-check.statement-is-too-large")];
+ }
+ return [];
+}, []);
+
+const runCheckInternal = async (statement: string) => {
+ const result = await releaseServiceClient.checkRelease({
+ parent: database.value.project,
+ release: {
+ files: [
+ {
+ // Use a random uuid to avoid duplication.
+ version: uuidv4(),
+ type: ReleaseFileType.VERSIONED,
+ statement: statement,
+ changeType: changeType.value,
+ },
+ ],
+ },
+ targets: [database.value.name],
+ });
+ return result;
+};
+
+const handleButtonClick = async () => {
+ await runChecks();
+
+ if (hasError.value) {
+ const d = defer<boolean>();
+ d.promise.finally(onPanelClose);
+ showDetailPanel.value = true;
+ return d.promise;
+ }
+};
+
+const runChecks = async () => {
+ if (statementErrors.value.length > 0) {
+ return;
+ }
+
+ const handleErrors = (errors: string[]) => {
+ // Mock the pre-check errors to advices.
+ checkResult.value = CheckReleaseResponse.fromPartial({
+ results: [
+ {
+ advices: errors.map((err) =>
+ Advice.fromPartial({
+ title: "Pre check",
+ status: Advice_Status.WARNING,
+ content: err,
+ })
+ ),
+ },
+ ],
+ });
+ isRunning.value = false;
+ };
+
+ isRunning.value = true;
+ if (new Blob([statement.value]).size > STATEMENT_SKIP_CHECK_THRESHOLD) {
+ return handleErrors([t("issue.sql-check.statement-is-too-large")]);
+ }
+ try {
+ checkResult.value = await runCheckInternal(statement.value);
+ } finally {
+ isRunning.value = false;
+ }
+};
+
+const onPanelClose = () => {
+ showDetailPanel.value = false;
+ confirmDialog.value = undefined;
+};
+
+const hasError = computed(() => {
+ return advices.value?.some(
+ (advice) =>
+ advice.status === Advice_Status.ERROR ||
+ advice.status === Advice_Status.WARNING
+ );
+});
+
+watch(checkResult, (result) => {
+ for (const r of result?.results || []) {
+ upsertResult(r.target, r);
+ }
+});
+</script>
diff --git a/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckSection.vue b/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckSection.vue
index 63dbd3a874..688f41e968 100644
--- a/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckSection.vue
+++ b/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckSection.vue
@@ -1,75 +1,62 @@
<template>
- <div v-if="show" class="flex items-center gap-x-4 px-4 py-2">
+ <div v-if="show" class="w-full flex items-center gap-x-4 px-4 py-2">
<div class="textlabel h-[26px] inline-flex items-center">
{{ $t("issue.sql-check.sql-checks") }}
</div>
-
- <SQLCheckButton
+ <div
v-if="database"
- :key="selectedTask.name"
- :get-statement="getStatement"
- :database="database"
- :change-type="changeType"
- :button-props="{
- size: 'small',
- }"
- button-style="--n-padding: 0 8px 0 6px; --n-icon-margin: 3px;"
- class="justify-between flex-1"
- :show-code-location="true"
- @update:advices="$emit('update:advices', $event)"
+ class="grow flex flex-row items-center justify-between gap-2"
>
- <template #result="{ affectedRows, advices, isRunning }">
- <span v-if="advices === undefined" class="textinfolabel">
- {{ $t("issue.sql-check.not-executed-yet") }}
- </span>
- <div v-else class="flex flex-row justify-start items-center gap-2">
- <SQLCheckBadge :is-running="isRunning" :advices="advices" />
- <NTooltip v-if="affectedRows && affectedRows > 0">
- <template #trigger>
- <NTag round>
- <span class="opacity-80"
- >{{ $t("task.check-type.affected-rows.self") }}:
- </span>
- <span>{{ affectedRows }}</span>
- </NTag>
- </template>
- {{ $t("task.check-type.affected-rows.description") }}
- </NTooltip>
- </div>
- </template>
- </SQLCheckButton>
+ <span v-if="checkResult === undefined" class="textinfolabel">
+ {{ $t("issue.sql-check.not-executed-yet") }}
+ </span>
+ <div v-else class="flex flex-row justify-start items-center gap-2">
+ <SQLCheckBadge :advices="checkResult.advices" />
+ <NTooltip v-if="checkResult.affectedRows > 0">
+ <template #trigger>
+ <NTag round>
+ <span class="opacity-80"
+ >{{ $t("task.check-type.affected-rows.self") }}:
+ </span>
+ <span>{{ checkResult.affectedRows }}</span>
+ </NTag>
+ </template>
+ {{ $t("task.check-type.affected-rows.description") }}
+ </NTooltip>
+ </div>
+
+ <SQLCheckButton
+ :key="selectedTask.name"
+ :database="database"
+ button-style="--n-padding: 0 8px 0 6px; --n-icon-margin: 3px;"
+ :show-code-location="true"
+ />
+ </div>
</div>
</template>
<script lang="ts" setup>
import { NTag, NTooltip } from "naive-ui";
import { computed } from "vue";
-import {
- useIssueContext,
- databaseForTask,
- specForTask,
-} from "@/components/IssueV1/logic";
-import { SQLCheckButton } from "@/components/SQLCheck";
+import { useIssueContext, databaseForTask } from "@/components/IssueV1/logic";
import { TaskTypeListWithStatement } from "@/types";
-import { Plan_ChangeDatabaseConfig_Type } from "@/types/proto/v1/plan_service";
-import { Release_File_ChangeType } from "@/types/proto/v1/release_service";
import { Task_Type } from "@/types/proto/v1/rollout_service";
-import { Advice } from "@/types/proto/v1/sql_service";
-import { useTaskSheet } from "../StatementSection/useTaskSheet";
import SQLCheckBadge from "./SQLCheckBadge.vue";
-
-defineEmits<{
- (event: "update:advices", advices: Advice[] | undefined): void;
-}>();
+import SQLCheckButton from "./SQLCheckButton.vue";
+import { useIssueSQLCheckContext } from "./context";
const { issue, selectedTask } = useIssueContext();
-const { sheetStatement } = useTaskSheet();
+
+const { enabled, resultMap } = useIssueSQLCheckContext();
const database = computed(() => {
return databaseForTask(issue.value, selectedTask.value);
});
const show = computed(() => {
+ if (!enabled.value) {
+ return false;
+ }
const type = selectedTask.value.type;
if (type === Task_Type.DATABASE_SCHEMA_BASELINE) {
return false;
@@ -80,23 +67,8 @@ const show = computed(() => {
return false;
});
-const getStatement = async () => {
- return {
- statement: sheetStatement.value,
- errors: [],
- };
-};
-
-const changeType = computed((): Release_File_ChangeType | undefined => {
- const spec = specForTask(issue.value.planEntity, selectedTask.value);
- switch (spec?.changeDatabaseConfig?.type) {
- case Plan_ChangeDatabaseConfig_Type.MIGRATE:
- return Release_File_ChangeType.DDL;
- case Plan_ChangeDatabaseConfig_Type.MIGRATE_GHOST:
- return Release_File_ChangeType.DDL_GHOST;
- case Plan_ChangeDatabaseConfig_Type.DATA:
- return Release_File_ChangeType.DML;
- }
- return undefined;
+const checkResult = computed(() => {
+ const database = databaseForTask(issue.value, selectedTask.value);
+ return resultMap.value[database.name] || undefined;
});
</script>
diff --git a/frontend/src/components/IssueV1/components/SQLCheckSection/common.ts b/frontend/src/components/IssueV1/components/SQLCheckSection/common.ts
new file mode 100644
index 0000000000..6006a4ad6e
--- /dev/null
+++ b/frontend/src/components/IssueV1/components/SQLCheckSection/common.ts
@@ -0,0 +1,22 @@
+import type { ComposedIssue } from "@/types";
+import { Plan_ChangeDatabaseConfig_Type } from "@/types/proto/v1/plan_service";
+import { Release_File_ChangeType } from "@/types/proto/v1/release_service";
+import type { Task } from "@/types/proto/v1/rollout_service";
+import { specForTask } from "../../logic";
+
+export const getTaskChangeType = (
+ issue: ComposedIssue,
+ task: Task
+): Release_File_ChangeType => {
+ const spec = specForTask(issue.planEntity, task);
+ switch (spec?.changeDatabaseConfig?.type) {
+ case Plan_ChangeDatabaseConfig_Type.MIGRATE:
+ return Release_File_ChangeType.DDL;
+ case Plan_ChangeDatabaseConfig_Type.MIGRATE_GHOST:
+ return Release_File_ChangeType.DDL_GHOST;
+ case Plan_ChangeDatabaseConfig_Type.DATA:
+ return Release_File_ChangeType.DML;
+ }
+ // Default to DDL if no type is specified.
+ return Release_File_ChangeType.DDL;
+};
diff --git a/frontend/src/components/IssueV1/components/SQLCheckSection/context.ts b/frontend/src/components/IssueV1/components/SQLCheckSection/context.ts
new file mode 100644
index 0000000000..46fcc325e6
--- /dev/null
+++ b/frontend/src/components/IssueV1/components/SQLCheckSection/context.ts
@@ -0,0 +1,46 @@
+import type { ComputedRef, InjectionKey, Ref } from "vue";
+import { computed, inject, provide, ref } from "vue";
+import { Issue_Type } from "@/types/proto/v1/issue_service";
+import type { CheckReleaseResponse_CheckResult } from "@/types/proto/v1/release_service";
+import { useIssueContext } from "../../logic";
+
+export type SQLCheckContext = {
+ enabled: ComputedRef<boolean>;
+ resultMap: Ref<Record<string, CheckReleaseResponse_CheckResult>>;
+
+ upsertResult: (key: string, result: CheckReleaseResponse_CheckResult) => void;
+};
+
+export const KEY = Symbol(
+ "bb.issue.context.sql-checks"
+) as InjectionKey<SQLCheckContext>;
+
+export const useIssueSQLCheckContext = () => {
+ return inject(KEY)!;
+};
+
+export const provideIssueSQLCheckContext = () => {
+ const { isCreating, issue } = useIssueContext();
+ const resultMap = ref<Record<string, CheckReleaseResponse_CheckResult>>({});
+
+ const enabled = computed(() => {
+ return (
+ isCreating.value &&
+ [Issue_Type.DATABASE_CHANGE, Issue_Type.DATABASE_DATA_EXPORT].includes(
+ issue.value.type
+ )
+ );
+ });
+
+ const context: SQLCheckContext = {
+ enabled,
+ resultMap,
+ upsertResult: (key, result) => {
+ resultMap.value[key] = result;
+ },
+ };
+
+ provide(KEY, context);
+
+ return context;
+};
diff --git a/frontend/src/components/IssueV1/components/StageSection/StageCard.vue b/frontend/src/components/IssueV1/components/StageSection/StageCard.vue
index 696500ffc7..4bf3526a74 100644
--- a/frontend/src/components/IssueV1/components/StageSection/StageCard.vue
+++ b/frontend/src/components/IssueV1/components/StageSection/StageCard.vue
@@ -1,9 +1,8 @@
<template>
<div class="stage" :class="stageClass">
<TaskStatusIcon
- :active="isActiveStage"
+ :task="activeTaskInStage"
:status="activeTaskInStage.status"
- :ignore-plan-check-status="true"
/>
<div class="text" @click="handleClickStage">
diff --git a/frontend/src/components/IssueV1/components/StatementSection/StatementSection.vue b/frontend/src/components/IssueV1/components/StatementSection/StatementSection.vue
index ed0beb2530..1c4f7915d2 100644
--- a/frontend/src/components/IssueV1/components/StatementSection/StatementSection.vue
+++ b/frontend/src/components/IssueV1/components/StatementSection/StatementSection.vue
@@ -17,21 +17,23 @@ import { onBeforeRouteLeave } from "vue-router";
import { useRouter } from "vue-router";
import { TaskTypeListWithStatement } from "@/types";
import { Task_Type } from "@/types/proto/v1/rollout_service";
-import type { Advice } from "@/types/proto/v1/sql_service";
import { isValidTaskName } from "@/utils";
-import { useIssueContext } from "../../logic";
+import { databaseForTask, useIssueContext } from "../../logic";
+import { useIssueSQLCheckContext } from "../SQLCheckSection/context";
import EditorView from "./EditorView";
import SDLView from "./SDLView";
-defineProps<{
- advices?: Advice[];
-}>();
-
-const { isCreating, selectedTask } = useIssueContext();
+const { t } = useI18n();
+const router = useRouter();
+const { issue, isCreating, selectedTask } = useIssueContext();
+const { resultMap } = useIssueSQLCheckContext();
const editorViewRef = ref<InstanceType<typeof EditorView>>();
-const router = useRouter();
-const { t } = useI18n();
+
+const advices = computed(() => {
+ const database = databaseForTask(issue.value, selectedTask.value);
+ return resultMap.value[database.name]?.advices || [];
+});
type ViewMode = "NONE" | "EDITOR" | "SDL";
diff --git a/frontend/src/components/IssueV1/components/TaskStatusIcon.vue b/frontend/src/components/IssueV1/components/TaskStatusIcon.vue
index d4e4dff094..4edc679510 100644
--- a/frontend/src/components/IssueV1/components/TaskStatusIcon.vue
+++ b/frontend/src/components/IssueV1/components/TaskStatusIcon.vue
@@ -3,12 +3,10 @@
class="relative flex flex-shrink-0 items-center justify-center select-none w-6 h-6 overflow-hidden"
:class="classes"
>
- <template v-if="planCheckStatus === PlanCheckRun_Result_Status.ERROR">
+ <template v-if="checkStatus === PlanCheckRun_Result_Status.ERROR">
<CircleAlertIcon class="text-error" />
</template>
- <template
- v-else-if="planCheckStatus === PlanCheckRun_Result_Status.WARNING"
- >
+ <template v-else-if="checkStatus === PlanCheckRun_Result_Status.WARNING">
<TriangleAlertIcon class="text-warning" />
</template>
<template
@@ -63,26 +61,51 @@ import { SkipIcon } from "@/components/Icon";
import { PlanCheckRun_Result_Status } from "@/types/proto/v1/plan_service";
import type { Task } from "@/types/proto/v1/rollout_service";
import { Task_Status } from "@/types/proto/v1/rollout_service";
-import { planCheckStatusForTask, useIssueContext } from "../logic";
+import { Advice_Status } from "@/types/proto/v1/sql_service";
+import {
+ databaseForTask,
+ planCheckStatusForTask,
+ useIssueContext,
+} from "../logic";
+import { useIssueSQLCheckContext } from "./SQLCheckSection/context";
const props = defineProps<{
status: Task_Status;
task?: Task;
- ignorePlanCheckStatus?: boolean;
+ ignoreCheckStatus?: boolean;
}>();
-const { isCreating } = useIssueContext();
+const { issue, isCreating } = useIssueContext();
+const { resultMap } = useIssueSQLCheckContext();
-const planCheckStatus = computed(() => {
- if (props.ignorePlanCheckStatus) return undefined;
- if (isCreating.value) return undefined;
+const checkStatus = computed(() => {
+ if (props.ignoreCheckStatus) return undefined;
if (!props.task) return undefined;
+ if (isCreating.value) {
+ const checkResult =
+ resultMap.value[databaseForTask(issue.value, props.task).name];
+ if (!checkResult) return undefined;
+ if (
+ checkResult.advices.some(
+ (advice) => advice.status === Advice_Status.ERROR
+ )
+ ) {
+ return PlanCheckRun_Result_Status.ERROR;
+ } else if (
+ checkResult.advices.some(
+ (advice) => advice.status === Advice_Status.WARNING
+ )
+ ) {
+ return PlanCheckRun_Result_Status.WARNING;
+ }
+ return undefined;
+ }
return planCheckStatusForTask(props.task);
});
const classes = computed((): string => {
- if (Boolean(planCheckStatus.value)) {
+ if (Boolean(checkStatus.value)) {
return "";
}
diff --git a/frontend/src/components/SQLCheck/SQLCheckButton.vue b/frontend/src/components/SQLCheck/SQLCheckButton.vue
index 45af274745..f1867b4ef1 100644
--- a/frontend/src/components/SQLCheck/SQLCheckButton.vue
+++ b/frontend/src/components/SQLCheck/SQLCheckButton.vue
@@ -88,6 +88,7 @@ import { providePlanCheckRunContext } from "../PlanCheckRun/context";
import ErrorList from "../misc/ErrorList.vue";
import SQLCheckPanel from "./SQLCheckPanel.vue";
import SQLCheckSummary from "./SQLCheckSummary.vue";
+import { STATEMENT_SKIP_CHECK_THRESHOLD } from "./common";
import { useSQLCheckContext } from "./context";
const props = withDefaults(
@@ -121,8 +122,6 @@ const emit = defineEmits<{
}>();
const { t } = useI18n();
-// SKIP_CHECK_THRESHOLD is the MaxSheetCheckSize in the backend.
-const SKIP_CHECK_THRESHOLD = 2 * 1024 * 1024;
const isRunning = ref(false);
const showDetailPanel = ref(false);
const allowForceContinue = ref(true);
@@ -147,7 +146,7 @@ const statementErrors = asyncComputed(async () => {
if (statement.length === 0) {
return [t("issue.sql-check.statement-is-required")];
}
- if (new Blob([statement]).size > SKIP_CHECK_THRESHOLD) {
+ if (new Blob([statement]).size > STATEMENT_SKIP_CHECK_THRESHOLD) {
return [t("issue.sql-check.statement-is-too-large")];
}
return [];
@@ -213,7 +212,7 @@ const runChecks = async () => {
isRunning.value = true;
const { statement, errors } = await props.getStatement();
allowForceContinue.value = errors.length === 0;
- if (new Blob([statement]).size > SKIP_CHECK_THRESHOLD) {
+ if (new Blob([statement]).size > STATEMENT_SKIP_CHECK_THRESHOLD) {
return handleErrors([t("issue.sql-check.statement-is-too-large")]);
}
if (errors.length > 0) {
diff --git a/frontend/src/components/SQLCheck/common.ts b/frontend/src/components/SQLCheck/common.ts
new file mode 100644
index 0000000000..452e7f9ea3
--- /dev/null
+++ b/frontend/src/components/SQLCheck/common.ts
@@ -0,0 +1,3 @@
+// STATEMENT_SKIP_CHECK_THRESHOLD is the MaxSheetCheckSize in the backend.
+// Default to 2MB.
+export const STATEMENT_SKIP_CHECK_THRESHOLD = 2 * 1024 * 1024;