Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: primary keys and indexes (#3950)
Liu Jiae2c4122794f
diff --git a/frontend/src/components/SchemaDiagram/ER/TableNode.vue b/frontend/src/components/SchemaDiagram/ER/TableNode.vueindex 24798f0189..a7be2c9004 100644--- a/frontend/src/components/SchemaDiagram/ER/TableNode.vue+++ b/frontend/src/components/SchemaDiagram/ER/TableNode.vue@@ -23,11 +23,14 @@:bb-column-name="column.name"><td class="w-5 py-1.5">- <!-- TODO: remove this --><heroicons-outline:key- v-if="column.name === 'emp_no' || column.name === 'dept_no'"+ v-if="isPrimaryKey(table, column)"class="w-3 h-3 mx-auto text-amber-500"/>+ <tabler:diamonds+ v-else-if="isIndex(table, column)"+ class="w-3 h-3 mx-auto text-gray-500"+ /></td><td class="w-auto text-xs py-1.5"><div class="whitespace-pre-wrap break-words">@@ -51,7 +54,7 @@ import { computed } from "vue";import { hashCode } from "@/bbkit/BBUtil";import { TableMetadata } from "@/types/proto/database";-import { useSchemaDiagramContext } from "../common";+import { useSchemaDiagramContext, isPrimaryKey, isIndex } from "../common";const props = withDefaults(defineProps<{diff --git a/frontend/src/components/SchemaDiagram/common/index.ts b/frontend/src/components/SchemaDiagram/common/index.tsindex c45ebc8a7f..fc4b498ff2 100644--- a/frontend/src/components/SchemaDiagram/common/index.ts+++ b/frontend/src/components/SchemaDiagram/common/index.ts@@ -1,3 +1,4 @@export * from "./context";export * from "./useDraggable";export * from "./utils";+export * from "./schema";diff --git a/frontend/src/components/SchemaDiagram/common/schema.ts b/frontend/src/components/SchemaDiagram/common/schema.tsnew file mode 100644index 0000000000..dc6fbe8786--- /dev/null+++ b/frontend/src/components/SchemaDiagram/common/schema.ts@@ -0,0 +1,21 @@+import { ColumnMetadata, TableMetadata } from "@/types/proto/database";++export const findPrimaryKey = (table: TableMetadata) => {+ return table.indexes.find((idx) => idx.primary);+};++export const isPrimaryKey = (table: TableMetadata, column: ColumnMetadata) => {+ const pk = findPrimaryKey(table);+ if (!pk) return false;+ return pk.expressions.includes(column.name);+};++export const findIndexes = (table: TableMetadata, column: ColumnMetadata) => {+ return table.indexes.filter(+ (idx) => !idx.primary && idx.expressions.includes(column.name)+ );+};++export const isIndex = (table: TableMetadata, column: ColumnMetadata) => {+ return findIndexes(table, column).length > 0;+};