Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: rebuild editable metadata in branching (#8797)
boojackb0de9472c01c
diff --git a/frontend/src/components/SchemaEditorV1/utils/metadata.ts b/frontend/src/components/SchemaEditorV1/utils/metadata.tsindex 25f9defe38..db1e834107 100644--- a/frontend/src/components/SchemaEditorV1/utils/metadata.ts+++ b/frontend/src/components/SchemaEditorV1/utils/metadata.ts@@ -72,12 +72,10 @@ export const mergeSchemaEditToMetadata = ((item) => item.name !== columnEdit.name);table.columns.push(transformColumnEditToMetadata(columnEdit));- continue;} else if (columnEdit.status === "dropped") {table.columns = table.columns.filter((item) => item.name !== columnEdit.name);- continue;} else {const column = table.columns.find((item) => item.name === columnEdit.name@@ -86,6 +84,7 @@ export const mergeSchemaEditToMetadata = (table.columns.push(transformColumnEditToMetadata(columnEdit));continue;}+column.type = columnEdit.type;column.nullable = columnEdit.nullable;column.comment = columnEdit.comment;@@ -107,6 +106,30 @@ export const mergeSchemaEditToMetadata = ();}}+ if (tableEdit.primaryKey.columnIdList.length > 0) {+ const primaryIndex =+ table.indexes.find((index) => index.primary) ||+ IndexMetadata.fromPartial({+ name: tableEdit.primaryKey.name,+ primary: true,+ expressions: [],+ });+ for (const columnId of tableEdit.primaryKey.columnIdList) {+ const column = tableEdit.columnList.find(+ (column) => column.id === columnId+ );+ if (column) {+ primaryIndex.expressions.push(column.name);+ }+ }+ table.indexes = table.indexes.filter((index) => !index.primary);+ primaryIndex.expressions = uniq(primaryIndex.expressions);+ if (primaryIndex.expressions.length > 0) {+ table.indexes.push(primaryIndex);+ }+ } else {+ table.indexes = table.indexes.filter((index) => !index.primary);+ }table.comment = tableEdit.comment;table.userComment = tableEdit.userComment;table.classification = tableEdit.classification || "";@@ -240,52 +263,7 @@ const transformSchemaEditToMetadata = (schemaEdit: Schema): SchemaMetadata => {});for (const table of schemaEdit.tableList) {- const tableMetadata = TableMetadata.fromPartial({- name: table.name,- columns: [],- indexes: [],- foreignKeys: [],- comment: table.comment,- userComment: table.userComment,- classification: table.classification,- });-- for (const column of table.columnList) {- tableMetadata.columns.push(- ColumnMetadata.fromPartial({- name: column.name,- type: column.type,- nullable: column.nullable,- hasDefault: column.hasDefault,- defaultNull: column.defaultNull,- defaultString: column.defaultString,- defaultExpression: column.defaultExpression,- comment: column.comment,- userComment: column.userComment,- classification: column.classification,- })- );- }-- if (table.primaryKey.columnIdList.length > 0) {- const primaryIndex = IndexMetadata.fromPartial({- name: `${table.name}-pk-${randomString(8).toLowerCase()}`,- primary: true,- expressions: [],- });- for (const columnId of table.primaryKey.columnIdList) {- const column = table.columnList.find(- (column) => column.id === columnId- );- if (column) {- primaryIndex.expressions.push(column.name);- }- }- if (primaryIndex.expressions.length > 0) {- tableMetadata.indexes.push(primaryIndex);- }- }-+ const tableMetadata = transformTableEditToMetadata(table);schemaMetadata.tables.push(tableMetadata);}@@ -324,7 +302,7 @@ export const transformTableEditToMetadata = (if (tableEdit.primaryKey.columnIdList.length > 0) {const primaryIndex = IndexMetadata.fromPartial({- name: `${tableEdit.name}-pk-${randomString(8).toLowerCase()}`,+ name: tableEdit.primaryKey.name,primary: true,expressions: [],});@@ -389,6 +367,10 @@ export const rebuildEditableSchemas = (continue;}+ editableTable.userComment = table.userComment;+ editableTable.classification = table.classification;+ editableTable.comment = table.comment;+const tableConfig =schemaConfig.tableConfigs.find((tableConfig) => tableConfig.name === editableTable.name@@ -455,6 +437,11 @@ export const rebuildEditableSchemas = (editableTable.primaryKey.columnIdList = uniq(editableTable.primaryKey.columnIdList);+ } else {+ editableTable.primaryKey = {+ name: "",+ columnIdList: [],+ };}}diff --git a/frontend/src/store/modules/schemaDesign.ts b/frontend/src/store/modules/schemaDesign.tsindex 5ada7dcb0e..860a5cf967 100644--- a/frontend/src/store/modules/schemaDesign.ts+++ b/frontend/src/store/modules/schemaDesign.ts@@ -49,6 +49,9 @@ export const useSchemaDesignStore = defineStore("schema_design", () => {parent: projectResourceId,schemaDesign,});+ console.debug("baseline schema", schemaDesign.baselineSchema);+ console.debug("target metadata", schemaDesign.schemaMetadata);+ console.debug("got schema", createdSchemaDesign.schema);schemaDesignMapByName.set(createdSchemaDesign.name, createdSchemaDesign);return createdSchemaDesign;};diff --git a/frontend/src/types/v1/schemaEditor/atomType.ts b/frontend/src/types/v1/schemaEditor/atomType.tsindex 23f24255cd..24bddb4b09 100644--- a/frontend/src/types/v1/schemaEditor/atomType.ts+++ b/frontend/src/types/v1/schemaEditor/atomType.ts@@ -107,6 +107,7 @@ export const convertTableMetadataToTable = (dataSize: tableMetadata.dataSize,comment: tableMetadata.comment,userComment: tableMetadata.userComment,+ classification: tableMetadata.classification,columnList: tableMetadata.columns.map((column) =>convertColumnMetadataToColumn(column,@@ -122,7 +123,6 @@ export const convertTableMetadataToTable = (},foreignKeyList: [],status,- classification: tableMetadata.classification,};for (const indexMetadata of tableMetadata.indexes) {