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: update index name generator in schema editor (#13574)
boojack3a1b0f88987a
diff --git a/frontend/package.json b/frontend/package.jsonindex cf467c3fa5..cb31b320b7 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -30,6 +30,7 @@"axios": "1.7.4","bootstrap": "5.3.3","canvas-confetti": "1.9.3",+ "crypto-js": "^4.2.0","d3-shape": "^3.2.0","dayjs": "1.11.11","dompurify": "3.1.6",@@ -92,6 +93,7 @@"@trivago/prettier-plugin-sort-imports": "^4.3.0","@tsconfig/node20": "20.1.4","@types/canvas-confetti": "1.6.4",+ "@types/crypto-js": "^4.2.2","@types/d3-shape": "^3.1.6","@types/dompurify": "3.0.5","@types/downloadjs": "1.4.6",diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yamlindex 1a57a57746..1a52514c59 100644--- a/frontend/pnpm-lock.yaml+++ b/frontend/pnpm-lock.yaml@@ -38,6 +38,9 @@ importers:canvas-confetti:specifier: 1.9.3version: 1.9.3+ crypto-js:+ specifier: ^4.2.0+ version: 4.2.0d3-shape:specifier: ^3.2.0version: 3.2.0@@ -219,6 +222,9 @@ importers:'@types/canvas-confetti':specifier: 1.6.4version: 1.6.4+ '@types/crypto-js':+ specifier: ^4.2.2+ version: 4.2.2'@types/d3-shape':specifier: ^3.1.6version: 3.1.6@@ -1154,6 +1160,9 @@ packages:'@types/[email protected]':resolution: {integrity: sha512-fNyZ/Fdw/Y92X0vv7B+BD6ysHL4xVU5dJcgzgxLdGbn8O3PezZNIJpml44lKM0nsGur+o/6+NZbZeNTt00U1uA==}+ '@types/[email protected]':+ resolution: {integrity: sha512-sDOLlVbHhXpAUAL0YHDUUwDZf3iN4Bwi4W6a0W0b+QcAezUbRtH4FVb+9J4h+XFPW7l/gQ9F8qC7P+Ec4k8QVQ==}+'@types/[email protected]':resolution: {integrity: sha512-P2dlU/q51fkOc/Gfl3Ul9kicV7l+ra934qBFXCFhrZMOL6du1TM0pm1ThYvENukyOn5h9v+yMJ9Fn5JK4QozrQ==}@@ -1812,6 +1821,9 @@ packages:resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==}engines: {node: '>= 8'}+ resolution: {integrity: sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==}+resolution: {integrity: sha512-9nF4PdUle+5ta4W5SyZdLCCmFd37uVimSjg1evcTqKJCyvCEEj12WKzOSBNak6r4im4J4iYXKH1OWpUV5LBYFg==}@@ -4841,6 +4853,8 @@ snapshots:'@types/[email protected]': {}+ '@types/[email protected]': {}+'@types/[email protected]': {}'@types/[email protected]':@@ -5646,6 +5660,8 @@ snapshots:shebang-command: 2.0.0which: 2.0.2+ [email protected]: {}+dependencies:'@emotion/hash': 0.8.0diff --git a/frontend/src/components/SchemaEditorLite/Aside/Tree.vue b/frontend/src/components/SchemaEditorLite/Aside/Tree.vueindex c932e00802..43fc835240 100644--- a/frontend/src/components/SchemaEditorLite/Aside/Tree.vue+++ b/frontend/src/components/SchemaEditorLite/Aside/Tree.vue@@ -102,6 +102,7 @@<script lang="ts" setup>import { useElementSize } from "@vueuse/core";+import { MD5 } from "crypto-js";import { cloneDeep, debounce, escape, head } from "lodash-es";import { MoreHorizontalIcon, CopyIcon } from "lucide-vue-next";import type { TreeOption } from "naive-ui";@@ -651,6 +652,10 @@ const handleDuplicateTable = (treeNode: TreeNodeForTable) => {const newTable = cloneDeep(table);newTable.name = getDuplicateName(targetName);+ // As index names should be unique, we need to generate new names for them.+ for (const index of newTable.indexes) {+ index.name = `${index.name}_${MD5(`${newTable.name}_${Date.now()}`).toString().slice(0, 6)}`;+ }schema.tables.push(newTable);markEditStatus(db,diff --git a/frontend/src/components/SchemaEditorLite/edit.ts b/frontend/src/components/SchemaEditorLite/edit.tsindex b9bb0826c4..c5d674b7b1 100644--- a/frontend/src/components/SchemaEditorLite/edit.ts+++ b/frontend/src/components/SchemaEditorLite/edit.ts@@ -1,3 +1,4 @@+import { MD5 } from "crypto-js";import { pull, pullAt } from "lodash-es";import type {ForeignKeyMetadata,@@ -12,10 +13,15 @@ export const upsertColumnPrimaryKey = () => {const pkIndex = table.indexes.findIndex((idx) => idx.primary);if (pkIndex < 0) {+ // Generate a unique pk name.+ // Format: table_pk_{md5(table_pk_timestamp).slice(0, 6)}, e.g. test_pk_d4402d+ const nameParts: string[] = [table.name, "pk"];+ const rawName = nameParts.join("_").toLowerCase();+ const name = `${rawName}_${MD5(`${rawName}_${Date.now()}`).toString().slice(0, 6)}`;table.indexes.push(IndexMetadata.fromPartial({+ name,primary: true,- name: "PRIMARY",unique: true,expressions: [columnName],})@@ -25,6 +31,7 @@ export const upsertColumnPrimaryKey = (upsertArray(pk.expressions, columnName);}};+export const removeColumnPrimaryKey = (table: TableMetadata,columnName: string@@ -39,6 +46,7 @@ export const removeColumnPrimaryKey = (pullAt(table.indexes, pkIndex);}};+export const upsertColumnFromForeignKey = (fk: ForeignKeyMetadata,columnName: string,@@ -52,6 +60,7 @@ export const upsertColumnFromForeignKey = (fk.referencedColumns[position] = referencedColumnName;}};+export const removeColumnFromForeignKey = (table: TableMetadata,fk: ForeignKeyMetadata,@@ -70,6 +79,7 @@ export const removeColumnFromForeignKey = (}}};+export const removeColumnFromAllForeignKeys = (table: TableMetadata,columnName: string