Skip to content

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

chore(frontend): specify sheet.engine if possible in CreateSheet (#11931)

Liu Jie96302ce593e
diff --git a/frontend/src/components/Branch/BranchRolloutView/BranchRolloutView.vue b/frontend/src/components/Branch/BranchRolloutView/BranchRolloutView.vue
index a8699de81f..1914198eac 100644
--- a/frontend/src/components/Branch/BranchRolloutView/BranchRolloutView.vue
+++ b/frontend/src/components/Branch/BranchRolloutView/BranchRolloutView.vue
@@ -336,6 +336,7 @@ const handlePreviewIssue = async () => {
}
const sheet = Sheet.fromPartial({
database: db.name,
+ engine: db.instanceEntity.engine,
payload: {
type: SheetPayload_Type.SCHEMA_DESIGN,
baselineDatabaseConfig: {
diff --git a/frontend/src/components/Changelist/ChangelistDashboard/CreateChangelistPanel.vue b/frontend/src/components/Changelist/ChangelistDashboard/CreateChangelistPanel.vue
index ebcee95565..7c160678a1 100644
--- a/frontend/src/components/Changelist/ChangelistDashboard/CreateChangelistPanel.vue
+++ b/frontend/src/components/Changelist/ChangelistDashboard/CreateChangelistPanel.vue
@@ -63,7 +63,9 @@
<template #icon>
<UploadIcon class="w-4 h-4" />
</template>
- {{ $t("changelist.import.optional-upload-sql-or-zip-file") }}
+ {{
+ $t("changelist.import.optional-upload-sql-or-zip-file")
+ }}
</NButton>
</NUploadTrigger>
<div class="flex flex-col gap-1">
@@ -151,6 +153,7 @@ import {
Changelist,
Changelist_Change as Change,
} from "@/types/proto/v1/changelist_service";
+import { Engine } from "@/types/proto/v1/common";
import { Sheet } from "@/types/proto/v1/sheet_service";
import { extractChangelistResourceName, setSheetStatement } from "@/utils";
import { getErrorCode } from "@/utils/grpcweb";
@@ -271,6 +274,7 @@ const doCreate = async () => {
const { name, content } = f;
const sheet = Sheet.fromPartial({
title: name,
+ engine: Engine.ENGINE_UNSPECIFIED, // TODO(jim)
});
setSheetStatement(sheet, content);
const created = await useSheetV1Store().createSheet(
diff --git a/frontend/src/components/Changelist/ChangelistDetail/NavBar/ImportButton.vue b/frontend/src/components/Changelist/ChangelistDetail/NavBar/ImportButton.vue
index a6b6f5d119..1dd20124a0 100644
--- a/frontend/src/components/Changelist/ChangelistDetail/NavBar/ImportButton.vue
+++ b/frontend/src/components/Changelist/ChangelistDetail/NavBar/ImportButton.vue
@@ -41,6 +41,7 @@ import {
Changelist_Change as Change,
Changelist,
} from "@/types/proto/v1/changelist_service";
+import { Engine } from "@/types/proto/v1/common";
import { Sheet } from "@/types/proto/v1/sheet_service";
import { setSheetStatement } from "@/utils";
import { readUpload, type ParsedFile } from "../../import";
@@ -87,6 +88,7 @@ const save = async (files: ParsedFile[]) => {
const { name, content } = f;
const sheet = Sheet.fromPartial({
title: name,
+ engine: Engine.ENGINE_UNSPECIFIED, // TODO(jim)
});
setSheetStatement(sheet, content);
const created = await useSheetV1Store().createSheet(
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 d1f6007af7..1b4f7a9be4 100644
--- a/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vue
+++ b/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vue
@@ -35,6 +35,7 @@ import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import { ErrorList } from "@/components/IssueV1/components/common";
import {
+ databaseEngineForSpec,
databaseForTask,
getLocalSheetByName,
isValidStage,
@@ -176,6 +177,11 @@ const createSheets = async () => {
// The sheet is pending create
const sheet = getLocalSheetByName(config.sheet);
sheet.database = config.target;
+ const engine = await databaseEngineForSpec(
+ issue.value.projectEntity,
+ spec
+ );
+ sheet.engine = engine;
pendingCreateSheetMap.set(sheet.name, sheet);
await maybeFormatSQL(sheet, sheet.database);
diff --git a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
index 1529490147..8bf991ed84 100644
--- a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
+++ b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
@@ -216,7 +216,7 @@
<script setup lang="ts">
import { useElementSize } from "@vueuse/core";
-import { cloneDeep } from "lodash-es";
+import { cloneDeep, head } from "lodash-es";
import { ExpandIcon } from "lucide-vue-next";
import { NButton, NTooltip, useDialog } from "naive-ui";
import { v1 as uuidv1 } from "uuid";
@@ -236,6 +236,7 @@ import {
notifyNotEditableLegacyIssue,
isDeploymentConfigChangeTaskV1,
isGroupingChangeTaskV1,
+ databaseEngineForSpec,
} from "@/components/IssueV1/logic";
import { MonacoEditor } from "@/components/MonacoEditor";
import { extensionNameOfLanguage } from "@/components/MonacoEditor/utils";
@@ -254,6 +255,7 @@ import { TaskTypeListWithStatement, dialectOfEngineV1 } from "@/types";
import { TenantMode } from "@/types/proto/v1/project_service";
import type { Plan_Spec, 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 {
defer,
flattenTaskV1List,
@@ -679,10 +681,11 @@ const updateStatement = async (statement: string) => {
.flatMap((step) => step.specs)
.filter((spec) => distinctSpecIds.has(spec.id));
- const sheet = {
+ const sheet = Sheet.fromPartial({
...createEmptyLocalSheet(),
title: issue.value.title,
- };
+ engine: await databaseEngineForSpec(project.value, head(specsToPatch)),
+ });
setSheetStatement(sheet, statement);
const createdSheet = await useSheetV1Store().createSheet(
issue.value.project,
diff --git a/frontend/src/components/IssueV1/logic/initialize/create.ts b/frontend/src/components/IssueV1/logic/initialize/create.ts
index f85e3b4fb7..fdd068567b 100644
--- a/frontend/src/components/IssueV1/logic/initialize/create.ts
+++ b/frontend/src/components/IssueV1/logic/initialize/create.ts
@@ -29,7 +29,7 @@ import {
Rollout,
Task_Type,
} from "@/types/proto/v1/rollout_service";
-import { SheetPayload } from "@/types/proto/v1/sheet_service";
+import { Sheet, SheetPayload } from "@/types/proto/v1/sheet_service";
import {
extractProjectResourceName,
extractSheetUID,
@@ -41,7 +41,7 @@ import {
sheetNameOfTaskV1,
} from "@/utils";
import { nextUID } from "../base";
-import { sheetNameForSpec } from "../plan";
+import { databaseEngineForSpec, sheetNameForSpec } from "../plan";
import { createEmptyLocalSheet, getLocalSheetByName } from "../sheet";
export type InitialSQL = {
@@ -213,9 +213,10 @@ export const buildStepsForDatabaseGroup = async (
// Create sheet from SQL template in URL query
// The sheet will be used when previewing rollout
const sql = params.initialSQL.sql ?? "";
- const sheetCreate = {
+ const sheetCreate = Sheet.fromPartial({
...createEmptyLocalSheet(),
- };
+ engine: await databaseEngineForSpec(params.project, databaseGroupName),
+ });
setSheetStatement(sheetCreate, sql);
const sheet = await useSheetV1Store().createSheet(
params.project.name,
diff --git a/frontend/src/components/IssueV1/logic/plan.ts b/frontend/src/components/IssueV1/logic/plan.ts
index a9eb6fd23c..207c15ae28 100644
--- a/frontend/src/components/IssueV1/logic/plan.ts
+++ b/frontend/src/components/IssueV1/logic/plan.ts
@@ -1,4 +1,18 @@
+import { head } from "lodash-es";
+import {
+ useDatabaseV1Store,
+ useDBGroupStore,
+ useDeploymentConfigV1Store,
+} from "@/store";
+import { type ComposedProject, UNKNOWN_ID } from "@/types";
+import { Engine } from "@/types/proto/v1/common";
import type { Plan_Spec } from "@/types/proto/v1/rollout_service";
+import {
+ extractDatabaseResourceName,
+ extractDatabaseGroupName,
+ extractDeploymentConfigName,
+ getPipelineFromDeploymentScheduleV1,
+} from "@/utils";
/**
*
@@ -7,3 +21,67 @@ import type { Plan_Spec } from "@/types/proto/v1/rollout_service";
export const sheetNameForSpec = (spec: Plan_Spec): string => {
return spec.changeDatabaseConfig?.sheet ?? spec.exportDataConfig?.sheet ?? "";
};
+
+export const databaseEngineForSpec = async (
+ project: ComposedProject,
+ specOrTarget?: Plan_Spec | string
+) => {
+ if (!specOrTarget) return Engine.ENGINE_UNSPECIFIED;
+
+ const getTarget = (specOrTarget: Plan_Spec | string) => {
+ if (typeof specOrTarget === "string") {
+ return specOrTarget;
+ }
+ const config =
+ specOrTarget.changeDatabaseConfig || specOrTarget.exportDataConfig;
+ if (!config) {
+ return Engine.ENGINE_UNSPECIFIED;
+ }
+ return config.target;
+ };
+ const target = getTarget(specOrTarget);
+
+ if (extractDatabaseResourceName(target).databaseName !== String(UNKNOWN_ID)) {
+ const db = await useDatabaseV1Store().getOrFetchDatabaseByName(
+ target,
+ /* silent */ true
+ );
+ if (db && db.uid !== String(UNKNOWN_ID)) {
+ return db.instanceEntity.engine;
+ }
+ }
+ if (extractDatabaseGroupName(target)) {
+ const dbGroup = await useDBGroupStore().getOrFetchDBGroupByName(target);
+ // Might be flaky: use the first database in the db group
+ const dbName = head(dbGroup.matchedDatabases)?.name;
+ if (dbName) {
+ const db = await useDatabaseV1Store().getOrFetchDatabaseByName(
+ dbName,
+ /* silent */ true
+ );
+ if (db && db.uid !== String(UNKNOWN_ID)) {
+ return db.instanceEntity.engine;
+ }
+ }
+ }
+ if (extractDeploymentConfigName(target)) {
+ const deploymentConfig =
+ await useDeploymentConfigV1Store().fetchDeploymentConfigByProjectName(
+ project.name
+ );
+ if (deploymentConfig) {
+ const databaseList = useDatabaseV1Store().databaseListByProject(
+ project.name
+ );
+ const pipeline = getPipelineFromDeploymentScheduleV1(
+ databaseList,
+ deploymentConfig.schedule
+ );
+ const db = head(head(pipeline));
+ if (db && db.uid !== String(UNKNOWN_ID)) {
+ return db.instanceEntity.engine;
+ }
+ }
+ }
+ return Engine.ENGINE_UNSPECIFIED;
+};
diff --git a/frontend/src/components/SyncDatabaseSchema/RawSQLEditor.vue b/frontend/src/components/SyncDatabaseSchema/RawSQLEditor.vue
index c7d38cba71..73618ce065 100644
--- a/frontend/src/components/SyncDatabaseSchema/RawSQLEditor.vue
+++ b/frontend/src/components/SyncDatabaseSchema/RawSQLEditor.vue
@@ -174,6 +174,7 @@ const handleSQLUpload = async (statement: string, filename: string) => {
try {
const sheet = await sheetStore.createSheet(DEFAULT_PROJECT_V1_NAME, {
title: filename,
+ engine: state.engine,
content: new TextEncoder().encode(statement),
});
const sheetId = Number(extractSheetUID(sheet.name));
diff --git a/frontend/src/store/modules/v1/sheet.ts b/frontend/src/store/modules/v1/sheet.ts
index 55b13d403f..84910c88dc 100644
--- a/frontend/src/store/modules/v1/sheet.ts
+++ b/frontend/src/store/modules/v1/sheet.ts
@@ -4,6 +4,7 @@ import { sheetServiceClient } from "@/grpcweb";
import { useCache } from "@/store/cache";
import type { MaybeRef } from "@/types";
import { UNKNOWN_ID } from "@/types";
+import { Engine, engineToJSON } from "@/types/proto/v1/common";
import type { Sheet } from "@/types/proto/v1/sheet_service";
import { extractSheetUID, getSheetStatement } from "@/utils";
@@ -34,6 +35,16 @@ export const useSheetV1Store = defineStore("sheet_v1", () => {
// CRUD
const createSheet = async (parent: string, sheet: Partial<Sheet>) => {
+ if (!sheet.engine || sheet.engine === Engine.ENGINE_UNSPECIFIED) {
+ const engineStr = sheet.engine
+ ? engineToJSON(sheet.engine)
+ : "<undefined>";
+ console.warn(
+ `[SheetService.CreateSheet] sheet.engine unspecified: ${engineStr}`
+ );
+
+ sheet.engine = Engine.ENGINE_UNSPECIFIED;
+ }
const created = await sheetServiceClient.createSheet({
parent,
sheet,