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: filter out invalid catalog (#19443)
ecmadao7120d3f88004
diff --git a/backend/api/v1/database_catalog_service.go b/backend/api/v1/database_catalog_service.goindex a60587d323..3c02ba36a4 100644--- a/backend/api/v1/database_catalog_service.go+++ b/backend/api/v1/database_catalog_service.go@@ -3,6 +3,7 @@ package v1import ("context""fmt"+ "strings""connectrpc.com/connect""github.com/pkg/errors"@@ -216,7 +217,7 @@ func validateCatalogSchemaNames(config *storepb.DatabaseConfig, metadata *storepif metadata != nil && hasEmptySchemaName(metadata.Schemas) {return nil}- return errors.New("schema name must not be empty for this database engine")+ return errors.Errorf("schema name must not be empty for database %v", strings.TrimSuffix(config.Name, common.CatalogSuffix))}func hasEmptySchemaName[T interface{ GetName() string }](schemas []T) bool {diff --git a/frontend/src/components/ColumnDataTable/LabelsCell.vue b/frontend/src/components/ColumnDataTable/LabelsCell.vueindex c68388892c..b5067890ce 100644--- a/frontend/src/components/ColumnDataTable/LabelsCell.vue+++ b/frontend/src/components/ColumnDataTable/LabelsCell.vue@@ -20,6 +20,7 @@<script lang="ts" setup>import { PencilIcon } from "lucide-vue-next";import { computed, reactive } from "vue";+import { useI18n } from "vue-i18n";import { MiniActionButton } from "@/components/v2";import { LabelsCell } from "@/components/v2/Model/cells";import { getColumnCatalog, useDatabaseCatalog } from "@/store";@@ -41,6 +42,7 @@ const props = defineProps<{const state = reactive<LocalState>({showLabelsDrawer: false,});+const { t } = useI18n();const databaseCatalog = useDatabaseCatalog(props.database, false);@@ -66,6 +68,7 @@ const onLabelsApply = async (labelsList: { [key: string]: string }[]) => {table: props.table,column: props.column,columnCatalog: { labels: labelsList[0] },+ notification: t("common.update"),});};</script>diff --git a/frontend/src/components/ColumnDataTable/index.vue b/frontend/src/components/ColumnDataTable/index.vueindex 6007f08800..421c73ce22 100644--- a/frontend/src/components/ColumnDataTable/index.vue+++ b/frontend/src/components/ColumnDataTable/index.vue@@ -274,7 +274,7 @@ const onClassificationIdApply = async (table: props.table.name,column,columnCatalog: { classification },- notification: !classification ? "common.removed" : undefined,+ notification: !classification ? t("common.removed") : t("common.update"),});};@@ -285,7 +285,7 @@ const onSemanticTypeApply = async (column: string, semanticType: string) => {table: props.table.name,column,columnCatalog: { semanticType },- notification: !semanticType ? "common.removed" : undefined,+ notification: !semanticType ? t("common.removed") : t("common.update"),});};</script>diff --git a/frontend/src/components/ColumnDataTable/utils.ts b/frontend/src/components/ColumnDataTable/utils.tsindex 068825f2b5..28746a84af 100644--- a/frontend/src/components/ColumnDataTable/utils.ts+++ b/frontend/src/components/ColumnDataTable/utils.ts@@ -19,14 +19,14 @@ export const updateColumnCatalog = async ({table,column,columnCatalog,- notification = "common.updated",+ notification,}: {database: string;schema: string;table: string;column: string;columnCatalog: Partial<ColumnCatalog>;- notification?: string;+ notification: string;}) => {const dbCatalogStore = useDatabaseCatalogV1Store();const catalog = await dbCatalogStore.getOrFetchDatabaseCatalog({ database });diff --git a/frontend/src/components/DatabaseDetail/ExportSchemaButton.vue b/frontend/src/components/DatabaseDetail/ExportSchemaButton.vueindex b6915bfd34..e066ba9c9c 100644--- a/frontend/src/components/DatabaseDetail/ExportSchemaButton.vue+++ b/frontend/src/components/DatabaseDetail/ExportSchemaButton.vue@@ -5,16 +5,18 @@:project="getDatabaseProject(database)":permissions="['bb.databases.getSchema']">- <NDropdown- :options="exportOptions"- :disabled="slotProps.disabled"- @select="handleExportFormat"- trigger="click"- >- <NButton :loading="exporting">- {{ $t("database.export-schema") }}- </NButton>- </NDropdown>+ <div>+ <NDropdown+ :options="exportOptions"+ :disabled="slotProps.disabled"+ @select="handleExportFormat"+ trigger="hover"+ >+ <NButton :loading="exporting">+ {{ $t("database.export-schema") }}+ </NButton>+ </NDropdown>+ </div></PermissionGuardWrapper></template>diff --git a/frontend/src/components/SensitiveData/useSemanticType.ts b/frontend/src/components/SensitiveData/useSemanticType.tsindex 41f9bbcb08..604a1264be 100644--- a/frontend/src/components/SensitiveData/useSemanticType.ts+++ b/frontend/src/components/SensitiveData/useSemanticType.ts@@ -1,6 +1,11 @@+import { create } from "@bufbuild/protobuf";import { computed, type MaybeRef, unref, watchEffect } from "vue";import { useSettingV1Store } from "@/store";-import { Setting_SettingName } from "@/types/proto-es/v1/setting_service_pb";+import {+ SemanticTypeSetting_SemanticTypeSchema,+ Setting_SettingName,+} from "@/types/proto-es/v1/setting_service_pb";+import { hasWorkspacePermissionV2 } from "@/utils";export const useSemanticType = (semanticTypeId: MaybeRef<string>) => {const settingV1Store = useSettingV1Store();@@ -27,6 +32,12 @@ export const useSemanticType = (semanticTypeId: MaybeRef<string>) => {if (!id) {return;}+ if (!hasWorkspacePermissionV2("bb.settings.get")) {+ return create(SemanticTypeSetting_SemanticTypeSchema, {+ id,+ title: id,+ });+ }return semanticTypeList.value.find((data) => data.id === id);});diff --git a/frontend/src/store/cache.ts b/frontend/src/store/cache.tsindex 1b016ad426..ea225a449b 100644--- a/frontend/src/store/cache.ts+++ b/frontend/src/store/cache.ts@@ -57,13 +57,15 @@ export const useCache = <K extends KeyType[], T>(namespace: string) => {const key = getKey(keys);const abortController = new AbortController();- promise.then((entity: T) => {- if (abortController.signal.aborted) {+ promise+ .then((entity: T) => {+ if (!abortController.signal.aborted) {+ setEntity(keys, entity);+ }+ })+ .finally(() => {invalidateRequest(keys);- return;- }- setEntity(keys, entity);- });+ });requestCacheMap.set(key, {keys,promise,diff --git a/frontend/src/store/modules/v1/databaseCatalog.ts b/frontend/src/store/modules/v1/databaseCatalog.tsindex befdff9905..9fc4646e17 100644--- a/frontend/src/store/modules/v1/databaseCatalog.ts+++ b/frontend/src/store/modules/v1/databaseCatalog.ts@@ -22,15 +22,26 @@ import {hasProjectPermissionV2,} from "@/utils";import { useDatabaseV1Store } from "./database";+import { useDBSchemaV1Store } from "./dbSchema";type DatabaseCatalogCacheKey = [string /* database catalog resource name */];+const ensureDatabaseResourceName = (name: string) => {+ return extractDatabaseResourceName(name).database;+};++const ensureDatabaseCatalogResourceName = (name: string) => {+ const database = ensureDatabaseResourceName(name);+ return `${database}/catalog`;+};+export const useDatabaseCatalogV1Store = defineStore("databaseCatalog_v1",() => {const cacheByName = useCache<DatabaseCatalogCacheKey, DatabaseCatalog>("bb.database-catalog.by-name");+ const dbSchemaStore = useDBSchemaV1Store();const getCache = (name: string): DatabaseCatalog | undefined => {const catalogResourceName = ensureDatabaseCatalogResourceName(name);@@ -84,8 +95,28 @@ export const useDatabaseCatalogV1Store = defineStore(};const updateDatabaseCatalog = async (catalog: DatabaseCatalog) => {+ const databaseName = ensureDatabaseResourceName(catalog.name);+ const validCatalog = create(DatabaseCatalogSchema, {+ name: catalog.name,+ schemas: [],+ });+ for (const schema of catalog.schemas) {+ try {+ const schemaMetadata = await dbSchemaStore.getOrFetchSchemaMetadata({+ database: databaseName,+ schema: schema.name,+ });+ if (!schemaMetadata || schemaMetadata.name !== schema.name) {+ continue;+ }+ validCatalog.schemas.push(schema);+ } catch {+ // fallback to add the schema catalog to avoid current user doesn't have the permission to get the metadata.+ validCatalog.schemas.push(schema);+ }+ }const request = create(UpdateDatabaseCatalogRequestSchema, {- catalog: catalog,+ catalog: validCatalog,});const response =await databaseCatalogServiceClientConnect.updateDatabaseCatalog(@@ -132,14 +163,6 @@ export const useDatabaseCatalogV1Store = defineStore(});-const ensureDatabaseResourceName = (name: string) => {- return extractDatabaseResourceName(name).database;-};-const ensureDatabaseCatalogResourceName = (name: string) => {- const database = ensureDatabaseResourceName(name);- return `${database}/catalog`;-};-export const getTableCatalog = (catalog: DatabaseCatalog,schema: string,diff --git a/frontend/src/store/modules/v1/dbSchema.ts b/frontend/src/store/modules/v1/dbSchema.tsindex e0db1d862c..155475b6e1 100644--- a/frontend/src/store/modules/v1/dbSchema.ts+++ b/frontend/src/store/modules/v1/dbSchema.ts@@ -125,10 +125,11 @@ export const useDBSchemaV1Store = defineStore("dbSchema_v1", () => {silent = false,skipCache = false,} = params;- const { databaseName } = extractDatabaseResourceName(database);+ const { databaseName, instanceName } =+ extractDatabaseResourceName(database);if (databaseName === String(UNKNOWN_ID) ||- databaseName === String(UNKNOWN_ID)+ instanceName === String(UNKNOWN_ID)) {return create(DatabaseMetadataSchema, {name: ensureDatabaseMetadataResourceName(@@ -187,10 +188,38 @@ export const useDBSchemaV1Store = defineStore("dbSchema_v1", () => {database: string;schema: string;}) => {- return (- getSchemaList(database).find((s) => s.name === schema) ??- create(SchemaMetadataSchema, {})- );+ return getSchemaList(database).find((s) => s.name === schema);+ };++ const getOrFetchSchemaMetadata = async ({+ database,+ schema,+ }: {+ database: string;+ schema: string;+ }) => {+ const { databaseName } = extractDatabaseResourceName(database);+ if (+ databaseName === String(UNKNOWN_ID) ||+ databaseName === String(UNKNOWN_ID)+ ) {+ return create(SchemaMetadataSchema, {+ name: schema,+ });+ }++ const schemaMetadata = getSchemaMetadata({ database, schema });+ if (schemaMetadata?.name === schema) {+ return schemaMetadata;+ }++ return getOrFetchDatabaseMetadata({+ database,+ silent: true,+ filter: `schema == "${schema}"`,+ }).then((res) => {+ return res.schemas.find((s) => s.name === schema);+ });};const getTableList = ({@@ -393,6 +422,7 @@ export const useDBSchemaV1Store = defineStore("dbSchema_v1", () => {getOrFetchDatabaseMetadata,getSchemaList,getSchemaMetadata,+ getOrFetchSchemaMetadata,getTableList,getTableMetadata,getOrFetchTableMetadata,diff --git a/frontend/src/views/project/ProjectDatabaseLayout.vue b/frontend/src/views/project/ProjectDatabaseLayout.vueindex f7a9a527ad..b4667d8ad8 100644--- a/frontend/src/views/project/ProjectDatabaseLayout.vue+++ b/frontend/src/views/project/ProjectDatabaseLayout.vue@@ -33,9 +33,14 @@ onMounted(async () => {const database = await databaseStore.getOrFetchDatabaseByName(`${instanceNamePrefix}${props.instanceId}/${databaseNamePrefix}${props.databaseName}`);- await dbSchemaStore.getOrFetchDatabaseMetadata({- database: database.name,- silent: true,- });+ try {+ await dbSchemaStore.getOrFetchDatabaseMetadata({+ database: database.name,+ silent: true,+ });+ } catch {+ // Silently ignore permission errors — the page can still render+ // without schema metadata.+ }});</script>diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/ColumnNode.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/ColumnNode.vueindex e35f167d07..a452eead6b 100644--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/ColumnNode.vue+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/ColumnNode.vue@@ -58,12 +58,12 @@ const columnMetadata = computed(() => {return tableMetadata.value?.columns.find((c) => c.name === column);} else if ("externalTable" in target.value) {const { externalTable } = target.value;- return schemaMetadata.externalTables+ return schemaMetadata?.externalTables.find((t) => t.name === externalTable)?.columns.find((c) => c.name === column);} else if ("view" in target.value) {const { view } = target.value;- return schemaMetadata.views+ return schemaMetadata?.views.find((v) => v.name === view)?.columns.find((c) => c.name === column);}diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/FunctionNode.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/FunctionNode.vueindex ad4e3031cb..210fc5dfcb 100644--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/FunctionNode.vue+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/FunctionNode.vue@@ -32,6 +32,6 @@ const functionMetadata = computed(dbSchema.getSchemaMetadata({database: target.value.database,schema: target.value.schema,- }).functions[target.value.position]+ })?.functions[target.value.position]);</script>diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/ProcedureNode.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/ProcedureNode.vueindex 7e9b33c101..f27d48d7b2 100644--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/ProcedureNode.vue+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/ProcedureNode.vue@@ -34,6 +34,6 @@ const procedureMetadata = computed(dbSchema.getSchemaMetadata({database: target.value.database,schema: target.value.schema,- }).procedures[target.value.position]+ })?.procedures[target.value.position]);</script>