Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore(plan): update sql check section (#16081)
boojack42ae7d940141
diff --git a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vueindex 0e61b8ca69..ebe3012b37 100644--- a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue+++ b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue@@ -15,27 +15,20 @@<divclass="space-y-4 h-full w-[calc(100vw-8rem)] lg:w-[60rem] max-w-[calc(100vw-8rem)] overflow-x-auto">- <div>- <div class="space-y-3">- <div class="w-full flex items-center space-x-2">- <AdvancedSearch- v-model:params="state.params"- :autofocus="false"- :placeholder="$t('database.filter-database')"- :scope-options="scopeOptions"- />- </div>-- <PagedDatabaseTable- mode="ALL_SHORT"- :filter="filter"- :parent="projectName"- :custom-click="true"- :show-sql-editor-button="false"- v-model:selected-database-names="state.selectedDatabaseNames"- />- </div>- </div>+ <AdvancedSearch+ v-model:params="state.params"+ :autofocus="false"+ :placeholder="$t('database.filter-database')"+ :scope-options="scopeOptions"+ />+ <PagedDatabaseTable+ mode="ALL_SHORT"+ :filter="filter"+ :parent="projectName"+ :custom-click="true"+ :show-sql-editor-button="false"+ v-model:selected-database-names="state.selectedDatabaseNames"+ /></div><template #footer>diff --git a/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vue b/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vueindex 551c69c770..2d9cf3c1c1 100644--- a/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vue+++ b/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vue@@ -28,6 +28,7 @@<SQLCheckPanelv-if="showSQLCheckResultPanel && databaseForTask(issue, selectedTask)"+ :project="issue.project":database="databaseForTask(issue, selectedTask)":advices="checkResultMap[databaseForTask(issue, selectedTask).name].advices":affected-rows="@@ -146,7 +147,9 @@ const issueCreateErrorList = computed(() => {issue.value.projectEntity.issueLabels).length === 0) {- errorList.push(t("project.settings.issue-related.labels.force-issue-labels.warning"));+ errorList.push(+ t("project.settings.issue-related.labels.force-issue-labels.warning")+ );}return errorList;});diff --git a/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckBadge.vue b/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckBadge.vueindex 23729f6422..efd9e893e0 100644--- a/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckBadge.vue+++ b/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckBadge.vue@@ -24,6 +24,7 @@<SQLCheckPanelv-if="showDetailPanel"+ :project="issue.project":database="database":advices="advices"@close="showDetailPanel = false"diff --git a/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckButton.vue b/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckButton.vueindex 98abecd360..5e49f3270d 100644--- a/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckButton.vue+++ b/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckButton.vue@@ -30,6 +30,7 @@<SQLCheckPanelv-if="checkResult && advices && showDetailPanel"+ :project="issue.project":database="database":advices="advices":affected-rows="checkResult.affectedRows"diff --git a/frontend/src/components/Plan/PlanDetailPage.vue b/frontend/src/components/Plan/PlanDetailPage.vueindex 56e013f845..0b4cddb108 100644--- a/frontend/src/components/Plan/PlanDetailPage.vue+++ b/frontend/src/components/Plan/PlanDetailPage.vue@@ -8,11 +8,9 @@class="flex-1 flex flex-col hide-scrollbar divide-y overflow-x-hidden"><SpecListSection />-- <SQLCheckSection v-if="isCreating" @update:advices="advices = $event" />- <PlanCheckSection v-if="!isCreating" />-- <StatementSection :advices="advices" />+ <SQLCheckSectionV1 v-if="isCreating" />+ <PlanCheckSection v-else />+ <StatementSection /><DescriptionSection /></div></div>@@ -20,23 +18,20 @@</template><script setup lang="ts">-import { ref } from "vue";-import type { Advice } from "@/types/proto/v1/sql_service";-import { provideSQLCheckContext } from "../SQLCheck";import {HeaderSection,PlanCheckSection,StatementSection,DescriptionSection,- SQLCheckSection,+ SQLCheckSectionV1,SpecListSection,} from "./components";+import { providePlanSQLCheckContext } from "./components/SQLCheckSectionV1/context";import { usePlanContext, usePollPlan } from "./logic";const { isCreating } = usePlanContext();-const advices = ref<Advice[]>();usePollPlan();-provideSQLCheckContext();+providePlanSQLCheckContext();</script>diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateButton.vue b/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateButton.vueindex 207ff1f141..54d370e33f 100644--- a/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateButton.vue+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateButton.vue@@ -41,7 +41,6 @@ import {isValidSpec,} from "@/components/Plan/logic";import { usePlanContext } from "@/components/Plan/logic";-import { useSQLCheckContext } from "@/components/SQLCheck";import { planServiceClient } from "@/grpcweb";import { PROJECT_V1_ROUTE_REVIEW_CENTER_DETAIL } from "@/router/dashboard/projectV1";import { useDatabaseV1Store, useSheetV1Store } from "@/store";@@ -64,7 +63,6 @@ const MAX_FORMATTABLE_STATEMENT_SIZE = 10000; // 10K charactersconst { t } = useI18n();const router = useRouter();const { plan, formatOnSave } = usePlanContext();-const { runSQLCheck } = useSQLCheckContext();const sheetStore = useSheetV1Store();const loading = ref(false);@@ -85,11 +83,6 @@ const planCreateErrorList = computed(() => {const doCreatePlan = async () => {loading.value = true;- const check = runSQLCheck.value;- if (check && !(await check())) {- loading.value = false;- return;- }try {await createSheets();diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateIssueButton.vue b/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateIssueButton.vueindex 5d4f318b6e..7eb2102b57 100644--- a/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateIssueButton.vue+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateIssueButton.vue@@ -40,7 +40,6 @@ import {usePlanContext,} from "@/components/Plan/logic";import { planCheckRunSummaryForCheckRunList } from "@/components/PlanCheckRun/common";-import { useSQLCheckContext } from "@/components/SQLCheck";import { issueServiceClient, rolloutServiceClient } from "@/grpcweb";import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";import { useCurrentUserV1, usePolicyV1Store } from "@/store";@@ -59,7 +58,6 @@ const router = useRouter();const dialog = useDialog();const policyV1Store = usePolicyV1Store();const { plan } = usePlanContext();-const { runSQLCheck } = useSQLCheckContext();const loading = ref(false);const restrictIssueCreationForSqlReviewPolicy = ref(false);@@ -140,11 +138,7 @@ const handleCreateIssue = async () => {const doCreateIssue = async () => {loading.value = true;- const check = runSQLCheck.value;- if (check && !(await check())) {- loading.value = false;- return;- }+ // TODO(steven): Check plan check results before creating issue.try {const createdIssue = await issueServiceClient.createIssue({diff --git a/frontend/src/components/Plan/components/SQLCheckSection/SQLCheckBadge.vue b/frontend/src/components/Plan/components/SQLCheckSection/SQLCheckBadge.vuedeleted file mode 100644index 08d5de3e57..0000000000--- a/frontend/src/components/Plan/components/SQLCheckSection/SQLCheckBadge.vue+++ /dev/null@@ -1,127 +0,0 @@-<template>- <button- class="inline-flex items-center px-3 py-0.5 rounded-full text-sm border border-transparent"- :class="buttonClasses"- @click="handleClick"- >- <template v-if="status === 'RUNNING'">- <TaskSpinner class="-ml-1 mr-1.5 h-4 w-4 text-info" />- </template>- <template v-else-if="status === 'SUCCESS'">- <heroicons-outline:check- class="-ml-1 mr-1.5 mt-0.5 h-4 w-4 text-success"- />- </template>- <template v-else-if="status === 'WARNING'">- <heroicons-outline:exclamation- class="-ml-1 mr-1.5 mt-0.5 h-4 w-4 text-warning"- />- </template>- <template v-else-if="status === 'ERROR'">- <span class="mr-1.5 font-medium text-error" aria-hidden="true"> ! </span>- </template>-- <span>{{ $t("task.check-type.sql-review") }}</span>-- <SQLCheckPanel- v-if="showDetailPanel"- :database="database"- :advices="advices"- @close="showDetailPanel = false"- >- </SQLCheckPanel>- </button>-</template>--<script setup lang="ts">-import { computed, ref } from "vue";-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";--const props = defineProps<{- isRunning: boolean;- advices: Advice[];-}>();--defineEmits<{- (event: "click"): void;-}>();--const { plan, selectedSpec } = usePlanContext();-const showDetailPanel = ref(false);--const database = computed(() => {- return databaseForSpec(plan.value, selectedSpec.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 buttonClasses = computed(() => {- let bgColor = "";- let bgHoverColor = "";- let textColor = "";- let borderColor = "";- switch (status.value) {- case "RUNNING":- bgColor = "bg-blue-100";- bgHoverColor = "bg-blue-300";- textColor = "text-blue-800";- borderColor = "border-blue-800";- break;- case "SUCCESS":- bgColor = "bg-gray-100";- bgHoverColor = "bg-gray-300";- textColor = "text-gray-800";- borderColor = "border-gray-800";- break;- case "WARNING":- bgColor = "bg-yellow-100";- bgHoverColor = "bg-yellow-300";- textColor = "text-yellow-800";- borderColor = "border-yellow-800";- break;- case "ERROR":- bgColor = "bg-red-100";- bgHoverColor = "bg-red-300";- textColor = "text-red-800";- borderColor = "border-red-800";- break;- }-- const styleList: string[] = [textColor, bgColor];- if (clickable.value) {- styleList.push(- "cursor-pointer",- `hover:${bgHoverColor}`,- `hover:${borderColor}`- );- } else {- styleList.push("cursor-default");- }-- return styleList.join(" ");-});--const handleClick = () => {- showDetailPanel.value = true;-};-</script>diff --git a/frontend/src/components/Plan/components/SQLCheckSection/SQLCheckSection.vue b/frontend/src/components/Plan/components/SQLCheckSection/SQLCheckSection.vuedeleted file mode 100644index e99b8ca6d2..0000000000--- a/frontend/src/components/Plan/components/SQLCheckSection/SQLCheckSection.vue+++ /dev/null@@ -1,72 +0,0 @@-<template>- <div class="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- v-if="database"- :key="selectedSpec.id"- :get-statement="getStatement"- :database="database"- :change-type="changeType"- :button-props="{- size: 'tiny',- }"- button-style="--n-padding: 0 8px 0 6px; --n-icon-margin: 3px;"- class="justify-between flex-1"- @update:advices="$emit('update:advices', $event)"- >- <template #result="{ advices, isRunning }">- <template v-if="advices === undefined">- <span class="textinfolabel">- {{ $t("issue.sql-check.not-executed-yet") }}- </span>- </template>- <SQLCheckBadge v-else :is-running="isRunning" :advices="advices" />- </template>- </SQLCheckButton>- </div>-</template>--<script lang="ts" setup>-import { computed } from "vue";-import { databaseForSpec } from "@/components/Plan/logic";-import { SQLCheckButton } from "@/components/SQLCheck";-import { Plan_ChangeDatabaseConfig_Type } from "@/types/proto/v1/plan_service";-import { Release_File_ChangeType } from "@/types/proto/v1/release_service";-import { Advice } from "@/types/proto/v1/sql_service";-import { usePlanContext } from "../../logic";-import { useSpecSheet } from "../StatementSection/useSpecSheet";-import SQLCheckBadge from "./SQLCheckBadge.vue";--defineEmits<{- (event: "update:advices", advices: Advice[] | undefined): void;-}>();--const { plan, selectedSpec } = usePlanContext();-const { sheetStatement } = useSpecSheet();--const database = computed(() => {- return databaseForSpec(plan.value, selectedSpec.value);-});--const getStatement = async () => {- return {- statement: sheetStatement.value,- errors: [],- };-};--const changeType = computed((): Release_File_ChangeType | undefined => {- switch (selectedSpec.value?.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;-});-</script>diff --git a/frontend/src/components/Plan/components/SQLCheckSectionV1/AdviceStatusIcon.vue b/frontend/src/components/Plan/components/SQLCheckSectionV1/AdviceStatusIcon.vuenew file mode 100644index 0000000000..0b1dfa16c2--- /dev/null+++ b/frontend/src/components/Plan/components/SQLCheckSectionV1/AdviceStatusIcon.vue@@ -0,0 +1,51 @@+<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/SQLCheckBadge.vue b/frontend/src/components/Plan/components/SQLCheckSectionV1/SQLCheckBadge.vuenew file mode 100644index 0000000000..40ac3eb75c--- /dev/null+++ b/frontend/src/components/Plan/components/SQLCheckSectionV1/SQLCheckBadge.vue@@ -0,0 +1,96 @@+<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="plan.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 { 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";++const props = defineProps<{+ advices: Advice[];+ isRunning?: boolean;+}>();++defineEmits<{+ (event: "click"): void;+}>();++const { plan, selectedSpec } = usePlanContext();+const showDetailPanel = ref(false);++const database = computed(() => {+ return databaseForSpec(plan.value, selectedSpec.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/Plan/components/SQLCheckSectionV1/SQLCheckButton.vue b/frontend/src/components/Plan/components/SQLCheckSectionV1/SQLCheckButton.vuenew file mode 100644index 0000000000..7904b8007a--- /dev/null+++ b/frontend/src/components/Plan/components/SQLCheckSectionV1/SQLCheckButton.vue@@ -0,0 +1,199 @@+<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="plan.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 { 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 { databaseForSpec, usePlanContext } from "../../logic";+import { useSpecSheet } from "../StatementSection/useSpecSheet";+import { getSpecChangeType } from "./common";+import { usePlanSQLCheckContext } from "./context";++withDefaults(+ defineProps<{+ buttonStyle?: VueStyle;+ showCodeLocation?: boolean;+ }>(),+ {+ buttonStyle: undefined,+ showCodeLocation: undefined,+ }+);++const { t } = useI18n();+const { plan, selectedSpec } = usePlanContext();+const { upsertResult } = usePlanSQLCheckContext();+const { sheetStatement } = useSpecSheet();++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(() =>+ databaseForSpec(plan.value, selectedSpec.value)+);++const statement = computed(() => sheetStatement.value);++const changeType = computed(() => getSpecChangeType(selectedSpec.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: 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/Plan/components/SQLCheckSectionV1/SQLCheckSection.vue b/frontend/src/components/Plan/components/SQLCheckSectionV1/SQLCheckSection.vuenew file mode 100644index 0000000000..716a3dd6a9--- /dev/null+++ b/frontend/src/components/Plan/components/SQLCheckSectionV1/SQLCheckSection.vue@@ -0,0 +1,57 @@+<template>+ <div 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>{{ checkResult.affectedRows }}</span>+ </NTag>+ </template>+ {{ $t("task.check-type.affected-rows.description") }}+ </NTooltip>+ </div>++ <SQLCheckButton+ :key="selectedSpec.id"+ :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 { databaseForSpec, usePlanContext } from "../../logic";+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, selectedSpec.value);+});++const checkResult = computed(() => {+ return resultMap.value[database.value.name] || undefined;+});+</script>diff --git a/frontend/src/components/Plan/components/SQLCheckSectionV1/common.ts b/frontend/src/components/Plan/components/SQLCheckSectionV1/common.tsnew file mode 100644index 0000000000..c27bdc00fc--- /dev/null+++ b/frontend/src/components/Plan/components/SQLCheckSectionV1/common.ts@@ -0,0 +1,18 @@+import {+ Plan_ChangeDatabaseConfig_Type,+ Plan_Spec,+} 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 => {+ 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/Plan/components/SQLCheckSectionV1/context.ts b/frontend/src/components/Plan/components/SQLCheckSectionV1/context.tsnew file mode 100644index 0000000000..29511419cc--- /dev/null+++ b/frontend/src/components/Plan/components/SQLCheckSectionV1/context.ts@@ -0,0 +1,33 @@+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/SQLCheckSection/index.ts b/frontend/src/components/Plan/components/SQLCheckSectionV1/index.tssimilarity index 100%rename from frontend/src/components/Plan/components/SQLCheckSection/index.tsrename to frontend/src/components/Plan/components/SQLCheckSectionV1/index.tsdiff --git a/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue b/frontend/src/components/Plan/components/SpecListSection/SpecCard.vueindex af63d5b8e0..71a93c2dcf 100644--- a/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue+++ b/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue@@ -32,7 +32,7 @@</NTooltip><divv-if="isDatabaseChangeSpec(spec)"- class="flex items-center gap-2 truncate"+ class="flex items-center gap-1 truncate"><InstanceV1Name:instance="databaseForSpec(plan, spec).instanceResource"@@ -43,13 +43,14 @@databaseForSpec(plan, spec).databaseName}}</span></div>- <!-- Fallback to show the database group name if the spec is a grouping change spec in old plans. --><divv-else-if="isGroupingChangeSpec(spec) && relatedDatabaseGroup"class="flex items-center gap-2 truncate"><NTooltip>- <template #trigger><DatabaseGroupIcon class="w-4 h-auto" /></template>+ <template #trigger>+ <DatabaseGroupIcon class="w-4 h-auto" />+ </template>{{ $t("dynamic.resource.database-group") }}</NTooltip><span class="truncate text-sm">{{@@ -57,7 +58,7 @@}}</span></div><!-- Fallback -->- <div v-else class="flex items-center gap-2 text-sm">Unknown type</div>+ <div v-else class="flex items-center gap-2 text-sm">Unknown target</div></div></template>@@ -68,7 +69,7 @@ import { computed, onMounted } from "vue";import DatabaseGroupIcon from "@/components/DatabaseGroupIcon.vue";import { planCheckRunSummaryForCheckRunList } from "@/components/PlanCheckRun/common";import { InstanceV1Name } from "@/components/v2";-import { useDBGroupStore } from "@/store";+import { useDatabaseV1Store, useDBGroupStore } from "@/store";import { DatabaseGroupView } from "@/types/proto/v1/database_group_service";import {PlanCheckRun_Result_Status,@@ -87,6 +88,7 @@ const props = defineProps<{}>();const { isCreating, plan, selectedSpec, events } = usePlanContext();+const databaseStore = useDatabaseV1Store();const dbGroupStore = useDBGroupStore();const specClass = computed(() => {@@ -118,7 +120,6 @@ const relatedDatabaseGroup = computed(() => {const planCheckStatus = computed((): PlanCheckRun_Result_Status => {if (isCreating.value) return PlanCheckRun_Result_Status.STATUS_UNSPECIFIED;-const summary = planCheckRunSummaryForCheckRunList(planCheckRunListForSpec(plan.value, props.spec));@@ -131,8 +132,13 @@ const planCheckStatus = computed((): PlanCheckRun_Result_Status => {return PlanCheckRun_Result_Status.SUCCESS;});+// Prepare target.onMounted(async () => {- if (isGroupingChangeSpec(props.spec)) {+ if (isDatabaseChangeSpec(props.spec)) {+ await databaseStore.getOrFetchDatabaseByName(+ props.spec.changeDatabaseConfig!.target+ );+ } else if (isGroupingChangeSpec(props.spec)) {await dbGroupStore.getOrFetchDBGroupByName(props.spec.changeDatabaseConfig!.target,{diff --git a/frontend/src/components/Plan/components/SpecListSection/SpecListSection.vue b/frontend/src/components/Plan/components/SpecListSection/SpecListSection.vueindex ed39f31e49..ac5af3c8be 100644--- a/frontend/src/components/Plan/components/SpecListSection/SpecListSection.vue+++ b/frontend/src/components/Plan/components/SpecListSection/SpecListSection.vue@@ -2,7 +2,7 @@<div class="w-full relative"><divref="specBar"- class="spec-list w-full gap-2 px-4 py-2 grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-5 4xl:grid-cols-6 overflow-y-auto"+ class="spec-list gap-2 px-4 py-2 grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 3xl:grid-cols-5 4xl:grid-cols-6 overflow-y-auto":class="{'more-bottom': specBarScrollState.bottom,'more-top': specBarScrollState.top,@@ -22,7 +22,7 @@ import { useVerticalScrollState } from "@/composables/useScrollState";import { usePlanContext } from "../../logic";import SpecCard from "./SpecCard.vue";-const MAX_LIST_HEIGHT = 207;+const MAX_LIST_HEIGHT = 256;const { plan } = usePlanContext();const specBar = ref<HTMLDivElement>();@@ -33,12 +33,12 @@ const specList = computed(() => plan.value.steps.flatMap((step) => step.specs));<style scoped lang="postcss">.spec-list::before {- @apply absolute top-0 h-4 w-full -ml-2 z-10 pointer-events-none transition-shadow;+ @apply absolute top-0 h-4 w-full -ml-4 z-10 pointer-events-none transition-shadow;content: "";box-shadow: none;}.spec-list::after {- @apply absolute bottom-0 h-4 w-full -ml-2 z-10 pointer-events-none transition-shadow;+ @apply absolute bottom-0 h-4 w-full -ml-4 z-10 pointer-events-none transition-shadow;content: "";box-shadow: none;}diff --git a/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue b/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vueindex 7a343e4558..566c3f417c 100644--- a/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue+++ b/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue@@ -196,7 +196,7 @@ import { cloneDeep, head, isEmpty } from "lodash-es";import { ExpandIcon } from "lucide-vue-next";import { NButton, NTooltip, useDialog } from "naive-ui";import { v1 as uuidv1 } from "uuid";-import { computed, h, reactive, ref, toRef, watch } from "vue";+import { computed, h, reactive, ref, watch } from "vue";import { useI18n } from "vue-i18n";import { BBAttention, BBModal } from "@/bbkit";import { FeatureModal } from "@/components/FeatureGuard";@@ -218,7 +218,6 @@ import type { SQLDialect } from "@/types";import { EMPTY_ID, dialectOfEngineV1 } from "@/types";import type { Plan_Spec } from "@/types/proto/v1/plan_service";import { Sheet } from "@/types/proto/v1/sheet_service";-import type { Advice } from "@/types/proto/v1/sql_service";import {defer,getSheetStatement,@@ -227,6 +226,7 @@ import {getStatementSize,flattenSpecList,} from "@/utils";+import { usePlanSQLCheckContext } from "../../SQLCheckSectionV1/context";import { useSQLAdviceMarkers } from "../useSQLAdviceMarkers";import FormatOnSaveCheckbox from "./FormatOnSaveCheckbox.vue";import type { EditState } from "./useTempEditState";@@ -238,15 +238,11 @@ type LocalState = EditState & {isUploadingFile: boolean;};-const props = defineProps<{- advices?: Advice[];-}>();-const { t } = useI18n();-const context = usePlanContext();-const { isCreating, plan, selectedSpec, formatOnSave, events } =- usePlanContext();const dialog = useDialog();+const context = usePlanContext();+const { isCreating, plan, selectedSpec, formatOnSave, events } = context;+const { resultMap } = usePlanSQLCheckContext();const editorContainerElRef = ref<HTMLElement>();const monacoEditorRef = ref<InstanceType<typeof MonacoEditor>>();const { height: editorContainerHeight } = useElementSize(editorContainerElRef);@@ -278,7 +274,11 @@ const dialect = computed((): SQLDialect => {const statementTitle = computed(() => {return language.value === "sql" ? t("common.sql") : t("common.statement");});-const { markers } = useSQLAdviceMarkers(context, toRef(props, "advices"));+const advices = computed(() => {+ const database = databaseForSpec(plan.value, selectedSpec.value);+ return resultMap.value[database.name]?.advices || [];+});+const { markers } = useSQLAdviceMarkers(context, advices);/*** to set the MonacoEditor as readonlydiff --git a/frontend/src/components/Plan/components/StatementSection/StatementSection.vue b/frontend/src/components/Plan/components/StatementSection/StatementSection.vueindex 682526f37b..25b6e1f7d1 100644--- a/frontend/src/components/Plan/components/StatementSection/StatementSection.vue+++ b/frontend/src/components/Plan/components/StatementSection/StatementSection.vue@@ -1,52 +1,23 @@<template><div v-if="viewMode !== 'NONE'" class="px-4 py-2 flex flex-col gap-y-2">- <EditorView ref="editorViewRef" :advices="advices" />+ <EditorView ref="editorViewRef" /></div></template><script setup lang="ts">import { computed } from "vue";import { ref } from "vue";-import { nextTick } from "vue";-import { useRouter } from "vue-router";import { EMPTY_ID } from "@/types";-import type { Advice } from "@/types/proto/v1/sql_service";-import { usePlanContext } from "../../logic";+import { usePlanContext } from "../..";import EditorView from "./EditorView";-defineProps<{- advices?: Advice[];-}>();-const { selectedSpec } = usePlanContext();-const editorViewRef = ref<InstanceType<typeof EditorView>>();-const router = useRouter();-type ViewMode = "NONE" | "EDITOR";--const viewMode = computed((): ViewMode => {+const viewMode = computed((): "NONE" | "EDITOR" => {if (selectedSpec.value.id !== String(EMPTY_ID)) {return "EDITOR";}-return "NONE";});--router.afterEach((to) => {- if (to.hash) {- scrollToLineByHash(to.hash);- }-});--const scrollToLineByHash = (hash: string) => {- const match = hash.match(/^#L(\d+)$/);- if (!match) return;- const lineNumber = parseInt(match[1], 10);- nextTick(() => {- editorViewRef.value?.editor?.monacoEditor?.editor?.codeEditor?.revealLineNearTop(- lineNumber- );- });-};</script>diff --git a/frontend/src/components/Plan/components/index.ts b/frontend/src/components/Plan/components/index.tsindex 85f9404392..bcc065e11a 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 SQLCheckSection from "./SQLCheckSection";+import SQLCheckSectionV1 from "./SQLCheckSectionV1";import SpecListSection from "./SpecListSection";import StatementSection from "./StatementSection";@@ -9,7 +9,7 @@ export {HeaderSection,SpecListSection,PlanCheckSection,+ SQLCheckSectionV1,StatementSection,DescriptionSection,- SQLCheckSection,};diff --git a/frontend/src/components/Plan/logic/index.ts b/frontend/src/components/Plan/logic/index.tsindex c4bac3a552..3cd9982525 100644--- a/frontend/src/components/Plan/logic/index.ts+++ b/frontend/src/components/Plan/logic/index.ts@@ -5,3 +5,4 @@ export * from "./initialize";export * from "./sheet";export * from "./plan-check";export * from "./poll";+export * from "./utils";diff --git a/frontend/src/components/Plan/logic/utils.ts b/frontend/src/components/Plan/logic/utils.tsnew file mode 100644index 0000000000..5930decfa8--- /dev/null+++ b/frontend/src/components/Plan/logic/utils.ts@@ -0,0 +1,32 @@+import { mockDatabase } from "@/components/IssueV1";+import { useDatabaseV1Store } from "@/store";+import { isValidDatabaseName, unknownDatabase } from "@/types";+import type { Plan_Spec } from "@/types/proto/v1/plan_service";+import type { ComposedPlan } from "@/types/v1/issue/plan";++export const targetOfSpec = (spec: Plan_Spec) => {+ if (spec.changeDatabaseConfig) {+ return spec.changeDatabaseConfig.target;+ } else if (spec.exportDataConfig) {+ return spec.exportDataConfig.target;+ }+ return undefined;+};++export const databaseOfSpec = (plan: ComposedPlan, spec: Plan_Spec) => {+ if (spec.createDatabaseConfig) {+ return mockDatabase(+ plan.projectEntity,+ `${spec.createDatabaseConfig.target}/databases/${spec.createDatabaseConfig.database}`+ );+ }+ const target = targetOfSpec(spec);+ if (!target) {+ return unknownDatabase();+ }+ const db = useDatabaseV1Store().getDatabaseByName(target);+ if (!isValidDatabaseName(db.name)) {+ return mockDatabase(plan.projectEntity, target);+ }+ return db;+};diff --git a/frontend/src/components/SQLCheck/SQLCheckButton.vue b/frontend/src/components/SQLCheck/SQLCheckButton.vueindex e8247ff8df..8873835f22 100644--- a/frontend/src/components/SQLCheck/SQLCheckButton.vue+++ b/frontend/src/components/SQLCheck/SQLCheckButton.vue@@ -46,6 +46,7 @@<SQLCheckPanelv-if="checkResult && filteredAdvices && showDetailPanel"+ :project="database.project":database="database":advices="filteredAdvices":affected-rows="checkResult.affectedRows"diff --git a/frontend/src/components/SQLCheck/SQLCheckPanel.vue b/frontend/src/components/SQLCheck/SQLCheckPanel.vueindex ab0f50a474..95cabac2d3 100644--- a/frontend/src/components/SQLCheck/SQLCheckPanel.vue+++ b/frontend/src/components/SQLCheck/SQLCheckPanel.vue@@ -76,8 +76,9 @@ import type { Defer } from "@/utils";const props = withDefaults(defineProps<{- database: ComposedDatabase;+ project: string;advices: Advice[];+ database?: ComposedDatabase;affectedRows?: number;riskLevel?: CheckReleaseResponse_RiskLevel;overrideTitle?: string;@@ -134,7 +135,7 @@ watchEffect(async () => {const projectLevelPolicy =await policyV1Store.getOrFetchPolicyByParentAndType({- parentPath: props.database.project,+ parentPath: props.project,policyType: PolicyType.RESTRICT_ISSUE_CREATION_FOR_SQL_REVIEW,});if (projectLevelPolicy?.restrictIssueCreationForSqlReviewPolicy?.disallow) {