Skip to content

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

chore: support spanner "Default" schema (#14528)

Liu Ji294695eb971b
diff --git a/frontend/src/components/Database/DatabaseOverviewPanel.vue b/frontend/src/components/Database/DatabaseOverviewPanel.vue
index 6cfec5c128..8066818f09 100644
--- a/frontend/src/components/Database/DatabaseOverviewPanel.vue
+++ b/frontend/src/components/Database/DatabaseOverviewPanel.vue
@@ -183,6 +183,7 @@ import { head } from "lodash-es";
import { NSelect } from "naive-ui";
import type { PropType } from "vue";
import { computed, reactive, watch } from "vue";
+import { useI18n } from "vue-i18n";
import { useRoute, useRouter } from "vue-router";
import type { BBTableSectionDataSource } from "@/bbkit/types";
import AnomalyTable from "@/components/AnomalyCenter/AnomalyTable.vue";
@@ -228,6 +229,8 @@ const props = defineProps({
type: Object as PropType<Anomaly[]>,
},
});
+
+const { t } = useI18n();
const route = useRoute();
const router = useRouter();
const state = reactive<LocalState>({
@@ -296,7 +299,7 @@ const schemaList = computed(() => {
const schemaNameOptions = computed(() => {
return schemaList.value.map((schema) => ({
value: schema.name,
- label: schema.name,
+ label: schema.name || t("db.schema.default"),
}));
});
diff --git a/frontend/src/components/FunctionDataTable.vue b/frontend/src/components/FunctionDataTable.vue
index 9cbe948413..d3a67e3be1 100644
--- a/frontend/src/components/FunctionDataTable.vue
+++ b/frontend/src/components/FunctionDataTable.vue
@@ -49,7 +49,7 @@ const columns = computed(() => {
tooltip: true,
},
render: () => {
- return props.schemaName;
+ return props.schemaName || t("db.schema.default");
},
},
{
diff --git a/frontend/src/components/MonacoEditor/composables/useAutoComplete.ts b/frontend/src/components/MonacoEditor/composables/useAutoComplete.ts
index d215015407..45d7096660 100644
--- a/frontend/src/components/MonacoEditor/composables/useAutoComplete.ts
+++ b/frontend/src/components/MonacoEditor/composables/useAutoComplete.ts
@@ -48,7 +48,7 @@ export const useAutoComplete = async (
if (databaseName && databaseName !== String(UNKNOWN_ID)) {
p.databaseName = databaseName;
}
- if (ctx.schema) {
+ if (ctx.schema !== undefined) {
p.schema = ctx.schema;
}
}
diff --git a/frontend/src/components/PackageDataTable.vue b/frontend/src/components/PackageDataTable.vue
index 3fd238e3a8..0d4d3ef0c4 100644
--- a/frontend/src/components/PackageDataTable.vue
+++ b/frontend/src/components/PackageDataTable.vue
@@ -64,7 +64,7 @@ const columns = computed(() => {
});
const getPackageName = (packageName: string) => {
- if (hasSchemaProperty(engine.value)) {
+ if (hasSchemaProperty(engine.value) && props.schemaName) {
return `"${props.schemaName}"."${packageName}"`;
}
return packageName;
diff --git a/frontend/src/components/SchemaDiagram/Navigator/TreeNode/Label.vue b/frontend/src/components/SchemaDiagram/Navigator/TreeNode/Label.vue
index 51bd5d4cbf..bd50fae99a 100644
--- a/frontend/src/components/SchemaDiagram/Navigator/TreeNode/Label.vue
+++ b/frontend/src/components/SchemaDiagram/Navigator/TreeNode/Label.vue
@@ -15,6 +15,7 @@
<script lang="ts" setup>
import { escape } from "lodash-es";
import { computed } from "vue";
+import { useI18n } from "vue-i18n";
import { getHighlightHTMLByKeyWords } from "@/utils";
import type { TreeNode } from "../types";
import { isTypedNode } from "../utils";
@@ -24,6 +25,8 @@ const props = defineProps<{
keyword: string;
}>();
+const { t } = useI18n();
+
// render an unique id for every node
// for auto scroll to the node when tab switches
const id = computed(() => {
@@ -33,7 +36,7 @@ const id = computed(() => {
const text = computed(() => {
const { node } = props;
- return node.data.name;
+ return node.data.name || t("db.schema.default");
});
const html = computed(() => {
diff --git a/frontend/src/components/SchemaEditorLite/spec.ts b/frontend/src/components/SchemaEditorLite/spec.ts
index d19083b5c1..714ceba57c 100644
--- a/frontend/src/components/SchemaEditorLite/spec.ts
+++ b/frontend/src/components/SchemaEditorLite/spec.ts
@@ -1,4 +1,5 @@
import { Engine } from "@/types/proto/v1/common";
+import { hasSchemaProperty } from "@/utils";
export const engineSupportsEditIndexes = (engine: Engine) => {
return [Engine.MYSQL, Engine.TIDB].includes(engine);
@@ -21,5 +22,5 @@ export const engineSupportsEditFunctions = (engine: Engine) => {
};
export const engineSupportsMultiSchema = (engine: Engine) => {
- return [Engine.POSTGRES].includes(engine);
+ return hasSchemaProperty(engine);
};
diff --git a/frontend/src/components/TableDataTable.vue b/frontend/src/components/TableDataTable.vue
index e19891d33e..a56424a027 100644
--- a/frontend/src/components/TableDataTable.vue
+++ b/frontend/src/components/TableDataTable.vue
@@ -135,7 +135,7 @@ const columns = computed(() => {
tooltip: true,
},
render: () => {
- return props.schemaName;
+ return props.schemaName || t("db.schema.default");
},
},
{
diff --git a/frontend/src/components/TableDetailDrawer.vue b/frontend/src/components/TableDetailDrawer.vue
index ecadb276de..7456dbb106 100644
--- a/frontend/src/components/TableDetailDrawer.vue
+++ b/frontend/src/components/TableDetailDrawer.vue
@@ -358,7 +358,7 @@ const shouldShowColumnTable = computed(() => {
});
const getTableName = (tableName: string) => {
- if (hasSchemaProperty(instanceEngine.value)) {
+ if (hasSchemaProperty(instanceEngine.value) && props.schemaName) {
return `"${props.schemaName}"."${tableName}"`;
}
return tableName;
diff --git a/frontend/src/components/ViewDataTable.vue b/frontend/src/components/ViewDataTable.vue
index ba20a80609..a26b985732 100644
--- a/frontend/src/components/ViewDataTable.vue
+++ b/frontend/src/components/ViewDataTable.vue
@@ -68,7 +68,7 @@ const columns = computed(() => {
});
const getViewName = (viewName: string) => {
- if (hasSchemaProperty(engine.value)) {
+ if (hasSchemaProperty(engine.value) && props.schemaName) {
return `"${props.schemaName}"."${viewName}"`;
}
return viewName;
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 8fd852cc72..e658bce26c 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1445,6 +1445,9 @@
"timing": "Timing",
"event": "Event",
"table-name": "Table name"
+ },
+ "schema": {
+ "default": "Default"
}
},
"instance": {
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 35d81ce56a..f86cf02696 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -1445,6 +1445,9 @@
"timing": "Momento",
"event": "Evento",
"table-name": "Nombre de la tabla"
+ },
+ "schema": {
+ "default": "Por defecto"
}
},
"instance": {
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index dd5c0dcb4b..863921ea57 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -1445,6 +1445,9 @@
"timing": "タイミング",
"event": "イベント",
"table-name": "テーブル名"
+ },
+ "schema": {
+ "default": "デフォルト"
}
},
"instance": {
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 354057b376..01208c54eb 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1445,6 +1445,9 @@
"timing": "时机",
"event": "事件",
"table-name": "表名"
+ },
+ "schema": {
+ "default": "默认"
}
},
"instance": {
diff --git a/frontend/src/types/sqlEditor/editor.ts b/frontend/src/types/sqlEditor/editor.ts
index 0a1831df9f..3d4d1dee7c 100644
--- a/frontend/src/types/sqlEditor/editor.ts
+++ b/frontend/src/types/sqlEditor/editor.ts
@@ -67,6 +67,8 @@ export interface SQLEditorConnection {
table?: string;
}
+export const SQLEditorTabConnectionSchemaUnspecified = "-1";
+
export type SQLEditorQueryParams = {
connection: SQLEditorConnection; // the connection snapshot of the query
statement: string; // the statement snapshot of the query
diff --git a/frontend/src/utils/v1/instance.ts b/frontend/src/utils/v1/instance.ts
index 9cb72353c8..17dae23cae 100644
--- a/frontend/src/utils/v1/instance.ts
+++ b/frontend/src/utils/v1/instance.ts
@@ -355,7 +355,8 @@ export const hasSchemaProperty = (databaseEngine: Engine) => {
databaseEngine === Engine.MSSQL ||
databaseEngine === Engine.REDSHIFT ||
databaseEngine === Engine.RISINGWAVE ||
- databaseEngine === Engine.COCKROACHDB
+ databaseEngine === Engine.COCKROACHDB ||
+ databaseEngine === Engine.SPANNER
);
};
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/SchemaPane.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/SchemaPane.vue
index d0a139ec7e..0a7ab7529b 100644
--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/SchemaPane.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/SchemaPane.vue
@@ -260,7 +260,7 @@ const selectedKeys = computed(() => {
if (!isValidDatabaseName(db.name)) return [];
const keys: string[] = [];
const tab = currentTab.value;
- if (tab && tab.connection.schema) {
+ if (tab && tab.connection.schema !== undefined) {
keys.push(`${db.name}/schemas/${tab.connection.schema}`);
}
if (!panelViewState.value || panelViewState.value.view === "CODE") {
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/CommonNode.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/CommonNode.vue
index 5bebbe803a..ffab53f294 100644
--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/CommonNode.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/CommonNode.vue
@@ -13,7 +13,7 @@
>
<slot name="icon" />
</span>
- <slot name="text">
+ <slot v-if="text" name="text">
<HighlightLabelText
v-if="highlight"
:text="text"
@@ -22,6 +22,7 @@
/>
<span v-else class="pl-[2px]">{{ text }}</span>
</slot>
+ <slot v-else name="fallback-text" />
<slot name="suffix" />
</slot>
</div>
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/SchemaNode.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/SchemaNode.vue
index a510504117..94b12df597 100644
--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/SchemaNode.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/SchemaNode.vue
@@ -3,6 +3,9 @@
<template #icon>
<SchemaIcon class="w-4 h-4" />
</template>
+ <template #fallback-text>
+ {{ $t("db.schema.default") }}
+ </template>
</CommonNode>
</template>
diff --git a/frontend/src/views/sql-editor/EditorCommon/SchemaChooser.vue b/frontend/src/views/sql-editor/EditorCommon/SchemaChooser.vue
index 86ec71db5a..a558141255 100644
--- a/frontend/src/views/sql-editor/EditorCommon/SchemaChooser.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/SchemaChooser.vue
@@ -33,17 +33,17 @@
--n-color-focus: rgb(var(--color-accent) / 0.05);
"
:style="{
- maxWidth: chosenSchema ? '12rem' : 'unset',
+ maxWidth: isChosen ? '12rem' : 'unset',
}"
>
<template #icon>
<SchemaIcon
class="w-4 h-4"
- :class="chosenSchema ? 'text-main' : 'text-control-placeholder'"
+ :class="isChosen ? 'text-main' : 'text-control-placeholder'"
/>
</template>
- <span v-if="chosenSchema" class="truncate text-main">
- {{ chosenSchema }}
+ <span v-if="isChosen" class="truncate text-main">
+ {{ chosenSchema || $t("db.schema.default") }}
</span>
<span v-else class="text-control-placeholder whitespace-nowrap">
{{ $t("database.schema.select") }}
@@ -67,6 +67,8 @@ import {
import { DatabaseMetadataView } from "@/types/proto/v1/database_service";
import { instanceAllowsSchemaScopedQuery } from "@/utils";
+const SchemaOptionValueUnspecified = "-1";
+
const { t } = useI18n();
const { currentTab: tab } = storeToRefs(useSQLEditorTabStore());
const { database, instance } = useConnectionOfCurrentSQLEditorTab();
@@ -104,28 +106,35 @@ const options = computed(() => {
const options = databaseMetadata.value.schemas.map<SelectOption>(
(schema) => ({
value: schema.name,
- label: schema.name,
+ label: schema.name || t("db.schema.default"),
})
);
options.unshift({
- value: "",
+ value: SchemaOptionValueUnspecified,
label: t("database.schema.unspecified"),
});
return options;
});
-const chosenSchema = computed<string | undefined>({
+const chosenSchema = computed<string>({
get() {
- return tab.value?.connection.schema ?? "";
+ const schema = tab.value?.connection.schema;
+ if (schema === undefined) return SchemaOptionValueUnspecified;
+ return schema;
},
set(value) {
if (!tab.value) return;
- tab.value.connection.schema = value;
+ tab.value.connection.schema =
+ value === SchemaOptionValueUnspecified ? undefined : value;
},
});
+const isChosen = computed(() => {
+ return chosenSchema.value !== SchemaOptionValueUnspecified;
+});
+
const handleSelect = async (value: string) => {
- chosenSchema.value = value === "" ? undefined : value;
+ chosenSchema.value = value;
};
const handleToggleShow = async (show: boolean) => {
diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/common/SchemaSelectToolbar.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/common/SchemaSelectToolbar.vue
index 855b3ba72b..f2d2538270 100644
--- a/frontend/src/views/sql-editor/EditorPanel/Panels/common/SchemaSelectToolbar.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/common/SchemaSelectToolbar.vue
@@ -31,6 +31,7 @@
<script setup lang="ts">
import { NSelect, type SelectOption } from "naive-ui";
import { computed } from "vue";
+import { useI18n } from "vue-i18n";
import { SchemaIcon } from "@/components/Icon";
import {
useConnectionOfCurrentSQLEditorTab,
@@ -48,6 +49,7 @@ defineProps<{
simple?: boolean;
}>();
+const { t } = useI18n();
const { database, instance } = useConnectionOfCurrentSQLEditorTab();
const { selectedSchemaName } = useEditorPanelContext();
const databaseMetadata = computed(() => {
@@ -58,10 +60,11 @@ const databaseMetadata = computed(() => {
});
const schemaSelectOptions = computed(() => {
return databaseMetadata.value.schemas.map<SelectOption>((schema) => ({
- label: schema.name,
+ label: schema.name || t("db.schema.default"),
value: schema.name,
}));
});
+
const showSchemaSelect = computed(() => {
return hasSchemaProperty(instance.value.engine);
});
diff --git a/frontend/src/views/sql-editor/EditorPanel/StandardPanel/SQLEditor.vue b/frontend/src/views/sql-editor/EditorPanel/StandardPanel/SQLEditor.vue
index 2fbb3b5012..55b26ecd30 100644
--- a/frontend/src/views/sql-editor/EditorPanel/StandardPanel/SQLEditor.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/StandardPanel/SQLEditor.vue
@@ -13,7 +13,7 @@
:auto-complete-context="{
instance: instance.name,
database: database.name,
- schema: chosenSchema,
+ schema: currentTab?.connection.schema,
scene: 'query',
}"
@update:content="handleUpdateStatement"
@@ -106,12 +106,6 @@ const filename = computed(() => {
return `${name}.${ext}`;
});
-const chosenSchema = computed(() => {
- const tab = currentTab.value;
- if (!tab || tab.connection.schema === "") return undefined;
- return tab.connection.schema;
-});
-
const handleUpdateStatement = (value: string) => {
// When we are switching between tabs, the MonacoEditor emits a 'change'
// event, but we shouldn't update the current tab;
diff --git a/frontend/src/views/sql-editor/EditorPanel/TerminalPanel/CompactSQLEditor.vue b/frontend/src/views/sql-editor/EditorPanel/TerminalPanel/CompactSQLEditor.vue
index 94f20c2622..23931f29db 100644
--- a/frontend/src/views/sql-editor/EditorPanel/TerminalPanel/CompactSQLEditor.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/TerminalPanel/CompactSQLEditor.vue
@@ -18,7 +18,7 @@
:auto-complete-context="{
instance: instance.name,
database: database.name,
- schema: chosenSchema,
+ schema: currentTab?.connection.schema,
scene: 'query',
}"
@update:content="handleChange"
@@ -89,12 +89,6 @@ const dialect = computed((): SQLDialect => {
return dialectOfEngineV1(engine);
});
-const chosenSchema = computed(() => {
- const tab = currentTab.value;
- if (!tab || tab.connection.schema === "") return undefined;
- return tab.connection.schema;
-});
-
const firstLinePrompt = computed(() => {
const lang = language.value;
if (lang === "javascript") return "MONGO>";
diff --git a/frontend/src/views/sql-editor/EditorPanel/context/index.ts b/frontend/src/views/sql-editor/EditorPanel/context/index.ts
index f967ba14b0..d915b6194e 100644
--- a/frontend/src/views/sql-editor/EditorPanel/context/index.ts
+++ b/frontend/src/views/sql-editor/EditorPanel/context/index.ts
@@ -108,7 +108,7 @@ export const provideEditorPanelContext = (base: {
watch(
() => tab.value?.connection.schema,
(schema) => {
- if (!schema) return;
+ if (schema === undefined) return;
if (!viewState.value) return;
if (viewState.value.schema === schema) return;
viewState.value.schema = schema;
@@ -120,7 +120,7 @@ export const provideEditorPanelContext = (base: {
(schema) => {
if (!schema) return;
if (!tab.value) return;
- if (!tab.value.connection.schema) return; // if schema chooser is "ALL", don't sync
+ if (tab.value.connection.schema === undefined) return; // if schema chooser is "ALL", don't sync
if (tab.value.connection.schema === schema) return;
tab.value.connection.schema = schema;
},