Skip to content

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

refactor: unify sql check section in plan&issue (#16183)

boojackdec25b3601fd
diff --git a/frontend/i18n.ts b/frontend/i18n.ts
index 89192b814e..4ced486d81 100644
--- a/frontend/i18n.ts
+++ b/frontend/i18n.ts
@@ -1,3 +1,4 @@
+/* eslint-disable no-console */
import { config } from "dotenv";
import { promises as fs } from "fs";
diff --git a/frontend/src/components/IssueV1/DataExportIssueDetailPage.vue b/frontend/src/components/IssueV1/DataExportIssueDetailPage.vue
index 35593cc7d2..630934ec38 100644
--- a/frontend/src/components/IssueV1/DataExportIssueDetailPage.vue
+++ b/frontend/src/components/IssueV1/DataExportIssueDetailPage.vue
@@ -62,9 +62,12 @@
</template>
<script setup lang="ts">
-import { ref } from "vue";
+import { computed, ref } from "vue";
import { FeatureAttention } from "@/components/FeatureGuard";
+import type { Plan, Plan_Spec } from "@/types/proto/v1/plan_service";
import type { Task } from "@/types/proto/v1/rollout_service";
+import { SQLCheckSection } from "../Plan/components";
+import { providePlanSQLCheckContext } from "../Plan/components/SQLCheckSection/context";
import { provideSidebarContext } from "../Plan/logic";
import { Drawer } from "../v2";
import {
@@ -78,20 +81,18 @@ import {
IssueReviewActionPanel,
IssueStatusActionPanel,
TaskRolloutActionPanel,
- SQLCheckSection,
DataExportSection,
TaskRunSection,
} from "./components";
-import { provideIssueSQLCheckContext } from "./components/SQLCheckSection/context";
import type {
IssueReviewAction,
IssueStatusAction,
TaskRolloutAction,
} from "./logic";
-import { useIssueContext, usePollIssue } from "./logic";
+import { specForTask, useIssueContext, usePollIssue } from "./logic";
const containerRef = ref<HTMLElement>();
-const { isCreating, events } = useIssueContext();
+const { isCreating, issue, selectedTask, events } = useIssueContext();
const ongoingIssueReviewAction = ref<{
action: IssueReviewAction;
@@ -125,7 +126,14 @@ events.on("perform-task-rollout-action", async ({ action, tasks }) => {
};
});
-provideIssueSQLCheckContext();
+providePlanSQLCheckContext({
+ project: computed(() => issue.value.projectEntity),
+ plan: computed(() => issue.value.planEntity as Plan),
+ selectedSpec: computed(
+ () => specForTask(issue.value.planEntity, selectedTask.value) as Plan_Spec
+ ),
+ selectedTask: selectedTask,
+});
const {
mode: sidebarMode,
diff --git a/frontend/src/components/IssueV1/IssueDetailPage.vue b/frontend/src/components/IssueV1/IssueDetailPage.vue
index a1d5282c83..95335b74ab 100644
--- a/frontend/src/components/IssueV1/IssueDetailPage.vue
+++ b/frontend/src/components/IssueV1/IssueDetailPage.vue
@@ -70,9 +70,12 @@
</template>
<script setup lang="ts">
-import { ref } from "vue";
+import { computed, ref } from "vue";
import { FeatureAttention } from "@/components/FeatureGuard";
+import type { Plan, Plan_Spec } from "@/types/proto/v1/plan_service";
import { type Task } from "@/types/proto/v1/rollout_service";
+import { SQLCheckSection } from "../Plan/components";
+import { providePlanSQLCheckContext } from "../Plan/components/SQLCheckSection/context";
import { provideSidebarContext } from "../Plan/logic";
import { Drawer } from "../v2";
import {
@@ -88,19 +91,17 @@ import {
IssueReviewActionPanel,
IssueStatusActionPanel,
TaskRolloutActionPanel,
- SQLCheckSection,
IssueCommentSection,
} from "./components";
-import { provideIssueSQLCheckContext } from "./components/SQLCheckSection/context";
import type {
IssueReviewAction,
IssueStatusAction,
TaskRolloutAction,
} from "./logic";
-import { useIssueContext, usePollIssue } from "./logic";
+import { specForTask, useIssueContext, usePollIssue } from "./logic";
const containerRef = ref<HTMLElement>();
-const { isCreating, events } = useIssueContext();
+const { isCreating, issue, selectedTask, events } = useIssueContext();
const ongoingIssueReviewAction = ref<{
action: IssueReviewAction;
@@ -134,7 +135,14 @@ events.on("perform-task-rollout-action", async ({ action, tasks }) => {
};
});
-provideIssueSQLCheckContext();
+providePlanSQLCheckContext({
+ project: computed(() => issue.value.projectEntity),
+ plan: computed(() => issue.value.planEntity as Plan),
+ selectedSpec: computed(
+ () => specForTask(issue.value.planEntity, selectedTask.value) as Plan_Spec
+ ),
+ selectedTask: selectedTask,
+});
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 65227cb154..ad16c608ee 100644
--- a/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vue
+++ b/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vue
@@ -60,12 +60,14 @@ import { getValidIssueLabels } from "@/components/IssueV1/components/IssueLabelS
import { ErrorList } from "@/components/IssueV1/components/common";
import {
databaseEngineForSpec,
- getLocalSheetByName,
isValidStage,
+ specForTask,
useIssueContext,
} from "@/components/IssueV1/logic";
import formatSQL from "@/components/MonacoEditor/sqlFormatter";
-import { isValidSpec } from "@/components/Plan";
+import { getLocalSheetByName, isValidSpec } from "@/components/Plan";
+import { getSpecChangeType } from "@/components/Plan/components/SQLCheckSection/common";
+import { usePlanSQLCheckContext } from "@/components/Plan/components/SQLCheckSection/context";
import { databaseForTask } from "@/components/Rollout/RolloutDetail";
import { SQLCheckPanel } from "@/components/SQLCheck";
import { STATEMENT_SKIP_CHECK_THRESHOLD } from "@/components/SQLCheck/common";
@@ -79,7 +81,7 @@ import { emitWindowEvent } from "@/plugins";
import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";
import { useDatabaseV1Store, useSheetV1Store } from "@/store";
import { dialectOfEngineV1, languageOfEngineV1 } from "@/types";
-import { Issue } from "@/types/proto/v1/issue_service";
+import { Issue, Issue_Type } 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";
@@ -98,19 +100,15 @@ import {
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, events, selectedTask } = useIssueContext();
-const {
- enabled: shouldRunSQLCheck,
- resultMap: checkResultMap,
- upsertResult: upsertCheckResult,
-} = useIssueSQLCheckContext();
+const { isCreating, issue, formatOnSave, events, selectedTask } =
+ useIssueContext();
+const { resultMap: checkResultMap, upsertResult: upsertCheckResult } =
+ usePlanSQLCheckContext();
const sheetStore = useSheetV1Store();
const loading = ref(false);
const showSQLCheckResultPanel = ref(false);
@@ -299,8 +297,13 @@ const emitIssueCreateWindowEvent = (issue: Issue) => {
};
const runSQLCheckForIssue = async () => {
- if (!shouldRunSQLCheck.value) {
- return true;
+ if (
+ !isCreating.value ||
+ ![Issue_Type.DATABASE_CHANGE, Issue_Type.DATABASE_DATA_EXPORT].includes(
+ issue.value.type
+ )
+ ) {
+ return;
}
const flattenTasks = flattenTaskV1List(issue.value.rolloutEntity);
@@ -339,7 +342,9 @@ const runSQLCheckForIssue = async () => {
version: "0",
type: ReleaseFileType.VERSIONED,
statement: new TextEncoder().encode(statement),
- changeType: getTaskChangeType(issue.value, flattenTasks[0]),
+ changeType: getSpecChangeType(
+ specForTask(issue.value.planEntity, selectedTask.value)
+ ),
},
],
},
diff --git a/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckBadge.vue b/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckBadge.vue
deleted file mode 100644
index 7404b59410..0000000000
--- a/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckBadge.vue
+++ /dev/null
@@ -1,97 +0,0 @@
-<template>
- <NTag
- :class="[clickable && 'cursor-pointer']"
- :type="tagType"
- round
- @click="handleClick"
- >
- <template #icon>
- <template v-if="status === 'RUNNING'">
- <TaskSpinner class="h-4 w-4 text-info" />
- </template>
- <template v-else-if="status === 'SUCCESS'">
- <CheckIcon :size="16" class="text-success" />
- </template>
- <template v-else-if="status === 'WARNING'">
- <TriangleAlertIcon :size="16" />
- </template>
- <template v-else-if="status === 'ERROR'">
- <CircleAlertIcon :size="16" />
- </template>
- </template>
- <span>{{ $t("task.check-type.sql-review") }}</span>
- </NTag>
-
- <SQLCheckPanel
- v-if="showDetailPanel"
- :project="issue.project"
- :database="database"
- :advices="advices"
- @close="showDetailPanel = false"
- />
-</template>
-
-<script setup lang="ts">
-import { CheckIcon, TriangleAlertIcon, CircleAlertIcon } from "lucide-vue-next";
-import { NTag } from "naive-ui";
-import { computed, ref } from "vue";
-import { databaseForTask } from "@/components/Rollout/RolloutDetail";
-import { SQLCheckPanel } from "@/components/SQLCheck";
-import type { Advice } from "@/types/proto/v1/sql_service";
-import { Advice_Status } from "@/types/proto/v1/sql_service";
-import { useIssueContext } from "../../logic";
-import { TaskSpinner } from "../common";
-
-const props = defineProps<{
- advices: Advice[];
- isRunning?: boolean;
-}>();
-
-defineEmits<{
- (event: "click"): void;
-}>();
-
-const { issue, selectedTask } = useIssueContext();
-const showDetailPanel = ref(false);
-
-const database = computed(() => {
- return databaseForTask(issue.value.projectEntity, selectedTask.value);
-});
-
-const status = computed(() => {
- const { isRunning, advices } = props;
- if (isRunning) {
- return "RUNNING";
- }
- if (advices.some((adv) => adv.status === Advice_Status.ERROR)) {
- return "ERROR";
- }
- if (advices.some((adv) => adv.status === Advice_Status.WARNING)) {
- return "WARNING";
- }
- return "SUCCESS";
-});
-
-const clickable = computed(() => {
- return status.value === "ERROR" || status.value === "WARNING";
-});
-
-const tagType = computed(() => {
- switch (status.value) {
- case "SUCCESS":
- return "default";
- case "RUNNING":
- return "info";
- case "WARNING":
- return "warning";
- case "ERROR":
- return "error";
- }
- // Should not reach here.
- return "default";
-});
-
-const handleClick = () => {
- showDetailPanel.value = true;
-};
-</script>
diff --git a/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckButton.vue b/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckButton.vue
deleted file mode 100644
index 211623e550..0000000000
--- a/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckButton.vue
+++ /dev/null
@@ -1,201 +0,0 @@
-<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"
- :project="issue.project"
- :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 { computed, ref, watch } from "vue";
-import { useI18n } from "vue-i18n";
-import { BBSpin } from "@/bbkit";
-import { databaseForTask } from "@/components/Rollout/RolloutDetail";
-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 { 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.projectEntity, 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 "0" for dummy version.
- version: "0",
- type: ReleaseFileType.VERSIONED,
- statement: new TextEncoder().encode(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
deleted file mode 100644
index 5c99a2b341..0000000000
--- a/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckSection.vue
+++ /dev/null
@@ -1,93 +0,0 @@
-<template>
- <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>
- <div
- v-if="database"
- class="grow flex flex-row items-center justify-between gap-2"
- >
- <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 class="font-medium">{{ checkResult.affectedRows }}</span>
- </NTag>
- </template>
- {{ $t("task.check-type.affected-rows.description") }}
- </NTooltip>
- <NTag round v-if="shouldShowRiskLevelWarning">
- <span class="opacity-80">{{ $t("issue.risk-level.self") }}: </span>
- <span class="font-medium">{{
- $t(`issue.risk-level.${checkResult.riskLevel.toLowerCase()}`)
- }}</span>
- </NTag>
- </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 } from "@/components/IssueV1/logic";
-import { databaseForTask } from "@/components/Rollout/RolloutDetail";
-import { TaskTypeListWithStatement } from "@/types";
-import { CheckReleaseResponse_RiskLevel } from "@/types/proto/v1/release_service";
-import { Task_Type } from "@/types/proto/v1/rollout_service";
-import SQLCheckBadge from "./SQLCheckBadge.vue";
-import SQLCheckButton from "./SQLCheckButton.vue";
-import { useIssueSQLCheckContext } from "./context";
-
-const { issue, selectedTask } = useIssueContext();
-
-const { enabled, resultMap } = useIssueSQLCheckContext();
-
-const database = computed(() => {
- return databaseForTask(issue.value.projectEntity, selectedTask.value);
-});
-
-const show = computed(() => {
- if (!enabled.value) {
- return false;
- }
- const type = selectedTask.value.type;
- if (type === Task_Type.DATABASE_SCHEMA_BASELINE) {
- return false;
- }
- if (TaskTypeListWithStatement.includes(type)) {
- return true;
- }
- return false;
-});
-
-const checkResult = computed(() => {
- const database = databaseForTask(
- issue.value.projectEntity,
- selectedTask.value
- );
- return resultMap.value[database.name] || undefined;
-});
-
-const shouldShowRiskLevelWarning = computed(() => {
- return [
- CheckReleaseResponse_RiskLevel.LOW,
- CheckReleaseResponse_RiskLevel.MODERATE,
- CheckReleaseResponse_RiskLevel.HIGH,
- ].includes(checkResult.value.riskLevel);
-});
-</script>
diff --git a/frontend/src/components/IssueV1/components/SQLCheckSection/common.ts b/frontend/src/components/IssueV1/components/SQLCheckSection/common.ts
deleted file mode 100644
index 414441f8fd..0000000000
--- a/frontend/src/components/IssueV1/components/SQLCheckSection/common.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-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 DML if no type is specified.
- return Release_File_ChangeType.DML;
-};
diff --git a/frontend/src/components/IssueV1/components/SQLCheckSection/context.ts b/frontend/src/components/IssueV1/components/SQLCheckSection/context.ts
deleted file mode 100644
index e38e0a9c06..0000000000
--- a/frontend/src/components/IssueV1/components/SQLCheckSection/context.ts
+++ /dev/null
@@ -1,47 +0,0 @@
-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>;
- // Key is the database name.
- 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/StatementSection/EditorView/EditorView.vue b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
index c4c6624fd6..47c7d3f90f 100644
--- a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
+++ b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
@@ -206,13 +206,13 @@ import {
stageForTask,
isTaskEditable,
specForTask,
- createEmptyLocalSheet,
notifyNotEditableLegacyIssue,
isGroupingChangeTaskV1,
databaseEngineForSpec,
} from "@/components/IssueV1/logic";
import { MonacoEditor } from "@/components/MonacoEditor";
import { extensionNameOfLanguage } from "@/components/MonacoEditor/utils";
+import { createEmptyLocalSheet } from "@/components/Plan";
import { databaseForTask } from "@/components/Rollout/RolloutDetail";
import DownloadSheetButton from "@/components/Sheet/DownloadSheetButton.vue";
import SQLUploadButton from "@/components/misc/SQLUploadButton.vue";
diff --git a/frontend/src/components/IssueV1/components/StatementSection/StatementSection.vue b/frontend/src/components/IssueV1/components/StatementSection/StatementSection.vue
index 5415ae15c2..8c3c2286ea 100644
--- a/frontend/src/components/IssueV1/components/StatementSection/StatementSection.vue
+++ b/frontend/src/components/IssueV1/components/StatementSection/StatementSection.vue
@@ -15,19 +15,19 @@ import { computed, nextTick, ref } from "vue";
import { useI18n } from "vue-i18n";
import { onBeforeRouteLeave } from "vue-router";
import { useRouter } from "vue-router";
+import { usePlanSQLCheckContext } from "@/components/Plan/components/SQLCheckSection/context";
import { databaseForTask } from "@/components/Rollout/RolloutDetail";
import { TaskTypeListWithStatement } from "@/types";
import { Task_Type } from "@/types/proto/v1/rollout_service";
import { isValidTaskName } from "@/utils";
import { useIssueContext } from "../../logic";
-import { useIssueSQLCheckContext } from "../SQLCheckSection/context";
import EditorView from "./EditorView";
import SDLView from "./SDLView";
const { t } = useI18n();
const router = useRouter();
const { issue, isCreating, selectedTask } = useIssueContext();
-const { resultMap } = useIssueSQLCheckContext();
+const { resultMap } = usePlanSQLCheckContext();
const editorViewRef = ref<InstanceType<typeof EditorView>>();
diff --git a/frontend/src/components/IssueV1/components/StatementSection/useTaskSheet.ts b/frontend/src/components/IssueV1/components/StatementSection/useTaskSheet.ts
index 8844f216ed..a521622ec4 100644
--- a/frontend/src/components/IssueV1/components/StatementSection/useTaskSheet.ts
+++ b/frontend/src/components/IssueV1/components/StatementSection/useTaskSheet.ts
@@ -1,5 +1,6 @@
import { computedAsync } from "@vueuse/core";
import { computed, ref } from "vue";
+import { getLocalSheetByName } from "@/components/Plan";
import { useSheetV1Store } from "@/store";
import { ESTABLISH_BASELINE_SQL } from "@/types";
import { Task_Type } from "@/types/proto/v1/rollout_service";
@@ -9,7 +10,7 @@ import {
setSheetStatement,
sheetNameOfTaskV1,
} from "@/utils";
-import { getLocalSheetByName, useIssueContext } from "../../logic";
+import { useIssueContext } from "../../logic";
export const useTaskSheet = () => {
const sheetStore = useSheetV1Store();
diff --git a/frontend/src/components/IssueV1/components/TaskListSection/TaskFilter.vue b/frontend/src/components/IssueV1/components/TaskListSection/TaskFilter.vue
index 74132fc51d..97997ac9d5 100644
--- a/frontend/src/components/IssueV1/components/TaskListSection/TaskFilter.vue
+++ b/frontend/src/components/IssueV1/components/TaskListSection/TaskFilter.vue
@@ -81,11 +81,11 @@
<script lang="ts" setup>
import { NTag } from "naive-ui";
import { computed } from "vue";
+import AdviceStatusIcon from "@/components/Plan/components/SQLCheckSection/AdviceStatusIcon.vue";
+import { usePlanSQLCheckContext } from "@/components/Plan/components/SQLCheckSection/context";
import { Task_Status } from "@/types/proto/v1/rollout_service";
import { Advice_Status } from "@/types/proto/v1/sql_service";
import { useIssueContext } from "../../logic";
-import AdviceStatusIcon from "../SQLCheckSection/AdviceStatusIcon.vue";
-import { useIssueSQLCheckContext } from "../SQLCheckSection/context";
import TaskStatusIconV1 from "../TaskStatusIconV1.vue";
import { filterTask } from "./filter";
@@ -117,7 +117,7 @@ const ADVICE_STATUS_FILTERS: Advice_Status[] = [
];
const issueContext = useIssueContext();
-const sqlCheckContext = useIssueSQLCheckContext();
+const { resultMap } = usePlanSQLCheckContext();
const { isCreating, selectedStage } = issueContext;
@@ -125,7 +125,7 @@ const taskList = computed(() => selectedStage.value.tasks);
const getTaskCount = (status?: Task_Status, adviceStatus?: Advice_Status) => {
return taskList.value.filter((task) =>
- filterTask(issueContext, sqlCheckContext, task, { status, adviceStatus })
+ filterTask(issueContext, resultMap.value, task, { status, adviceStatus })
).length;
};
</script>
diff --git a/frontend/src/components/IssueV1/components/TaskListSection/TaskListSection.vue b/frontend/src/components/IssueV1/components/TaskListSection/TaskListSection.vue
index 5ef4aa54b6..d1263fd016 100644
--- a/frontend/src/components/IssueV1/components/TaskListSection/TaskListSection.vue
+++ b/frontend/src/components/IssueV1/components/TaskListSection/TaskListSection.vue
@@ -64,6 +64,7 @@ import { useDebounceFn } from "@vueuse/core";
import { NButton } from "naive-ui";
import { computed, ref, reactive, watch } from "vue";
import { BBSpin } from "@/bbkit";
+import { usePlanSQLCheckContext } from "@/components/Plan/components/SQLCheckSection/context";
import { databaseForTask } from "@/components/Rollout/RolloutDetail";
import { useVerticalScrollState } from "@/composables/useScrollState";
import { batchGetOrFetchDatabases } from "@/store";
@@ -72,7 +73,6 @@ import type { Task_Status } from "@/types/proto/v1/rollout_service";
import type { Advice_Status } from "@/types/proto/v1/sql_service";
import { isDev } from "@/utils";
import { useIssueContext } from "../../logic";
-import { useIssueSQLCheckContext } from "../SQLCheckSection/context";
import CurrentTaskSection from "./CurrentTaskSection.vue";
import TaskCard from "./TaskCard.vue";
import TaskFilter from "./TaskFilter.vue";
@@ -103,7 +103,7 @@ const state = reactive<LocalState>({
const issueContext = useIssueContext();
const { selectedStage, issue, selectedTask } = issueContext;
-const sqlCheckContext = useIssueSQLCheckContext();
+const { resultMap } = usePlanSQLCheckContext();
const taskBar = ref<HTMLDivElement>();
const taskBarScrollState = useVerticalScrollState(taskBar, MAX_LIST_HEIGHT);
@@ -139,7 +139,7 @@ const filteredTaskList = computed(() => {
if (stageState.value.adviceStatusFilters.length > 0) {
if (
!stageState.value.adviceStatusFilters.some((status) =>
- filterTask(issueContext, sqlCheckContext, task, {
+ filterTask(issueContext, resultMap.value, task, {
adviceStatus: status,
})
)
diff --git a/frontend/src/components/IssueV1/components/TaskListSection/filter.ts b/frontend/src/components/IssueV1/components/TaskListSection/filter.ts
index 2f7bfd94c7..9c1457741a 100644
--- a/frontend/src/components/IssueV1/components/TaskListSection/filter.ts
+++ b/frontend/src/components/IssueV1/components/TaskListSection/filter.ts
@@ -1,12 +1,12 @@
import { planCheckRunSummaryForCheckRunList } from "@/components/PlanCheckRun/common";
+import type { CheckReleaseResponse_CheckResult } from "@/types/proto/v1/release_service";
import type { Task, Task_Status } from "@/types/proto/v1/rollout_service";
import { Advice_Status } from "@/types/proto/v1/sql_service";
import { type IssueContext } from "../../logic";
-import { type SQLCheckContext } from "../SQLCheckSection/context";
export const filterTask = (
issueContext: IssueContext,
- sqlCheckContext: SQLCheckContext,
+ sqlCheckResultMap: Record<string, CheckReleaseResponse_CheckResult>,
task: Task,
{
status,
@@ -22,20 +22,17 @@ export const filterTask = (
}
if (adviceStatus) {
if (isCreating.value) {
- const { enabled, resultMap } = sqlCheckContext;
- if (enabled.value) {
- const result = resultMap.value[task.target];
- if (adviceStatus === Advice_Status.UNRECOGNIZED) {
- return !Boolean(result);
- }
- if (adviceStatus === Advice_Status.SUCCESS) {
- return result && result.advices.length === 0;
- }
- return (
- result &&
- result.advices.some((advice) => advice.status === adviceStatus)
- );
+ const result = sqlCheckResultMap[task.target];
+ if (adviceStatus === Advice_Status.UNRECOGNIZED) {
+ return !Boolean(result);
}
+ if (adviceStatus === Advice_Status.SUCCESS) {
+ return result && result.advices.length === 0;
+ }
+ return (
+ result &&
+ result.advices.some((advice) => advice.status === adviceStatus)
+ );
} else {
const summary = planCheckRunSummaryForCheckRunList(
getPlanCheckRunsForTask(task)
diff --git a/frontend/src/components/IssueV1/components/TaskStatusIcon.vue b/frontend/src/components/IssueV1/components/TaskStatusIcon.vue
index d725086dd4..8d78481ed4 100644
--- a/frontend/src/components/IssueV1/components/TaskStatusIcon.vue
+++ b/frontend/src/components/IssueV1/components/TaskStatusIcon.vue
@@ -58,13 +58,13 @@
import { CircleAlertIcon, TriangleAlertIcon } from "lucide-vue-next";
import { computed } from "vue";
import { SkipIcon } from "@/components/Icon";
+import { usePlanSQLCheckContext } from "@/components/Plan/components/SQLCheckSection/context";
import { databaseForTask } from "@/components/Rollout/RolloutDetail";
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 { Advice_Status } from "@/types/proto/v1/sql_service";
import { planCheckStatusForTask, useIssueContext } from "../logic";
-import { useIssueSQLCheckContext } from "./SQLCheckSection/context";
const props = defineProps<{
status: Task_Status;
@@ -73,7 +73,7 @@ const props = defineProps<{
}>();
const { issue, isCreating } = useIssueContext();
-const { resultMap } = useIssueSQLCheckContext();
+const { resultMap } = usePlanSQLCheckContext();
const checkStatus = computed(() => {
if (props.ignoreCheckStatus) return undefined;
diff --git a/frontend/src/components/IssueV1/components/index.ts b/frontend/src/components/IssueV1/components/index.ts
index ad79525dc0..229cfe7f4d 100644
--- a/frontend/src/components/IssueV1/components/index.ts
+++ b/frontend/src/components/IssueV1/components/index.ts
@@ -5,7 +5,6 @@ import HeaderSection from "./HeaderSection";
import IssueCommentSection from "./IssueCommentSection";
import IssueSearch from "./IssueSearch";
import PlanCheckSection from "./PlanCheckSection";
-import SQLCheckSection from "./SQLCheckSection";
import Sidebar from "./Sidebar";
import StageSection from "./StageSection";
import StatementSection from "./StatementSection";
@@ -25,7 +24,6 @@ export {
DescriptionSection,
IssueSearch,
Sidebar,
- SQLCheckSection,
DataExportSection,
IssueCommentSection,
};
diff --git a/frontend/src/components/IssueV1/logic/index.ts b/frontend/src/components/IssueV1/logic/index.ts
index b539171d55..418aec00fe 100644
--- a/frontend/src/components/IssueV1/logic/index.ts
+++ b/frontend/src/components/IssueV1/logic/index.ts
@@ -7,7 +7,6 @@ export * from "./rollout";
export * from "./utils";
export * from "./initialize";
export * from "./action";
-export * from "./sheet";
export * from "./plan-check";
export * from "./task-run";
export * from "./poll";
diff --git a/frontend/src/components/IssueV1/logic/initialize/create.ts b/frontend/src/components/IssueV1/logic/initialize/create.ts
index 47c1b2986e..031ec134cf 100644
--- a/frontend/src/components/IssueV1/logic/initialize/create.ts
+++ b/frontend/src/components/IssueV1/logic/initialize/create.ts
@@ -2,7 +2,10 @@ import { cloneDeep, groupBy, orderBy } from "lodash-es";
import { v4 as uuidv4 } from "uuid";
import { reactive } from "vue";
import { useRoute } from "vue-router";
-import { extractInitialSQLFromQuery } from "@/components/Plan";
+import {
+ extractInitialSQLFromQuery,
+ getLocalSheetByName,
+} from "@/components/Plan";
import { getArchiveDatabase } from "@/components/Plan/components/Sidebar/PreBackupSection/utils";
import { rolloutServiceClient } from "@/grpcweb";
import {
@@ -46,7 +49,6 @@ import {
} from "@/utils";
import { nextUID } from "../base";
import { databaseEngineForSpec, sheetNameForSpec } from "../plan";
-import { getLocalSheetByName } from "../sheet";
export type InitialSQL = {
sqlMap?: Record<string, string>;
diff --git a/frontend/src/components/IssueV1/logic/sheet.ts b/frontend/src/components/IssueV1/logic/sheet.ts
deleted file mode 100644
index ad6a875b7b..0000000000
--- a/frontend/src/components/IssueV1/logic/sheet.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import { reactive } from "vue";
-import { Sheet } from "@/types/proto/v1/sheet_service";
-
-const sheetsByName = reactive(new Map<string, Sheet>());
-
-export const createEmptyLocalSheet = () => {
- return reactive(Sheet.fromJSON({}));
-};
-
-export const getLocalSheetByName = (name: string) => {
- const existed = sheetsByName.get(name);
- if (existed) {
- return existed;
- }
- const sheet = reactive({
- ...createEmptyLocalSheet(),
- name,
- });
- sheetsByName.set(name, sheet);
- return sheet;
-};
diff --git a/frontend/src/components/Plan/PlanDetailPage.vue b/frontend/src/components/Plan/PlanDetailPage.vue
index 6812f01096..40530a9277 100644
--- a/frontend/src/components/Plan/PlanDetailPage.vue
+++ b/frontend/src/components/Plan/PlanDetailPage.vue
@@ -8,7 +8,7 @@
class="flex-1 flex flex-col hide-scrollbar divide-y overflow-x-hidden"
>
<SpecListSection />
- <SQLCheckSectionV1 v-if="isCreating" />
+ <SQLCheckSection v-if="isCreating" />
<PlanCheckSection v-else />
<StatementSection />
<DescriptionSection />
@@ -43,27 +43,31 @@
</template>
<script setup lang="ts">
-import { ref } from "vue";
+import { computed, ref } from "vue";
import { Drawer } from "@/components/v2";
import {
HeaderSection,
PlanCheckSection,
StatementSection,
DescriptionSection,
- SQLCheckSectionV1,
+ SQLCheckSection,
SpecListSection,
} from "./components";
-import { providePlanSQLCheckContext } from "./components/SQLCheckSectionV1/context";
+import { providePlanSQLCheckContext } from "./components/SQLCheckSection/context";
import Sidebar from "./components/Sidebar";
import { usePlanContext, usePollPlan } from "./logic";
import { provideSidebarContext } from "./logic";
const containerRef = ref<HTMLElement>();
-const { isCreating } = usePlanContext();
+const { isCreating, plan, selectedSpec } = usePlanContext();
usePollPlan();
-providePlanSQLCheckContext();
+providePlanSQLCheckContext({
+ project: computed(() => plan.value.projectEntity),
+ plan: plan,
+ selectedSpec: selectedSpec,
+});
const {
mode: sidebarMode,
diff --git a/frontend/src/components/IssueV1/components/SQLCheckSection/AdviceStatusIcon.vue b/frontend/src/components/Plan/components/SQLCheckSection/AdviceStatusIcon.vue
similarity index 100%
rename from frontend/src/components/IssueV1/components/SQLCheckSection/AdviceStatusIcon.vue
rename to frontend/src/components/Plan/components/SQLCheckSection/AdviceStatusIcon.vue
diff --git a/frontend/src/components/Plan/components/SQLCheckSectionV1/SQLCheckBadge.vue b/frontend/src/components/Plan/components/SQLCheckSection/SQLCheckBadge.vue
similarity index 89%
rename from frontend/src/components/Plan/components/SQLCheckSectionV1/SQLCheckBadge.vue
rename to frontend/src/components/Plan/components/SQLCheckSection/SQLCheckBadge.vue
index a627c42ac8..67ef10d68c 100644
--- a/frontend/src/components/Plan/components/SQLCheckSectionV1/SQLCheckBadge.vue
+++ b/frontend/src/components/Plan/components/SQLCheckSection/SQLCheckBadge.vue
@@ -24,7 +24,7 @@
<SQLCheckPanel
v-if="showDetailPanel"
- :project="plan.project"
+ :project="project.name"
:database="database"
:advices="advices"
@close="showDetailPanel = false"
@@ -39,7 +39,7 @@ import { TaskSpinner } from "@/components/IssueV1/components/common";
import { SQLCheckPanel } from "@/components/SQLCheck";
import type { Advice } from "@/types/proto/v1/sql_service";
import { Advice_Status } from "@/types/proto/v1/sql_service";
-import { databaseForSpec, usePlanContext } from "../../logic";
+import { usePlanSQLCheckContext } from "./context";
const props = defineProps<{
advices: Advice[];
@@ -50,13 +50,9 @@ defineEmits<{
(event: "click"): void;
}>();
-const { plan, selectedSpec } = usePlanContext();
+const { database, project } = usePlanSQLCheckContext();
const showDetailPanel = ref(false);
-const database = computed(() => {
- return databaseForSpec(plan.value.projectEntity, selectedSpec.value);
-});
-
const status = computed(() => {
const { isRunning, advices } = props;
if (isRunning) {
diff --git a/frontend/src/components/Plan/components/SQLCheckSectionV1/SQLCheckButton.vue b/frontend/src/components/Plan/components/SQLCheckSection/SQLCheckButton.vue
similarity index 84%
rename from frontend/src/components/Plan/components/SQLCheckSectionV1/SQLCheckButton.vue
rename to frontend/src/components/Plan/components/SQLCheckSection/SQLCheckButton.vue
index 3c40a53f9b..71ed5b40fb 100644
--- a/frontend/src/components/Plan/components/SQLCheckSectionV1/SQLCheckButton.vue
+++ b/frontend/src/components/Plan/components/SQLCheckSection/SQLCheckButton.vue
@@ -30,7 +30,7 @@
<SQLCheckPanel
v-if="checkResult && advices && showDetailPanel"
- :project="plan.project"
+ :project="project.name"
:database="database"
:advices="advices"
:affected-rows="checkResult.affectedRows"
@@ -50,7 +50,7 @@
<script lang="ts" setup>
import { asyncComputed } from "@vueuse/core";
import { NButton, NPopover } from "naive-ui";
-import { computed, ref, watch } from "vue";
+import { computed, ref } from "vue";
import { useI18n } from "vue-i18n";
import { BBSpin } from "@/bbkit";
import { SQLCheckPanel } from "@/components/SQLCheck";
@@ -64,7 +64,6 @@ import {
import { Advice, Advice_Status } from "@/types/proto/v1/sql_service";
import type { Defer, VueStyle } from "@/utils";
import { defer } from "@/utils";
-import { databaseForSpec, usePlanContext } from "../../logic";
import { useSpecSheet } from "../StatementSection/useSpecSheet";
import { getSpecChangeType } from "./common";
import { usePlanSQLCheckContext } from "./context";
@@ -81,9 +80,9 @@ withDefaults(
);
const { t } = useI18n();
-const { plan, selectedSpec } = usePlanContext();
-const { upsertResult } = usePlanSQLCheckContext();
-const { sheetStatement } = useSpecSheet();
+const { database, project, selectedSpec, upsertResult } =
+ usePlanSQLCheckContext();
+const { sheetStatement } = useSpecSheet(selectedSpec.value);
const isRunning = ref(false);
const showDetailPanel = ref(false);
@@ -95,19 +94,13 @@ const advices = computed(() => {
return checkResult.value?.results.flatMap((r) => r.advices);
});
-const database = computed(() =>
- databaseForSpec(plan.value.projectEntity, selectedSpec.value)
-);
-
-const statement = computed(() => sheetStatement.value);
-
const changeType = computed(() => getSpecChangeType(selectedSpec.value));
const statementErrors = asyncComputed(async () => {
- if (statement.value.length === 0) {
+ if (sheetStatement.value.length === 0) {
return [t("issue.sql-check.statement-is-required")];
}
- if (new Blob([statement.value]).size > STATEMENT_SKIP_CHECK_THRESHOLD) {
+ if (new Blob([sheetStatement.value]).size > STATEMENT_SKIP_CHECK_THRESHOLD) {
return [t("issue.sql-check.statement-is-too-large")];
}
return [];
@@ -115,7 +108,7 @@ const statementErrors = asyncComputed(async () => {
const runCheckInternal = async (statement: string) => {
const result = await releaseServiceClient.checkRelease({
- parent: database.value.project,
+ parent: project.value.name,
release: {
files: [
{
@@ -167,11 +160,16 @@ const runChecks = async () => {
};
isRunning.value = true;
- if (new Blob([statement.value]).size > STATEMENT_SKIP_CHECK_THRESHOLD) {
+ if (new Blob([sheetStatement.value]).size > STATEMENT_SKIP_CHECK_THRESHOLD) {
return handleErrors([t("issue.sql-check.statement-is-too-large")]);
}
try {
- checkResult.value = await runCheckInternal(statement.value);
+ checkResult.value = await runCheckInternal(sheetStatement.value);
+ // Upsert the result to the map.
+ for (const r of checkResult.value.results || []) {
+ // target is the database name.
+ upsertResult(r.target, r);
+ }
} finally {
isRunning.value = false;
}
@@ -189,10 +187,4 @@ const hasError = computed(() => {
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/Plan/components/SQLCheckSectionV1/SQLCheckSection.vue b/frontend/src/components/Plan/components/SQLCheckSection/SQLCheckSection.vue
similarity index 80%
rename from frontend/src/components/Plan/components/SQLCheckSectionV1/SQLCheckSection.vue
rename to frontend/src/components/Plan/components/SQLCheckSection/SQLCheckSection.vue
index ca8c50a076..671e32524d 100644
--- a/frontend/src/components/Plan/components/SQLCheckSectionV1/SQLCheckSection.vue
+++ b/frontend/src/components/Plan/components/SQLCheckSection/SQLCheckSection.vue
@@ -4,7 +4,7 @@
{{ $t("issue.sql-check.sql-checks") }}
</div>
<div
- v-if="database"
+ v-if="isValidDatabaseName(database.name)"
class="grow flex flex-row items-center justify-between gap-2"
>
<span v-if="checkResult === undefined" class="textinfolabel">
@@ -26,8 +26,7 @@
</div>
<SQLCheckButton
- :key="selectedSpec.id"
- :database="database"
+ :key="database.name"
button-style="--n-padding: 0 8px 0 6px; --n-icon-margin: 3px;"
:show-code-location="true"
/>
@@ -38,18 +37,12 @@
<script lang="ts" setup>
import { NTag, NTooltip } from "naive-ui";
import { computed } from "vue";
-import { databaseForSpec, usePlanContext } from "../../logic";
+import { isValidDatabaseName } from "@/types";
import SQLCheckBadge from "./SQLCheckBadge.vue";
import SQLCheckButton from "./SQLCheckButton.vue";
import { usePlanSQLCheckContext } from "./context";
-const { plan, selectedSpec } = usePlanContext();
-
-const { resultMap } = usePlanSQLCheckContext();
-
-const database = computed(() => {
- return databaseForSpec(plan.value.projectEntity, selectedSpec.value);
-});
+const { database, resultMap } = usePlanSQLCheckContext();
const checkResult = computed(() => {
return resultMap.value[database.value.name] || undefined;
diff --git a/frontend/src/components/Plan/components/SQLCheckSectionV1/common.ts b/frontend/src/components/Plan/components/SQLCheckSection/common.ts
similarity index 87%
rename from frontend/src/components/Plan/components/SQLCheckSectionV1/common.ts
rename to frontend/src/components/Plan/components/SQLCheckSection/common.ts
index c27bdc00fc..c7c3e1c9f9 100644
--- a/frontend/src/components/Plan/components/SQLCheckSectionV1/common.ts
+++ b/frontend/src/components/Plan/components/SQLCheckSection/common.ts
@@ -4,7 +4,9 @@ import {
} from "@/types/proto/v1/plan_service";
import { Release_File_ChangeType } from "@/types/proto/v1/release_service";
-export const getSpecChangeType = (spec: Plan_Spec): Release_File_ChangeType => {
+export const getSpecChangeType = (
+ spec?: Plan_Spec
+): Release_File_ChangeType => {
switch (spec?.changeDatabaseConfig?.type) {
case Plan_ChangeDatabaseConfig_Type.MIGRATE:
return Release_File_ChangeType.DDL;
diff --git a/frontend/src/components/Plan/components/SQLCheckSection/context.ts b/frontend/src/components/Plan/components/SQLCheckSection/context.ts
new file mode 100644
index 0000000000..39d7e98eba
--- /dev/null
+++ b/frontend/src/components/Plan/components/SQLCheckSection/context.ts
@@ -0,0 +1,53 @@
+import type { InjectionKey, Ref } from "vue";
+import { computed, inject, provide, ref } from "vue";
+import { databaseForTask } from "@/components/Rollout/RolloutDetail";
+import { unknownDatabase, type ComposedProject } from "@/types";
+import type { Plan, Plan_Spec } from "@/types/proto/v1/plan_service";
+import type { CheckReleaseResponse_CheckResult } from "@/types/proto/v1/release_service";
+import type { Task } from "@/types/proto/v1/rollout_service";
+import { databaseForSpec } from "../../logic";
+
+export const KEY = Symbol(
+ "bb.plan.context.sql-checks"
+) as InjectionKey<SQLCheckContext>;
+
+export const usePlanSQLCheckContext = () => {
+ return inject(KEY)!;
+};
+
+export const providePlanSQLCheckContext = (refs: {
+ project: Ref<ComposedProject>;
+ plan: Ref<Plan>;
+ selectedSpec: Ref<Plan_Spec>;
+ selectedTask?: Ref<Task | undefined>;
+}) => {
+ const resultMap = ref<Record<string, CheckReleaseResponse_CheckResult>>({});
+ const { project, plan, selectedSpec, selectedTask } = refs;
+
+ const database = computed(() => {
+ if (selectedTask?.value) {
+ return databaseForTask(project.value, selectedTask.value);
+ } else if (selectedSpec.value) {
+ // TODO(steven): handle db group as target in spec.
+ return databaseForSpec(project.value, selectedSpec.value);
+ }
+ return unknownDatabase();
+ });
+
+ const context = {
+ project,
+ plan,
+ database,
+ selectedSpec,
+ resultMap,
+ upsertResult: (key: string, result: CheckReleaseResponse_CheckResult) => {
+ resultMap.value[key] = result;
+ },
+ };
+
+ provide(KEY, context);
+
+ return context;
+};
+
+type SQLCheckContext = ReturnType<typeof providePlanSQLCheckContext>;
diff --git a/frontend/src/components/IssueV1/components/SQLCheckSection/index.ts b/frontend/src/components/Plan/components/SQLCheckSection/index.ts
similarity index 100%
rename from frontend/src/components/IssueV1/components/SQLCheckSection/index.ts
rename to frontend/src/components/Plan/components/SQLCheckSection/index.ts
diff --git a/frontend/src/components/Plan/components/SQLCheckSectionV1/AdviceStatusIcon.vue b/frontend/src/components/Plan/components/SQLCheckSectionV1/AdviceStatusIcon.vue
deleted file mode 100644
index 0b1dfa16c2..0000000000
--- a/frontend/src/components/Plan/components/SQLCheckSectionV1/AdviceStatusIcon.vue
+++ /dev/null
@@ -1,51 +0,0 @@
-<template>
- <NTooltip>
- <template #trigger>
- <template v-if="status === Advice_Status.SUCCESS">
- <CheckIcon :size="16" class="text-success" />
- </template>
- <template v-else-if="status === Advice_Status.WARNING">
- <TriangleAlertIcon :size="16" class="text-warning" />
- </template>
- <template v-else-if="status === Advice_Status.ERROR">
- <CircleAlertIcon :size="16" class="text-error" />
- </template>
- <template v-else>
- <PlayIcon :size="16" />
- </template>
- </template>
- {{ statusMessage }}
- </NTooltip>
-</template>
-
-<script setup lang="ts">
-import {
- CheckIcon,
- PlayIcon,
- TriangleAlertIcon,
- CircleAlertIcon,
-} from "lucide-vue-next";
-import { NTooltip } from "naive-ui";
-import { computed } from "vue";
-import { useI18n } from "vue-i18n";
-import { Advice_Status } from "@/types/proto/v1/sql_service";
-
-const props = defineProps<{
- status: Advice_Status;
-}>();
-
-const { t } = useI18n();
-
-const statusMessage = computed(() => {
- switch (props.status) {
- case Advice_Status.SUCCESS:
- return "Success";
- case Advice_Status.WARNING:
- return "Warning";
- case Advice_Status.ERROR:
- return "Error";
- default:
- return t("issue.sql-check.not-executed-yet");
- }
-});
-</script>
diff --git a/frontend/src/components/Plan/components/SQLCheckSectionV1/context.ts b/frontend/src/components/Plan/components/SQLCheckSectionV1/context.ts
deleted file mode 100644
index 29511419cc..0000000000
--- a/frontend/src/components/Plan/components/SQLCheckSectionV1/context.ts
+++ /dev/null
@@ -1,33 +0,0 @@
-import type { InjectionKey, Ref } from "vue";
-import { inject, provide, ref } from "vue";
-import type { CheckReleaseResponse_CheckResult } from "@/types/proto/v1/release_service";
-
-export type SQLCheckContext = {
- // Key is the database name.
- resultMap: Ref<Record<string, CheckReleaseResponse_CheckResult>>;
-
- upsertResult: (key: string, result: CheckReleaseResponse_CheckResult) => void;
-};
-
-export const KEY = Symbol(
- "bb.plan.context.sql-checks"
-) as InjectionKey<SQLCheckContext>;
-
-export const usePlanSQLCheckContext = () => {
- return inject(KEY)!;
-};
-
-export const providePlanSQLCheckContext = () => {
- const resultMap = ref<Record<string, CheckReleaseResponse_CheckResult>>({});
-
- const context: SQLCheckContext = {
- resultMap,
- upsertResult: (key, result) => {
- resultMap.value[key] = result;
- },
- };
-
- provide(KEY, context);
-
- return context;
-};
diff --git a/frontend/src/components/Plan/components/SQLCheckSectionV1/index.ts b/frontend/src/components/Plan/components/SQLCheckSectionV1/index.ts
deleted file mode 100644
index 2028b2b13c..0000000000
--- a/frontend/src/components/Plan/components/SQLCheckSectionV1/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-import SQLCheckSection from "./SQLCheckSection.vue";
-
-export default SQLCheckSection;
diff --git a/frontend/src/components/Plan/components/SpecListSection/SpecFilter.vue b/frontend/src/components/Plan/components/SpecListSection/SpecFilter.vue
index 94772f97b2..26851204b4 100644
--- a/frontend/src/components/Plan/components/SpecListSection/SpecFilter.vue
+++ b/frontend/src/components/Plan/components/SpecListSection/SpecFilter.vue
@@ -48,8 +48,8 @@ import { NTag } from "naive-ui";
import { computed } from "vue";
import { Advice_Status } from "@/types/proto/v1/sql_service";
import { usePlanContext } from "../../logic";
-import AdviceStatusIcon from "../SQLCheckSectionV1/AdviceStatusIcon.vue";
-import { usePlanSQLCheckContext } from "../SQLCheckSectionV1/context";
+import AdviceStatusIcon from "../SQLCheckSection/AdviceStatusIcon.vue";
+import { usePlanSQLCheckContext } from "../SQLCheckSection/context";
import { filterSpec } from "./filter";
defineProps<{
@@ -69,7 +69,7 @@ const ADVICE_STATUS_FILTERS: Advice_Status[] = [
];
const planContext = usePlanContext();
-const sqlCheckContext = usePlanSQLCheckContext();
+const { resultMap } = usePlanSQLCheckContext();
const { plan } = planContext;
@@ -77,7 +77,9 @@ const specList = computed(() => plan.value.steps.flatMap((step) => step.specs));
const getSpecCount = (adviceStatus?: Advice_Status) => {
return specList.value.filter((spec) =>
- filterSpec(planContext, sqlCheckContext, spec, { adviceStatus })
+ filterSpec(planContext, resultMap.value, spec, {
+ adviceStatus,
+ })
).length;
};
</script>
diff --git a/frontend/src/components/Plan/components/SpecListSection/SpecListSection.vue b/frontend/src/components/Plan/components/SpecListSection/SpecListSection.vue
index 9bbdb5885b..cee5353a16 100644
--- a/frontend/src/components/Plan/components/SpecListSection/SpecListSection.vue
+++ b/frontend/src/components/Plan/components/SpecListSection/SpecListSection.vue
@@ -70,7 +70,7 @@ import {
targetOfSpec,
usePlanContext,
} from "../../logic";
-import { usePlanSQLCheckContext } from "../SQLCheckSectionV1/context";
+import { usePlanSQLCheckContext } from "../SQLCheckSection/context";
import CurrentSpecSection from "./CurrentSpecSection.vue";
import SpecCard from "./SpecCard.vue";
import SpecFilter from "./SpecFilter.vue";
@@ -90,7 +90,7 @@ const MAX_LIST_HEIGHT = 256;
const SPEC_PER_PAGE = isDev() ? 4 : 20;
const planContext = usePlanContext();
-const sqlCheckContext = usePlanSQLCheckContext();
+const { resultMap } = usePlanSQLCheckContext();
const { plan, selectedSpec } = planContext;
const dbGroupStore = useDBGroupStore();
const state = reactive<LocalState>({
@@ -108,7 +108,7 @@ const filteredSpecList = computed(() => {
if (state.adviceStatusFilters.length > 0) {
if (
!state.adviceStatusFilters.some((status) =>
- filterSpec(planContext, sqlCheckContext, spec, {
+ filterSpec(planContext, resultMap.value, spec, {
adviceStatus: status,
})
)
diff --git a/frontend/src/components/Plan/components/SpecListSection/filter.ts b/frontend/src/components/Plan/components/SpecListSection/filter.ts
index 8f7f95149d..f8cee5c5a1 100644
--- a/frontend/src/components/Plan/components/SpecListSection/filter.ts
+++ b/frontend/src/components/Plan/components/SpecListSection/filter.ts
@@ -1,13 +1,13 @@
import { planCheckRunSummaryForCheckRunList } from "@/components/PlanCheckRun/common";
import type { Plan_Spec } from "@/types/proto/v1/plan_service";
+import type { CheckReleaseResponse_CheckResult } from "@/types/proto/v1/release_service";
import { Advice_Status } from "@/types/proto/v1/sql_service";
import { sheetNameOfSpec } from "@/utils";
import { targetOfSpec, type PlanContext } from "../../logic";
-import type { SQLCheckContext } from "../SQLCheckSectionV1/context";
export const filterSpec = (
planContext: PlanContext,
- sqlCheckContext: SQLCheckContext,
+ sqlCheckResultMap: Record<string, CheckReleaseResponse_CheckResult>,
spec: Plan_Spec,
{
adviceStatus,
@@ -18,8 +18,7 @@ export const filterSpec = (
const { isCreating } = planContext;
if (adviceStatus) {
if (isCreating.value) {
- const { resultMap } = sqlCheckContext;
- const result = resultMap.value[targetOfSpec(spec) || ""];
+ const result = sqlCheckResultMap[targetOfSpec(spec) || ""];
if (adviceStatus === Advice_Status.UNRECOGNIZED) {
return !Boolean(result);
}
diff --git a/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue b/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue
index e1e06093a6..7fde4c7de3 100644
--- a/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue
+++ b/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue
@@ -226,7 +226,7 @@ import {
getStatementSize,
flattenSpecList,
} from "@/utils";
-import { usePlanSQLCheckContext } from "../../SQLCheckSectionV1/context";
+import { usePlanSQLCheckContext } from "../../SQLCheckSection/context";
import { useSQLAdviceMarkers } from "../useSQLAdviceMarkers";
import FormatOnSaveCheckbox from "./FormatOnSaveCheckbox.vue";
import type { EditState } from "./useTempEditState";
diff --git a/frontend/src/components/Plan/components/StatementSection/EditorView/useTempEditState.ts b/frontend/src/components/Plan/components/StatementSection/EditorView/useTempEditState.ts
index 4821fad4a5..d3dada6879 100644
--- a/frontend/src/components/Plan/components/StatementSection/EditorView/useTempEditState.ts
+++ b/frontend/src/components/Plan/components/StatementSection/EditorView/useTempEditState.ts
@@ -10,7 +10,9 @@ export type EditState = {
export const useTempEditState = (state: EditState) => {
const { isCreating, selectedSpec } = usePlanContext();
- const { sheet, sheetName, sheetReady, sheetStatement } = useSpecSheet();
+ const { sheet, sheetName, sheetReady, sheetStatement } = useSpecSheet(
+ selectedSpec.value
+ );
let stopWatching = () => {
// noop
diff --git a/frontend/src/components/Plan/components/StatementSection/useSpecSheet.ts b/frontend/src/components/Plan/components/StatementSection/useSpecSheet.ts
index 167c010369..0a3581bcf4 100644
--- a/frontend/src/components/Plan/components/StatementSection/useSpecSheet.ts
+++ b/frontend/src/components/Plan/components/StatementSection/useSpecSheet.ts
@@ -1,20 +1,20 @@
import { computedAsync } from "@vueuse/core";
import { computed, ref } from "vue";
+import { getLocalSheetByName } from "@/components/Plan";
import { useSheetV1Store } from "@/store";
+import type { Plan_Spec } from "@/types/proto/v1/plan_service";
import {
extractSheetUID,
getSheetStatement,
setSheetStatement,
sheetNameOfSpec,
} from "@/utils";
-import { getLocalSheetByName, usePlanContext } from "../../logic";
-export const useSpecSheet = () => {
+export const useSpecSheet = (spec: Plan_Spec) => {
const sheetStore = useSheetV1Store();
- const { selectedSpec } = usePlanContext();
const sheetName = computed(() => {
- return sheetNameOfSpec(selectedSpec.value);
+ return sheetNameOfSpec(spec);
});
const isFetchingSheet = ref(false);
const sheetReady = computed(() => {
diff --git a/frontend/src/components/Plan/components/index.ts b/frontend/src/components/Plan/components/index.ts
index bcc065e11a..c0a362dae9 100644
--- a/frontend/src/components/Plan/components/index.ts
+++ b/frontend/src/components/Plan/components/index.ts
@@ -1,7 +1,7 @@
import DescriptionSection from "./DescriptionSection";
import HeaderSection from "./HeaderSection";
import PlanCheckSection from "./PlanCheckSection";
-import SQLCheckSectionV1 from "./SQLCheckSectionV1";
+import SQLCheckSection from "./SQLCheckSection";
import SpecListSection from "./SpecListSection";
import StatementSection from "./StatementSection";
@@ -9,7 +9,7 @@ export {
HeaderSection,
SpecListSection,
PlanCheckSection,
- SQLCheckSectionV1,
+ SQLCheckSection,
StatementSection,
DescriptionSection,
};
diff --git a/frontend/src/components/PlanCheckRun/PlanCheckRunDetail.vue b/frontend/src/components/PlanCheckRun/PlanCheckRunDetail.vue
index 3b2e0f70ea..ef72db73b4 100644
--- a/frontend/src/components/PlanCheckRun/PlanCheckRunDetail.vue
+++ b/frontend/src/components/PlanCheckRun/PlanCheckRunDetail.vue
@@ -293,7 +293,6 @@ const props = defineProps<{
const { t } = useI18n();
const router = useRouter();
-const { events } = usePlanCheckRunContext();
const hideDocLink = useAppFeature("bb.feature.sql-check.hide-doc-link");
const state = reactive<LocalState>({
activeRule: undefined,
@@ -533,6 +532,8 @@ const cancelPlanCheckRun = async () => {
parent: `${projectNamePrefix}${projectName}/${planNamePrefix}${planId}`,
planCheckRuns: [planCheckRunName],
});
- events.emit("status-changed");
+ if (usePlanCheckRunContext()) {
+ usePlanCheckRunContext().events.emit("status-changed");
+ }
};
</script>
diff --git a/frontend/src/components/SQLCheck/SQLCheckButton.vue b/frontend/src/components/SQLCheck/SQLCheckButton.vue
index a9efa6d1c0..b87d4d4099 100644
--- a/frontend/src/components/SQLCheck/SQLCheckButton.vue
+++ b/frontend/src/components/SQLCheck/SQLCheckButton.vue
@@ -84,7 +84,6 @@ import {
import { Advice, Advice_Status } from "@/types/proto/v1/sql_service";
import type { Defer, VueStyle } from "@/utils";
import { defer } from "@/utils";
-import { providePlanCheckRunContext } from "../PlanCheckRun/context";
import ErrorList from "../misc/ErrorList.vue";
import SQLCheckPanel from "./SQLCheckPanel.vue";
import SQLCheckSummary from "./SQLCheckSummary.vue";
@@ -152,8 +151,6 @@ const statementErrors = asyncComputed(async () => {
return [];
}, []);
-providePlanCheckRunContext({});
-
const runCheckInternal = async (statement: string) => {
const { database, changeType } = props;
const result = await releaseServiceClient.checkRelease({