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(schema-editor): minor bug fixes (#9844)
Liu Ji3fbea58f102c
diff --git a/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vue b/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vueindex a6359701dc..69e6b7b015 100644--- a/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vue+++ b/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vue@@ -381,7 +381,12 @@ const generateDiffDDLMap = async (silent: boolean) => {const editing = cloneDeep(target.metadata);await applyMetadataEdit(database, editing);- const result = await generateSingleDiffDDL(database, source, editing);+ const result = await generateSingleDiffDDL(+ database,+ source,+ editing,+ /* !allowEmptyDiffDDLWithConfigChange */ false+ );if (result.fatal && !silent) {pushNotification({module: "bytebase",diff --git a/frontend/src/components/Branch/BranchDetailView.vue b/frontend/src/components/Branch/BranchDetailView.vueindex 072b894d2a..ca7ad70127 100644--- a/frontend/src/components/Branch/BranchDetailView.vue+++ b/frontend/src/components/Branch/BranchDetailView.vue@@ -433,7 +433,12 @@ const handleApplyToDatabase = async (databaseIdList: string[]) => {const source =branch.baselineSchemaMetadata ?? DatabaseMetadata.fromPartial({});const target = branch.schemaMetadata ?? DatabaseMetadata.fromPartial({});- const result = await generateDiffDDL(database.value, source, target);+ const result = await generateDiffDDL(+ database.value,+ source,+ target,+ /* !allowEmptyDiffDDLWithConfigChange */ false+ );if (result.fatal) {pushNotification({diff --git a/frontend/src/components/SchemaEditorLite/algorithm/index.ts b/frontend/src/components/SchemaEditorLite/algorithm/index.tsindex 2c59f487ed..896668b97b 100644--- a/frontend/src/components/SchemaEditorLite/algorithm/index.ts+++ b/frontend/src/components/SchemaEditorLite/algorithm/index.ts@@ -1,5 +1,12 @@import { ComposedDatabase } from "@/types";-import { DatabaseMetadata } from "@/types/proto/v1/database_service";+import {+ DatabaseMetadata,+ SchemaConfig,+ SchemaMetadata,+ TableConfig,+ TableMetadata,+} from "@/types/proto/v1/database_service";+import { keyBy } from "@/utils";import { SchemaEditorContext } from "../context";import { DiffMerge } from "./diff-merge";@@ -55,7 +62,57 @@ export const useAlgorithm = (context: SchemaEditorContext) => {});});});++ cleanupUnusedConfigs(metadata);};return { rebuildMetadataEdit, applyMetadataEdit };};++const cleanupUnusedConfigs = (metadata: DatabaseMetadata) => {+ const cleanupColumnConfigs = (+ table: TableMetadata,+ tableConfig: TableConfig+ ) => {+ const columnMap = keyBy(table.columns, (column) => column.name);+ // Remove unused column configs+ tableConfig.columnConfigs = tableConfig.columnConfigs.filter((cc) =>+ columnMap.has(cc.name)+ );+ };+ const cleanupTableConfigs = (+ schema: SchemaMetadata,+ schemaConfig: SchemaConfig+ ) => {+ const tableMap = keyBy(schema.tables, (table) => table.name);+ // Remove unused table configs+ schemaConfig.tableConfigs = schemaConfig.tableConfigs.filter((tc) =>+ tableMap.has(tc.name)+ );+ // Recursively cleanup column configs+ schemaConfig.tableConfigs.forEach((tc) => {+ cleanupColumnConfigs(tableMap.get(tc.name)!, tc);+ });+ // Cleanup empty table configs+ schemaConfig.tableConfigs = schemaConfig.tableConfigs.filter(+ (tc) => tc.columnConfigs.length > 0+ );+ };+ const cleanupSchemaConfigs = (metadata: DatabaseMetadata) => {+ const schemaMap = keyBy(metadata.schemas, (schema) => schema.name);+ // Remove unused schema configs+ metadata.schemaConfigs = metadata.schemaConfigs.filter((sc) =>+ schemaMap.has(sc.name)+ );+ // Recursively cleanup table configs+ metadata.schemaConfigs.forEach((sc) => {+ cleanupTableConfigs(schemaMap.get(sc.name)!, sc);+ });+ // Cleanup empty schema configs+ metadata.schemaConfigs = metadata.schemaConfigs.filter(+ (sc) => sc.tableConfigs.length > 0+ );+ };++ cleanupSchemaConfigs(metadata);+};diff --git a/frontend/src/components/SchemaEditorLite/common.ts b/frontend/src/components/SchemaEditorLite/common.tsindex e9fd761cf8..76951b175a 100644--- a/frontend/src/components/SchemaEditorLite/common.ts+++ b/frontend/src/components/SchemaEditorLite/common.ts@@ -20,7 +20,8 @@ export type GenerateDiffDDLResult = {export const generateDiffDDL = async (database: ComposedDatabase,source: DatabaseMetadata,- target: DatabaseMetadata+ target: DatabaseMetadata,+ allowEmptyDiffDDLWithConfigChange = true): Promise<GenerateDiffDDLResult> => {const finish = (statement: string, errors: string[], fatal: boolean) => {_generateDiffDDLTimer.end("generateDiffDDL");@@ -56,7 +57,10 @@ export const generateDiffDDL = async ();const { diff } = diffResponse;if (diff.length === 0) {- if (!isEqual(source.schemaConfigs, target.schemaConfigs)) {+ if (+ !allowEmptyDiffDDLWithConfigChange &&+ !isEqual(source.schemaConfigs, target.schemaConfigs)+ ) {return finish("",[t("schema-editor.message.cannot-change-config")],diff --git a/frontend/src/components/SchemaEditorLite/context/edit.ts b/frontend/src/components/SchemaEditorLite/context/edit.tsindex 3ee35f7c7b..ab6cbbbacb 100644--- a/frontend/src/components/SchemaEditorLite/context/edit.ts+++ b/frontend/src/components/SchemaEditorLite/context/edit.ts@@ -45,7 +45,9 @@ export const useEditStatus = () => {) => {const key = keyForResource(database, metadata);const keys = recursive- ? dirtyPathsArray.value.filter((path) => path.startsWith(key))+ ? dirtyPathsArray.value.filter(+ (path) => path === key || path.startsWith(`${key}/`)+ ): [key];keys.forEach((key) => dirtyPaths.value.delete(key));@@ -62,7 +64,7 @@ export const useEditStatus = () => {if (dirtyPaths.value.has(key)) {return dirtyPaths.value.get(key)!;}- if (dirtyPathsArray.value.some((path) => path.startsWith(key))) {+ if (dirtyPathsArray.value.some((path) => path.startsWith(`${key}/`))) {return "updated";}return "normal";@@ -80,7 +82,7 @@ export const useEditStatus = () => {if (dirtyPaths.value.has(key)) {return dirtyPaths.value.get(key)!;}- if (dirtyPathsArray.value.some((path) => path.startsWith(key))) {+ if (dirtyPathsArray.value.some((path) => path.startsWith(`${key}/`))) {return "updated";}return "normal";@@ -99,7 +101,7 @@ export const useEditStatus = () => {if (dirtyPaths.value.has(key)) {return dirtyPaths.value.get(key)!;}- if (dirtyPathsArray.value.some((path) => path.startsWith(key))) {+ if (dirtyPathsArray.value.some((path) => path.startsWith(`${key}/`))) {return "updated";}return "normal";