Skip to content

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

feat: provide SQL advice markers while previewing issue (#12463)

Liu Jiee0042883784
diff --git a/frontend/src/components/IssueV1/IssueDetailPage.vue b/frontend/src/components/IssueV1/IssueDetailPage.vue
index 5ca3f31e0c..48ded7ad38 100644
--- a/frontend/src/components/IssueV1/IssueDetailPage.vue
+++ b/frontend/src/components/IssueV1/IssueDetailPage.vue
@@ -16,10 +16,10 @@
<TaskRunSection v-if="!isCreating" />
- <SQLCheckSection v-if="isCreating" />
+ <SQLCheckSection v-if="isCreating" @update:advices="advices = $event" />
<PlanCheckSection v-if="!isCreating" />
- <StatementSection />
+ <StatementSection :advices="advices" />
<DescriptionSection />
@@ -76,6 +76,7 @@
<script setup lang="ts">
import { ref } from "vue";
import type { Task } from "@/types/proto/v1/rollout_service";
+import type { Advice } from "@/types/proto/v1/sql_service";
import { provideSQLCheckContext } from "../SQLCheck";
import { Drawer } from "../v2";
import {
@@ -107,6 +108,7 @@ import {
const containerRef = ref<HTMLElement>();
const { isCreating, phase, issue, events } = useIssueContext();
+const advices = ref<Advice[]>();
const ongoingIssueReviewAction = ref<{
action: IssueReviewAction;
diff --git a/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckSection.vue b/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckSection.vue
index a84caaecc4..5a88f18acb 100644
--- a/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckSection.vue
+++ b/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckSection.vue
@@ -15,6 +15,7 @@
}"
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">
@@ -48,12 +49,16 @@ import { SQLCheckButton } from "@/components/SQLCheck";
import { TaskTypeListWithStatement } from "@/types";
import { Plan_ChangeDatabaseConfig_Type } from "@/types/proto/v1/plan_service";
import { Task_Type } from "@/types/proto/v1/rollout_service";
-import { CheckRequest_ChangeType } from "@/types/proto/v1/sql_service";
+import { Advice, CheckRequest_ChangeType } from "@/types/proto/v1/sql_service";
import type { Defer } from "@/utils/util";
import { useTaskSheet } from "../StatementSection/useTaskSheet";
import OnlineMigrationAdviceExtra from "./OnlineMigrationAdviceExtra.vue";
import SQLCheckBadge from "./SQLCheckBadge.vue";
+defineEmits<{
+ (event: "update:advices", advices: Advice[] | undefined): void;
+}>();
+
const { issue, selectedTask, selectedSpec, events } = useIssueContext();
const { sheetStatement } = useTaskSheet();
diff --git a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
index b74ce7188f..7de184ac7b 100644
--- a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
+++ b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
@@ -127,7 +127,7 @@
:auto-focus="false"
:readonly="isEditorReadonly"
:dialect="dialect"
- :advices="isEditorReadonly ? markers : []"
+ :advices="isEditorReadonly || isCreating ? markers : []"
:auto-height="{ min: 120, max: 240 }"
:auto-complete-context="{
instance: database.instance,
@@ -176,7 +176,7 @@
:auto-focus="false"
:readonly="isEditorReadonly"
:dialect="dialect"
- :advices="isEditorReadonly ? markers : []"
+ :advices="isEditorReadonly || isCreating ? markers : []"
:auto-complete-context="{
instance: database.instance,
database: database.name,
@@ -211,7 +211,7 @@ import { cloneDeep, head, uniq } 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, watch } from "vue";
+import { computed, h, reactive, ref, toRef, watch } from "vue";
import { useI18n } from "vue-i18n";
import { useRoute } from "vue-router";
import { ErrorList } from "@/components/IssueV1/components/common";
@@ -251,6 +251,7 @@ import { IssueStatus } from "@/types/proto/v1/issue_service";
import type { Task } from "@/types/proto/v1/rollout_service";
import { Task_Type } from "@/types/proto/v1/rollout_service";
import { Sheet } from "@/types/proto/v1/sheet_service";
+import type { Advice } from "@/types/proto/v1/sql_service";
import {
defer,
flattenTaskV1List,
@@ -271,11 +272,16 @@ type LocalState = EditState & {
isUploadingFile: boolean;
};
+const props = defineProps<{
+ advices?: Advice[];
+}>();
+
const { t } = useI18n();
const route = useRoute();
const currentUser = useCurrentUserV1();
+const context = useIssueContext();
const { events, isCreating, issue, selectedTask, selectedSpec, formatOnSave } =
- useIssueContext();
+ context;
const project = computed(() => issue.value.projectEntity);
const dialog = useDialog();
const editorContainerElRef = ref<HTMLElement>();
@@ -313,7 +319,7 @@ const dialect = computed((): SQLDialect => {
const statementTitle = computed(() => {
return language.value === "sql" ? t("common.sql") : t("common.statement");
});
-const { markers } = useSQLAdviceMarkers();
+const { markers } = useSQLAdviceMarkers(context, toRef(props, "advices"));
const allowEditStatementWhenCreating = computed(() => {
if (route.query.sheetId) {
diff --git a/frontend/src/components/IssueV1/components/StatementSection/SDLView/SDLView.vue b/frontend/src/components/IssueV1/components/StatementSection/SDLView/SDLView.vue
index 01aaffcb25..762d72b5d7 100644
--- a/frontend/src/components/IssueV1/components/StatementSection/SDLView/SDLView.vue
+++ b/frontend/src/components/IssueV1/components/StatementSection/SDLView/SDLView.vue
@@ -96,6 +96,7 @@
<script lang="ts" setup>
import { NTabs, NTab, NTooltip } from "naive-ui";
import { reactive } from "vue";
+import { useIssueContext } from "@/components/IssueV1/logic";
import LearnMoreLink from "@/components/LearnMoreLink.vue";
import { DiffEditor, MonacoEditor } from "@/components/MonacoEditor";
import { hasFeature, pushNotification } from "@/store";
@@ -115,8 +116,9 @@ const state = reactive<LocalState>({
});
const { state: sdlState, events: sdlEvents } = useSDLState();
+const context = useIssueContext();
-const { markers } = useSQLAdviceMarkers();
+const { markers } = useSQLAdviceMarkers(context, undefined);
sdlEvents.on("error", ({ message }) => {
state.tab = "SCHEMA";
diff --git a/frontend/src/components/IssueV1/components/StatementSection/StatementSection.vue b/frontend/src/components/IssueV1/components/StatementSection/StatementSection.vue
index 8aa81192bf..9456547d83 100644
--- a/frontend/src/components/IssueV1/components/StatementSection/StatementSection.vue
+++ b/frontend/src/components/IssueV1/components/StatementSection/StatementSection.vue
@@ -1,6 +1,10 @@
<template>
<div v-if="viewMode !== 'NONE'" class="px-4 py-2 flex flex-col gap-y-2">
- <EditorView v-if="viewMode === 'EDITOR'" ref="editorViewRef" />
+ <EditorView
+ v-if="viewMode === 'EDITOR'"
+ ref="editorViewRef"
+ :advices="advices"
+ />
<SDLView v-if="viewMode === 'SDL'" />
</div>
</template>
@@ -12,10 +16,15 @@ import { nextTick } from "vue";
import { useRouter } from "vue-router";
import { EMPTY_ID, TaskTypeListWithStatement } from "@/types";
import { Task_Type } from "@/types/proto/v1/rollout_service";
+import type { Advice } from "@/types/proto/v1/sql_service";
import { useIssueContext } from "../../logic";
import EditorView from "./EditorView";
import SDLView from "./SDLView";
+defineProps<{
+ advices?: Advice[];
+}>();
+
const { isCreating, selectedTask, selectedSpec } = useIssueContext();
const editorViewRef = ref<InstanceType<typeof EditorView>>();
diff --git a/frontend/src/components/IssueV1/components/StatementSection/useSQLAdviceMarkers.ts b/frontend/src/components/IssueV1/components/StatementSection/useSQLAdviceMarkers.ts
index 9ccb7346a1..e79951027a 100644
--- a/frontend/src/components/IssueV1/components/StatementSection/useSQLAdviceMarkers.ts
+++ b/frontend/src/components/IssueV1/components/StatementSection/useSQLAdviceMarkers.ts
@@ -1,29 +1,54 @@
import { maxBy } from "lodash-es";
-import { computed } from "vue";
+import { computed, type Ref } from "vue";
import type { AdviceOption } from "@/components/MonacoEditor";
import {
PlanCheckRun,
PlanCheckRun_Result_Status,
PlanCheckRun_Type,
} from "@/types/proto/v1/plan_service";
-import { planCheckRunListForTask, useIssueContext } from "../../logic";
+import { Advice_Status, type Advice } from "@/types/proto/v1/sql_service";
+import { planCheckRunListForTask, type IssueContext } from "../../logic";
-export const useSQLAdviceMarkers = () => {
- const { isCreating, issue, selectedTask } = useIssueContext();
+export const useSQLAdviceMarkers = (
+ context: IssueContext,
+ advices: Ref<Advice[] | undefined> | undefined
+) => {
+ const { isCreating } = context;
const markers = computed(() => {
- if (isCreating.value) return [];
+ if (isCreating.value) {
+ if (!advices) return [];
+ if (!advices.value) return [];
+ return advices.value.map<AdviceOption>((advice) => {
+ const line = advice.line;
+ const column = advice.column ?? Number.MAX_SAFE_INTEGER;
+ const code = advice.code;
+ return {
+ severity: advice.status === Advice_Status.ERROR ? "ERROR" : "WARNING",
+ message: advice.content,
+ source: `${advice.title} (${code}) L${line}:C${column}`,
+ startLineNumber: line,
+ endLineNumber: line,
+ startColumn: column,
+ endColumn: column,
+ };
+ });
+ } else {
+ const { issue, selectedTask } = context;
- const task = selectedTask.value;
- const planCheckRunList = planCheckRunListForTask(issue.value, task);
-
- const types: PlanCheckRun_Type[] = [
- PlanCheckRun_Type.DATABASE_STATEMENT_ADVISE,
- ];
- return types.flatMap((type) => {
- return getLatestAdviceOptions(
- planCheckRunList.filter((checkRun) => checkRun.type === type)
+ const planCheckRunList = planCheckRunListForTask(
+ issue.value,
+ selectedTask.value
);
- });
+
+ const types: PlanCheckRun_Type[] = [
+ PlanCheckRun_Type.DATABASE_STATEMENT_ADVISE,
+ ];
+ return types.flatMap((type) => {
+ return getLatestAdviceOptions(
+ planCheckRunList.filter((checkRun) => checkRun.type === type)
+ );
+ });
+ }
});
return { markers };
};
diff --git a/frontend/src/components/Plan/PlanDetailPage.vue b/frontend/src/components/Plan/PlanDetailPage.vue
index c08363af61..18285f17f7 100644
--- a/frontend/src/components/Plan/PlanDetailPage.vue
+++ b/frontend/src/components/Plan/PlanDetailPage.vue
@@ -10,10 +10,10 @@
<StepSection />
<SpecListSection />
- <SQLCheckSection v-if="isCreating" />
+ <SQLCheckSection v-if="isCreating" @update:advices="advices = $event" />
<PlanCheckSection v-if="!isCreating" />
- <StatementSection />
+ <StatementSection :advices="advices" />
<DescriptionSection />
</div>
</div>
@@ -21,9 +21,10 @@
</template>
<script setup lang="ts">
-import { onMounted } from "vue";
+import { onMounted, ref } from "vue";
import { useRouter } from "vue-router";
import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";
+import type { Advice } from "@/types/proto/v1/sql_service";
import {
extractIssueUID,
extractProjectResourceName,
@@ -43,6 +44,7 @@ import { usePlanContext, usePollPlan } from "./logic";
const router = useRouter();
const { isCreating, plan } = usePlanContext();
+const advices = ref<Advice[]>();
usePollPlan();
diff --git a/frontend/src/components/Plan/components/SQLCheckSection/SQLCheckSection.vue b/frontend/src/components/Plan/components/SQLCheckSection/SQLCheckSection.vue
index 01a3146e45..9aceb7a1ae 100644
--- a/frontend/src/components/Plan/components/SQLCheckSection/SQLCheckSection.vue
+++ b/frontend/src/components/Plan/components/SQLCheckSection/SQLCheckSection.vue
@@ -15,6 +15,7 @@
}"
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">
@@ -33,11 +34,15 @@ 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 { CheckRequest_ChangeType } from "@/types/proto/v1/sql_service";
+import { Advice, CheckRequest_ChangeType } 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();
diff --git a/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue b/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue
index 85dfad690d..9946bdd044 100644
--- a/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue
+++ b/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue
@@ -122,7 +122,7 @@
:auto-focus="false"
:readonly="isEditorReadonly"
:dialect="dialect"
- :advices="isEditorReadonly ? markers : []"
+ :advices="isEditorReadonly || isCreating ? markers : []"
:auto-height="{ min: 120, max: 240 }"
:auto-complete-context="{
instance: database.instance,
@@ -171,7 +171,7 @@
:auto-focus="false"
:readonly="isEditorReadonly"
:dialect="dialect"
- :advices="isEditorReadonly ? markers : []"
+ :advices="isEditorReadonly || isCreating ? markers : []"
:auto-complete-context="{
instance: database.instance,
database: database.name,
@@ -194,7 +194,7 @@ import { cloneDeep, head, uniq } 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, watch } from "vue";
+import { computed, h, reactive, ref, toRef, watch } from "vue";
import { useI18n } from "vue-i18n";
import { MonacoEditor } from "@/components/MonacoEditor";
import { extensionNameOfLanguage } from "@/components/MonacoEditor/utils";
@@ -216,6 +216,7 @@ 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,
@@ -235,7 +236,12 @@ type LocalState = EditState & {
isUploadingFile: boolean;
};
+const props = defineProps<{
+ advices?: Advice[];
+}>();
+
const { t } = useI18n();
+const context = usePlanContext();
const { isCreating, plan, selectedSpec, formatOnSave, events } =
usePlanContext();
const project = computed(() => plan.value.projectEntity);
@@ -271,7 +277,7 @@ const dialect = computed((): SQLDialect => {
const statementTitle = computed(() => {
return language.value === "sql" ? t("common.sql") : t("common.statement");
});
-const { markers } = useSQLAdviceMarkers();
+const { markers } = useSQLAdviceMarkers(context, toRef(props, "advices"));
/**
* to set the MonacoEditor as readonly
diff --git a/frontend/src/components/Plan/components/StatementSection/StatementSection.vue b/frontend/src/components/Plan/components/StatementSection/StatementSection.vue
index 3165d2a6b3..682526f37b 100644
--- a/frontend/src/components/Plan/components/StatementSection/StatementSection.vue
+++ b/frontend/src/components/Plan/components/StatementSection/StatementSection.vue
@@ -1,6 +1,6 @@
<template>
<div v-if="viewMode !== 'NONE'" class="px-4 py-2 flex flex-col gap-y-2">
- <EditorView ref="editorViewRef" />
+ <EditorView ref="editorViewRef" :advices="advices" />
</div>
</template>
@@ -10,9 +10,14 @@ 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 EditorView from "./EditorView";
+defineProps<{
+ advices?: Advice[];
+}>();
+
const { selectedSpec } = usePlanContext();
const editorViewRef = ref<InstanceType<typeof EditorView>>();
diff --git a/frontend/src/components/Plan/components/StatementSection/useSQLAdviceMarkers.ts b/frontend/src/components/Plan/components/StatementSection/useSQLAdviceMarkers.ts
index 86722934ba..28dec86948 100644
--- a/frontend/src/components/Plan/components/StatementSection/useSQLAdviceMarkers.ts
+++ b/frontend/src/components/Plan/components/StatementSection/useSQLAdviceMarkers.ts
@@ -1,30 +1,52 @@
import { maxBy } from "lodash-es";
-import { computed } from "vue";
+import { computed, type Ref } from "vue";
import type { AdviceOption } from "@/components/MonacoEditor";
import {
PlanCheckRun,
PlanCheckRun_Result_Status,
PlanCheckRun_Type,
} from "@/types/proto/v1/plan_service";
-import { planCheckRunListForSpec, usePlanContext } from "../../logic";
+import { Advice_Status, type Advice } from "@/types/proto/v1/sql_service";
+import { planCheckRunListForSpec, type PlanContext } from "../../logic";
-export const useSQLAdviceMarkers = () => {
- const { isCreating, plan, selectedSpec } = usePlanContext();
+export const useSQLAdviceMarkers = (
+ context: PlanContext,
+ advices: Ref<Advice[] | undefined> | undefined
+) => {
+ const { isCreating } = context;
const markers = computed(() => {
- if (isCreating.value) return [];
-
- const planCheckRunList = planCheckRunListForSpec(
- plan.value,
- selectedSpec.value
- );
- const types: PlanCheckRun_Type[] = [
- PlanCheckRun_Type.DATABASE_STATEMENT_ADVISE,
- ];
- return types.flatMap((type) => {
- return getLatestAdviceOptions(
- planCheckRunList.filter((checkRun) => checkRun.type === type)
+ if (isCreating.value) {
+ if (!advices) return [];
+ if (!advices.value) return [];
+ return advices.value.map<AdviceOption>((advice) => {
+ const line = advice.line;
+ const column = advice.column ?? Number.MAX_SAFE_INTEGER;
+ const code = advice.code;
+ return {
+ severity: advice.status === Advice_Status.ERROR ? "ERROR" : "WARNING",
+ message: advice.content,
+ source: `${advice.title} (${code}) L${line}:C${column}`,
+ startLineNumber: line,
+ endLineNumber: line,
+ startColumn: column,
+ endColumn: column,
+ };
+ });
+ } else {
+ const { plan, selectedSpec } = context;
+ const planCheckRunList = planCheckRunListForSpec(
+ plan.value,
+ selectedSpec.value
);
- });
+ const types: PlanCheckRun_Type[] = [
+ PlanCheckRun_Type.DATABASE_STATEMENT_ADVISE,
+ ];
+ return types.flatMap((type) => {
+ return getLatestAdviceOptions(
+ planCheckRunList.filter((checkRun) => checkRun.type === type)
+ );
+ });
+ }
});
return { markers };
};
diff --git a/frontend/src/components/SQLCheck/SQLCheckButton.vue b/frontend/src/components/SQLCheck/SQLCheckButton.vue
index 1efface184..1999615b52 100644
--- a/frontend/src/components/SQLCheck/SQLCheckButton.vue
+++ b/frontend/src/components/SQLCheck/SQLCheckButton.vue
@@ -73,7 +73,7 @@
import { computedAsync } from "@vueuse/core";
import type { ButtonProps } from "naive-ui";
import { NButton, NPopover } from "naive-ui";
-import { computed, onUnmounted, ref } from "vue";
+import { computed, onUnmounted, ref, watch } from "vue";
import { onMounted } from "vue";
import { useI18n } from "vue-i18n";
import { sqlServiceClient } from "@/grpcweb";
@@ -106,6 +106,10 @@ const props = withDefaults(
}
);
+const emit = defineEmits<{
+ (event: "update:advices", advices: Advice[] | undefined): void;
+}>();
+
const { t } = useI18n();
const currentUser = useCurrentUserV1();
// SKIP_CHECK_THRESHOLD is the MaxSheetCheckSize in the backend.
@@ -243,4 +247,8 @@ onUnmounted(() => {
if (!context) return;
context.runSQLCheck.value = undefined;
});
+
+watch(advices, (advices) => {
+ emit("update:advices", advices);
+});
</script>
diff --git a/frontend/src/components/SQLCheck/SQLCheckPanel.vue b/frontend/src/components/SQLCheck/SQLCheckPanel.vue
index 34229fefed..74104bba38 100644
--- a/frontend/src/components/SQLCheck/SQLCheckPanel.vue
+++ b/frontend/src/components/SQLCheck/SQLCheckPanel.vue
@@ -12,6 +12,7 @@
:plan-check-run="planCheckRun"
:environment="environment"
:is-latest="true"
+ @close="$emit('close')"
>
<template #row-extra="{ row }">
<slot name="row-extra" :row="row" />