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(sql-editor): use more complex function node key for duplicated names (function overloading) (#13550)
Liu Ji242a5292f85c
diff --git a/frontend/src/utils/v1/dbSchema.ts b/frontend/src/utils/v1/dbSchema.tsnew file mode 100644index 0000000000..12aa3bbd34--- /dev/null+++ b/frontend/src/utils/v1/dbSchema.ts@@ -0,0 +1,34 @@+import {+ FunctionMetadata,+ ProcedureMetadata,+} from "@/types/proto/v1/database_service";++export const keyForFunction = (func: FunctionMetadata): string => {+ return JSON.stringify(FunctionMetadata.toJSON(func));+};++export const extractFunction = (key: string) => {+ if (!key) return FunctionMetadata.fromJSON({});+ try {+ const obj = JSON.parse(key);+ const func = FunctionMetadata.fromJSON(obj);+ return func;+ } catch {+ return FunctionMetadata.fromJSON({});+ }+};++export const keyForProcedure = (procedure: ProcedureMetadata): string => {+ return JSON.stringify(ProcedureMetadata.toJSON(procedure));+};++export const extractProcedure = (key: string) => {+ if (!key) return ProcedureMetadata.fromJSON({});+ try {+ const obj = JSON.parse(key);+ const procedure = ProcedureMetadata.fromJSON(obj);+ return procedure;+ } catch {+ return ProcedureMetadata.fromJSON({});+ }+};diff --git a/frontend/src/utils/v1/index.ts b/frontend/src/utils/v1/index.tsindex cb4970f89f..fb03b092b0 100644--- a/frontend/src/utils/v1/index.ts+++ b/frontend/src/utils/v1/index.ts@@ -17,3 +17,4 @@ export * from "./changelist";export * from "./cel";export * from "./advanced-search";export * from "./iam";+export * from "./dbSchema";diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsx b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsxindex 98d81a66b5..8ad275d787 100644--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsx+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsx@@ -43,6 +43,8 @@ import {generateSimpleSelectAllStatement,generateSimpleUpdateStatement,instanceV1HasAlterSchema,+ keyForFunction,+ keyForProcedure,sortByDictionary,toClipboard,} from "@/utils";@@ -266,10 +268,12 @@ export const useActions = () => {detail.view = (target as NodeTarget<"view">).view.name;}if (type === "procedure") {- detail.procedure = (target as NodeTarget<"procedure">).procedure.name;+ detail.procedure = keyForProcedure(+ (target as NodeTarget<"procedure">).procedure+ );}if (type === "function") {- detail.func = (target as NodeTarget<"function">).function.name;+ detail.func = keyForFunction((target as NodeTarget<"function">).function);}if (type === "external-table") {detail.externalTable = (diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/common.ts b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/common.tsindex 7cc1304959..bb5021ded5 100644--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/common.ts+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/common.ts@@ -16,6 +16,7 @@ import type {TablePartitionMetadata,ViewMetadata,} from "@/types/proto/v1/database_service";+import { keyForFunction, keyForProcedure } from "@/utils";export type NodeType =| "database"@@ -218,14 +219,16 @@ export const keyForNodeTarget = <T extends NodeType>(return [db.name,`schemas/${schema.name}`,- `procedures/${procedure.name}`,+ `procedures/${keyForProcedure(procedure)}`,].join("/");}if (type === "function") {const { db, schema, function: func } = target as NodeTarget<"function">;- return [db.name, `schemas/${schema.name}`, `functions/${func.name}`].join(- "/"- );+ return [+ db.name,+ `schemas/${schema.name}`,+ `functions/${keyForFunction(func)}`,+ ].join("/");}if (type === "expandable-text") {const { id } = target as NodeTarget<"expandable-text">;diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/FunctionsPanel/FunctionsPanel.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/FunctionsPanel/FunctionsPanel.vueindex 13676d42a7..be426eef92 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/FunctionsPanel/FunctionsPanel.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/FunctionsPanel/FunctionsPanel.vue@@ -58,6 +58,7 @@ import {FunctionMetadata,SchemaMetadata,} from "@/types/proto/v1/database_service";+import { extractFunction, keyForFunction } from "@/utils";import DatabaseChooser from "@/views/sql-editor/EditorCommon/DatabaseChooser.vue";import { useEditorPanelContext } from "../../context";import { SchemaSelectToolbar, CodeViewer } from "../common";@@ -80,8 +81,9 @@ const metadata = computed(() => {const schema = database.schemas.find((s) => s.name === viewState.value?.schema);+ const target = extractFunction(viewState.value?.detail?.func ?? "");const func = schema?.functions.find(- (f) => f.name === viewState.value?.detail?.func+ (f) => f.name === target.name && f.definition === target.definition);return { database, schema, func };});@@ -92,7 +94,7 @@ const select = (selected: {func: FunctionMetadata;}) => {updateViewState({- detail: { func: selected.func.name },+ detail: { func: keyForFunction(selected.func) },});};diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/FunctionsPanel/FunctionsTable.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/FunctionsPanel/FunctionsTable.vueindex fc3c14b9cf..59ee5b4fff 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/FunctionsPanel/FunctionsTable.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/FunctionsPanel/FunctionsTable.vue@@ -4,7 +4,7 @@v-bind="$attrs"ref="dataTableRef"size="small"- :row-key="(func) => func.name"+ :row-key="(func) => keyForFunction(func)":columns="columns":data="layoutReady ? filteredFuncs : []":row-props="rowProps"@@ -27,7 +27,7 @@ import type {FunctionMetadata,SchemaMetadata,} from "@/types/proto/v1/database_service";-import { getHighlightHTMLByRegExp } from "@/utils";+import { getHighlightHTMLByRegExp, keyForFunction } from "@/utils";import { useAutoHeightDataTable } from "../../common";import { useEditorPanelContext } from "../../context";diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/ProceduresPanel/ProceduresPanel.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/ProceduresPanel/ProceduresPanel.vueindex 031ee6b974..1cedbf984f 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/ProceduresPanel/ProceduresPanel.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/ProceduresPanel/ProceduresPanel.vue@@ -58,6 +58,7 @@ import {ProcedureMetadata,SchemaMetadata,} from "@/types/proto/v1/database_service";+import { extractProcedure, keyForProcedure } from "@/utils";import DatabaseChooser from "@/views/sql-editor/EditorCommon/DatabaseChooser.vue";import { useEditorPanelContext } from "../../context";import { SchemaSelectToolbar, CodeViewer } from "../common";@@ -80,8 +81,9 @@ const metadata = computed(() => {const schema = database.schemas.find((s) => s.name === viewState.value?.schema);- const procedure = schema?.procedures.find(- (p) => p.name === viewState.value?.detail?.procedure+ const target = extractProcedure(viewState.value?.detail?.procedure ?? "");+ const procedure = schema?.functions.find(+ (p) => p.name === target.name && p.definition === target.definition);return { database, schema, procedure };});@@ -92,7 +94,7 @@ const select = (selected: {procedure: ProcedureMetadata;}) => {updateViewState({- detail: { procedure: selected.procedure.name },+ detail: { procedure: keyForProcedure(selected.procedure) },});};diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/ProceduresPanel/ProceduresTable.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/ProceduresPanel/ProceduresTable.vueindex e20b95e6b9..77fce3aee0 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/ProceduresPanel/ProceduresTable.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/ProceduresPanel/ProceduresTable.vue@@ -4,7 +4,7 @@v-bind="$attrs"ref="dataTableRef"size="small"- :row-key="(procedure) => procedure.name"+ :row-key="(procedure) => keyForProcedure(procedure)":columns="columns":data="layoutReady ? filteredProcedures : []":row-props="rowProps"@@ -27,7 +27,7 @@ import type {ProcedureMetadata,SchemaMetadata,} from "@/types/proto/v1/database_service";-import { getHighlightHTMLByRegExp } from "@/utils";+import { getHighlightHTMLByRegExp, keyForProcedure } from "@/utils";import { useAutoHeightDataTable } from "../../common";import { useEditorPanelContext } from "../../context";