Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

refactor: remove catalog from Schema Editor (#18461)

Danny Xuac5d2f4415fb
diff --git a/CLAUDE.md b/CLAUDE.md
index 93ad60f34f..ea08bd3770 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -140,11 +140,6 @@ psql -U bbdev bbdev
- Use American English
- Avoid plurals like "xxxList" for simplicity and to prevent singular/plural ambiguity stemming from poor design
-### Git
-
-- Follow conventional commit format
-- **Worktrees** — Place git worktrees in `../bytebase-worktrees/` (sibling directory to the main repo) to keep them organized and separate from the main working directory
-
### Imports
- Use organized imports (sorted by the import path)
diff --git a/frontend/src/components/Plan/components/StatementSection/SchemaEditorDrawer.vue b/frontend/src/components/Plan/components/StatementSection/SchemaEditorDrawer.vue
index 198c06f6c2..9069a81cf9 100644
--- a/frontend/src/components/Plan/components/StatementSection/SchemaEditorDrawer.vue
+++ b/frontend/src/components/Plan/components/StatementSection/SchemaEditorDrawer.vue
@@ -54,7 +54,7 @@ import SchemaEditorLite, {
generateDiffDDL,
} from "@/components/SchemaEditorLite";
import { Drawer, DrawerContent } from "@/components/v2";
-import { useDatabaseCatalogV1Store, useDBSchemaV1Store } from "@/store";
+import { useDBSchemaV1Store } from "@/store";
import type { ComposedDatabase } from "@/types";
import type { Project } from "@/types/proto-es/v1/project_service_pb";
@@ -76,7 +76,6 @@ const show = computed({
const schemaEditorRef = ref<InstanceType<typeof SchemaEditorLite>>();
const dbSchemaStore = useDBSchemaV1Store();
-const dbCatalogStore = useDatabaseCatalogV1Store();
const state = reactive({
isPreparingMetadata: false,
@@ -110,25 +109,17 @@ const prepareDatabaseMetadata = async (database: ComposedDatabase) => {
state.isPreparingMetadata = true;
state.targets = [];
- const [metadata, catalog] = await Promise.all([
- dbSchemaStore.getOrFetchDatabaseMetadata({
- database: database.name,
- skipCache: true,
- limit: 200,
- }),
- dbCatalogStore.getOrFetchDatabaseCatalog({
- database: database.name,
- skipCache: true,
- }),
- ]);
+ const metadata = await dbSchemaStore.getOrFetchDatabaseMetadata({
+ database: database.name,
+ skipCache: true,
+ limit: 200,
+ });
state.targets = [
{
database: database,
metadata: cloneDeep(metadata),
baselineMetadata: metadata,
- catalog: cloneDeep(catalog),
- baselineCatalog: catalog,
},
];
@@ -166,16 +157,8 @@ const handleInsertSQL = async () => {
const target = state.targets[0];
if (!target) return;
- const {
- database,
- baselineMetadata,
- baselineCatalog: _baselineCatalog,
- } = target;
- const { metadata, catalog: _catalog } = applyMetadataEdit(
- database,
- target.metadata,
- target.catalog
- );
+ const { database, baselineMetadata } = target;
+ const { metadata } = applyMetadataEdit(database, target.metadata);
const result = await generateDiffDDL({
database,
diff --git a/frontend/src/components/SchemaEditorLite/Aside/Tree.vue b/frontend/src/components/SchemaEditorLite/Aside/Tree.vue
index fb32194845..05b1d9218e 100644
--- a/frontend/src/components/SchemaEditorLite/Aside/Tree.vue
+++ b/frontend/src/components/SchemaEditorLite/Aside/Tree.vue
@@ -195,8 +195,6 @@ const {
getViewStatus,
getProcedureStatus,
getFunctionStatus,
- getTableCatalog,
- upsertTableCatalog,
queuePendingScrollToTable,
queuePendingScrollToColumn,
} = useSchemaEditorContext();
@@ -704,25 +702,6 @@ const handleDuplicateTable = (treeNode: TreeNodeForTable) => {
);
});
- upsertTableCatalog(
- {
- database: db.name,
- schema: schema.name,
- table: newTable.name,
- },
- (config) => {
- Object.assign(
- config,
- getTableCatalog({
- database: db.name,
- schema: schema.name,
- table: table.name,
- }),
- { name: newTable.name }
- );
- }
- );
-
addTab({
type: "table",
database: db,
diff --git a/frontend/src/components/SchemaEditorLite/Modals/TableNameModal.vue b/frontend/src/components/SchemaEditorLite/Modals/TableNameModal.vue
index 01b55f7d77..c338dea48e 100644
--- a/frontend/src/components/SchemaEditorLite/Modals/TableNameModal.vue
+++ b/frontend/src/components/SchemaEditorLite/Modals/TableNameModal.vue
@@ -69,14 +69,8 @@ const emit = defineEmits<{
}>();
const { t } = useI18n();
-const {
- events,
- addTab,
- markEditStatus,
- queuePendingScrollToTable,
- upsertTableCatalog,
- removeTableCatalog,
-} = useSchemaEditorContext();
+const { events, addTab, markEditStatus, queuePendingScrollToTable } =
+ useSchemaEditorContext();
const inputRef = ref<InputInst>();
const notificationStore = useNotificationStore();
const mode = computed(() => {
@@ -163,21 +157,6 @@ const handleConfirmButtonClick = async () => {
});
} else {
const { table } = props;
- upsertTableCatalog(
- {
- database: props.database.name,
- schema: props.schema.name,
- table: table.name,
- },
- (catalog) => {
- catalog.name = state.tableName;
- }
- );
- removeTableCatalog({
- database: props.database.name,
- schema: props.schema.name,
- table: table.name,
- });
table.name = state.tableName;
events.emit("rebuild-edit-status", {
diff --git a/frontend/src/components/SchemaEditorLite/Panels/PreviewPane.vue b/frontend/src/components/SchemaEditorLite/Panels/PreviewPane.vue
index 576f70873e..ac02380e0b 100644
--- a/frontend/src/components/SchemaEditorLite/Panels/PreviewPane.vue
+++ b/frontend/src/components/SchemaEditorLite/Panels/PreviewPane.vue
@@ -57,7 +57,6 @@ import MaskSpinner from "@/components/misc/MaskSpinner.vue";
import { useEmitteryEventListener } from "@/composables/useEmitteryEventListener";
import { databaseServiceClientConnect } from "@/grpcweb";
import type { ComposedDatabase } from "@/types";
-import type { DatabaseCatalog } from "@/types/proto-es/v1/database_catalog_service_pb";
import type {
DatabaseMetadata,
SchemaMetadata,
@@ -72,7 +71,7 @@ const props = defineProps<{
database: DatabaseMetadata;
schema: SchemaMetadata;
title: string;
- mocked: { metadata: DatabaseMetadata; catalog: DatabaseCatalog } | undefined;
+ mocked: { metadata: DatabaseMetadata } | undefined;
}>();
const { hidePreview, events } = useSchemaEditorContext();
diff --git a/frontend/src/components/SchemaEditorLite/Panels/TableColumnEditor/TableColumnEditor.vue b/frontend/src/components/SchemaEditorLite/Panels/TableColumnEditor/TableColumnEditor.vue
index d2a285d019..0ad9f40e76 100644
--- a/frontend/src/components/SchemaEditorLite/Panels/TableColumnEditor/TableColumnEditor.vue
+++ b/frontend/src/components/SchemaEditorLite/Panels/TableColumnEditor/TableColumnEditor.vue
@@ -110,8 +110,6 @@ const {
markEditStatus,
removeEditStatus,
getColumnStatus,
- removeColumnCatalog,
- upsertColumnCatalog,
useConsumePendingScrollToColumn,
getAllColumnsSelectionState,
updateAllColumnsSelection,
@@ -212,12 +210,6 @@ const handleDropColumn = (column: ColumnMetadata) => {
removeColumnPrimaryKey(table, column.name);
removeColumnFromAllForeignKeys(table, column.name);
- removeColumnCatalog({
- database: props.db.name,
- schema: props.schema.name,
- table: props.table.name,
- column: column.name,
- });
} else {
markColumnStatus(column, "dropped");
}
@@ -299,23 +291,6 @@ const columns = computed(() => {
"--n-text-color-disabled": "rgb(var(--color-main))",
},
"onUpdate:value": (value: string) => {
- upsertColumnCatalog(
- {
- database: props.db.name,
- schema: props.schema.name,
- table: props.table.name,
- column: column.name,
- },
- (catalog) => {
- catalog.name = value;
- }
- );
- removeColumnCatalog({
- database: props.db.name,
- schema: props.schema.name,
- table: props.table.name,
- column: column.name,
- });
const oldStatus = statusForColumn(column);
const oldName = column.name;
diff --git a/frontend/src/components/SchemaEditorLite/Panels/TableColumnEditor/components/LabelsCell.vue b/frontend/src/components/SchemaEditorLite/Panels/TableColumnEditor/components/LabelsCell.vue
deleted file mode 100644
index cb414507e5..0000000000
--- a/frontend/src/components/SchemaEditorLite/Panels/TableColumnEditor/components/LabelsCell.vue
+++ /dev/null
@@ -1,39 +0,0 @@
-<template>
- <div class="flex justify-start items-center">
- <LabelsCell :labels="columnCatalog?.labels ?? {}" :show-count="1" />
- <MiniActionButton v-if="!readonly && !disabled" @click="$emit('edit')">
- <PencilIcon class="w-3 h-3" />
- </MiniActionButton>
- </div>
-</template>
-
-<script lang="ts" setup>
-import { PencilIcon } from "lucide-vue-next";
-import { computed } from "vue";
-import { useSchemaEditorContext } from "@/components/SchemaEditorLite/context";
-import { MiniActionButton } from "@/components/v2";
-import { LabelsCell } from "@/components/v2/Model/cells";
-
-const props = defineProps<{
- database: string;
- schema: string;
- table: string;
- column: string;
- readonly?: boolean;
- disabled?: boolean;
-}>();
-defineEmits<{
- (event: "edit"): void;
-}>();
-
-const { getColumnCatalog } = useSchemaEditorContext();
-
-const columnCatalog = computed(() => {
- return getColumnCatalog({
- database: props.database,
- schema: props.schema,
- table: props.table,
- column: props.column,
- });
-});
-</script>
diff --git a/frontend/src/components/SchemaEditorLite/Panels/TableColumnEditor/components/SemanticTypeCell.vue b/frontend/src/components/SchemaEditorLite/Panels/TableColumnEditor/components/SemanticTypeCell.vue
deleted file mode 100644
index 9c6024a44d..0000000000
--- a/frontend/src/components/SchemaEditorLite/Panels/TableColumnEditor/components/SemanticTypeCell.vue
+++ /dev/null
@@ -1,61 +0,0 @@
-<template>
- <div class="flex flex-row flex-wrap whitespace-nowrap">
- <span v-if="semanticType?.title">{{ semanticType?.title }}</span>
- <span v-else class="text-control-placeholder italic">N/A</span>
- <template v-if="!readonly">
- <MiniActionButton
- v-if="semanticType"
- :disabled="disabled"
- @click.prevent="$emit('remove')"
- >
- <XIcon class="w-3 h-3" />
- </MiniActionButton>
- <MiniActionButton :disabled="disabled" @click.prevent="$emit('edit')">
- <PencilIcon class="w-3 h-3" />
- </MiniActionButton>
- </template>
- </div>
-</template>
-
-<script lang="ts" setup>
-import { PencilIcon, XIcon } from "lucide-vue-next";
-import { computed } from "vue";
-import { useSchemaEditorContext } from "@/components/SchemaEditorLite/context";
-import { MiniActionButton } from "@/components/v2";
-import type { SemanticTypeSetting_SemanticType as SemanticType } from "@/types/proto-es/v1/setting_service_pb";
-
-const props = defineProps<{
- database: string;
- schema: string;
- table: string;
- column: string;
- readonly?: boolean;
- disabled: boolean;
- semanticTypeList: SemanticType[];
-}>();
-
-defineEmits<{
- (event: "edit"): void;
- (event: "remove"): void;
-}>();
-
-const { getColumnCatalog } = useSchemaEditorContext();
-
-const columnCatalog = computed(() => {
- return getColumnCatalog({
- database: props.database,
- schema: props.schema,
- table: props.table,
- column: props.column,
- });
-});
-
-const semanticType = computed(() => {
- const { semanticTypeList } = props;
- const catalog = columnCatalog.value;
- if (!catalog?.semanticType) {
- return;
- }
- return semanticTypeList.find((data) => data.id === catalog.semanticType);
-});
-</script>
diff --git a/frontend/src/components/SchemaEditorLite/Panels/TableColumnEditor/components/index.ts b/frontend/src/components/SchemaEditorLite/Panels/TableColumnEditor/components/index.ts
index 63276dbcfb..4d405a90af 100644
--- a/frontend/src/components/SchemaEditorLite/Panels/TableColumnEditor/components/index.ts
+++ b/frontend/src/components/SchemaEditorLite/Panels/TableColumnEditor/components/index.ts
@@ -1,11 +1,9 @@
import DataTypeCell from "./DataTypeCell.vue";
import DefaultValueCell from "./DefaultValueCell.vue";
import ForeignKeyCell from "./ForeignKeyCell.vue";
-import LabelsCell from "./LabelsCell.vue";
import OperationCell from "./OperationCell.vue";
import ReorderCell from "./ReorderCell.vue";
import SelectionCell from "./SelectionCell.vue";
-import SemanticTypeCell from "./SemanticTypeCell.vue";
export {
ReorderCell,
@@ -14,6 +12,4 @@ export {
DefaultValueCell,
ForeignKeyCell,
OperationCell,
- SemanticTypeCell,
- LabelsCell,
};
diff --git a/frontend/src/components/SchemaEditorLite/Panels/TableEditor.vue b/frontend/src/components/SchemaEditorLite/Panels/TableEditor.vue
index 96d2bb977b..b83e444fc6 100644
--- a/frontend/src/components/SchemaEditorLite/Panels/TableEditor.vue
+++ b/frontend/src/components/SchemaEditorLite/Panels/TableEditor.vue
@@ -163,10 +163,6 @@ import { computed, reactive, ref } from "vue";
import { IndexIcon, TablePartitionIcon } from "@/components/Icon";
import type { ComposedDatabase } from "@/types";
import { Engine } from "@/types/proto-es/v1/common_pb";
-import {
- DatabaseCatalogSchema,
- SchemaCatalogSchema,
-} from "@/types/proto-es/v1/database_catalog_service_pb";
import type {
ColumnMetadata,
DatabaseMetadata,
@@ -225,7 +221,6 @@ const {
getSchemaStatus,
getTableStatus,
getColumnStatus,
- getDatabaseCatalog,
queuePendingScrollToColumn,
selectionEnabled,
} = useSchemaEditorContext();
@@ -438,7 +433,6 @@ const handleEditColumnForeignKey = (
const mocked = computed(() => {
const { db, database, schema, table } = props;
- const databaseCatalog = getDatabaseCatalog(db.name);
const mockedTable = cloneDeep(table);
mockedTable.columns = mockedTable.columns.filter((column) => {
@@ -459,24 +453,7 @@ const mocked = computed(() => {
},
],
});
- const mockedCatalog = create(DatabaseCatalogSchema, {
- name: database.name,
- });
- const schemaCatalog = databaseCatalog.schemas.find(
- (sc) => sc.name === schema.name
- );
- const tableCatalog = schemaCatalog?.tables.find(
- (tc) => tc.name === table.name
- );
- if (schemaCatalog && tableCatalog) {
- mockedCatalog.schemas = [
- create(SchemaCatalogSchema, {
- ...schemaCatalog,
- tables: [cloneDeep(tableCatalog)],
- }),
- ];
- }
- return { metadata: mockedDatabase, catalog: mockedCatalog };
+ return { metadata: mockedDatabase };
});
const markTableStatus = (status: EditStatus) => {
diff --git a/frontend/src/components/SchemaEditorLite/Panels/ViewEditor.vue b/frontend/src/components/SchemaEditorLite/Panels/ViewEditor.vue
index 3ff95a69c4..20b8e0884b 100644
--- a/frontend/src/components/SchemaEditorLite/Panels/ViewEditor.vue
+++ b/frontend/src/components/SchemaEditorLite/Panels/ViewEditor.vue
@@ -41,13 +41,8 @@ const props = defineProps<{
view: ViewMetadata;
}>();
-const {
- readonly,
- markEditStatus,
- getDatabaseCatalog,
- getSchemaStatus,
- getViewStatus,
-} = useSchemaEditorContext();
+const { readonly, markEditStatus, getSchemaStatus, getViewStatus } =
+ useSchemaEditorContext();
const statusForSchema = () => {
return getSchemaStatus(props.db, {
@@ -80,7 +75,6 @@ const disallowChangeView = computed(() => {
const mocked = computed(() => {
const { database, schema, view } = props;
- const databaseCatalog = getDatabaseCatalog(database.name);
const mockedView = cloneDeep(view);
const mockedDatabase = create(DatabaseMetadataSchema, {
@@ -94,9 +88,8 @@ const mocked = computed(() => {
},
],
});
- const mockedCatalog = cloneDeep(databaseCatalog);
- return { metadata: mockedDatabase, catalog: mockedCatalog };
+ return { metadata: mockedDatabase };
});
const handleUpdateDefinition = (code: string) => {
diff --git a/frontend/src/components/SchemaEditorLite/algorithm/apply.ts b/frontend/src/components/SchemaEditorLite/algorithm/apply.ts
index fbc1d25a70..3c73089412 100644
--- a/frontend/src/components/SchemaEditorLite/algorithm/apply.ts
+++ b/frontend/src/components/SchemaEditorLite/algorithm/apply.ts
@@ -1,9 +1,7 @@
import { cloneDeep } from "lodash-es";
import type { ComposedDatabase } from "@/types";
-import type { DatabaseCatalog } from "@/types/proto-es/v1/database_catalog_service_pb";
import type { DatabaseMetadata } from "@/types/proto-es/v1/database_service_pb";
import type { SchemaEditorContext } from "../context";
-import { cleanupUnusedCatalog } from "./utils";
export const useApplyMetadataEdit = (context: SchemaEditorContext) => {
const {
@@ -17,8 +15,7 @@ export const useApplyMetadataEdit = (context: SchemaEditorContext) => {
const applyMetadataEdit = (
database: ComposedDatabase,
- metadata: DatabaseMetadata,
- catalog: DatabaseCatalog
+ metadata: DatabaseMetadata
) => {
const response = cloneDeep(metadata);
// Drop schemas
@@ -71,9 +68,7 @@ export const useApplyMetadataEdit = (context: SchemaEditorContext) => {
});
});
- const updatedCatalog = cleanupUnusedCatalog(response, catalog);
-
- return { metadata: response, catalog: updatedCatalog };
+ return { metadata: response };
};
return { applyMetadataEdit };
diff --git a/frontend/src/components/SchemaEditorLite/algorithm/diff-merge.ts b/frontend/src/components/SchemaEditorLite/algorithm/diff-merge.ts
index bfeb722d72..87d2b4bd14 100644
--- a/frontend/src/components/SchemaEditorLite/algorithm/diff-merge.ts
+++ b/frontend/src/components/SchemaEditorLite/algorithm/diff-merge.ts
@@ -1,18 +1,5 @@
-import { create } from "@bufbuild/protobuf";
import { cloneDeep, isEqual, pick } from "lodash-es";
import type { ComposedDatabase } from "@/types";
-import type {
- ColumnCatalog,
- DatabaseCatalog,
- SchemaCatalog,
- TableCatalog,
-} from "@/types/proto-es/v1/database_catalog_service_pb";
-import {
- ColumnCatalogSchema,
- SchemaCatalogSchema,
- TableCatalog_ColumnsSchema,
- TableCatalogSchema,
-} from "@/types/proto-es/v1/database_catalog_service_pb";
import type {
FunctionMetadata,
ProcedureMetadata,
@@ -55,8 +42,6 @@ export class DiffMerge {
database: ComposedDatabase;
sourceMetadata: DatabaseMetadata;
targetMetadata: DatabaseMetadata;
- sourceCatalog: DatabaseCatalog;
- targetCatalog: DatabaseCatalog;
sourceSchemaMap = new Map<string, SchemaMetadata>();
targetSchemaMap = new Map<string, SchemaMetadata>();
sourceTableMap = new Map<string, TableMetadata>();
@@ -69,12 +54,6 @@ export class DiffMerge {
targetProcedureMap = new Map<string, ProcedureMetadata>();
sourceFunctionMap = new Map<string, FunctionMetadata>();
targetFunctionMap = new Map<string, FunctionMetadata>();
- sourceSchemaCatalogMap = new Map<string, SchemaCatalog>();
- targetSchemaCatalogMap = new Map<string, SchemaCatalog>();
- sourceTableCatalogMap = new Map<string, TableCatalog>();
- targetTableCatalogMap = new Map<string, TableCatalog>();
- sourceColumnCatalogMap = new Map<string, ColumnCatalog>();
- targetColumnCatalogMap = new Map<string, ColumnCatalog>();
timer = new TinyTimer<
| "merge"
| "mergeSchemas"
@@ -85,37 +64,26 @@ export class DiffMerge {
| "mergeViews"
| "mergeProcedures"
| "mergeFunctions"
- | "mergeSchemaCatalog"
- | "mergeTableCatalog"
- | "mergeColumnCatalog"
- | "diffColumnCatalog"
>("DiffMerge");
constructor({
context,
database,
sourceMetadata,
targetMetadata,
- sourceCatalog,
- targetCatalog,
}: {
context: SchemaEditorContext;
database: ComposedDatabase;
sourceMetadata: DatabaseMetadata;
targetMetadata: DatabaseMetadata;
- sourceCatalog: DatabaseCatalog;
- targetCatalog: DatabaseCatalog;
}) {
this.context = context;
this.database = database;
this.sourceMetadata = sourceMetadata;
this.targetMetadata = targetMetadata;
- this.sourceCatalog = sourceCatalog;
- this.targetCatalog = targetCatalog;
}
merge() {
this.timer.begin("merge");
this.mergeSchemas();
- this.mergeSchemaCatalog();
this.timer.end("merge");
}
mergeSchemas() {
@@ -712,229 +680,6 @@ export class DiffMerge {
sourceFunctions.length + targetFunctions.length
);
}
- mergeSchemaCatalog() {
- const {
- context,
- database,
- sourceCatalog,
- targetCatalog,
- targetMetadata,
- sourceSchemaCatalogMap,
- targetSchemaCatalogMap,
- } = this;
- this.timer.begin("mergeSchemaCatalog");
- mapSchemaCatalog({
- database: database.name,
- schemas: sourceCatalog.schemas,
- map: sourceSchemaCatalogMap,
- });
- mapSchemaCatalog({
- database: database.name,
- schemas: targetCatalog.schemas,
- map: targetSchemaCatalogMap,
- });
- const mergedSchemaCatalogs: SchemaCatalog[] = [];
- for (let i = 0; i < targetMetadata.schemas.length; i++) {
- const schema = targetMetadata.schemas[i];
- const key = keyForResourceName({
- database: database.name,
- schema: schema.name,
- });
- const sourceSchemaCatalog = sourceSchemaCatalogMap.get(key);
- const targetSchemaCatalog = targetSchemaCatalogMap.get(key);
- const schemaStatus = context.getEditStatusByKey(key);
- if (schemaStatus === "dropped") {
- // copy source schema catalog for further restoring
- if (sourceSchemaCatalog) {
- mergedSchemaCatalogs.push(cloneDeep(sourceSchemaCatalog));
- }
- } else if (schemaStatus === "created") {
- // use newly created schema catalog
- if (targetSchemaCatalog) {
- mergedSchemaCatalogs.push(targetSchemaCatalog);
- }
- } else {
- // use the updated schema catalog and diff recursively
- if (targetSchemaCatalog) {
- mergedSchemaCatalogs.push(targetSchemaCatalog);
- }
- this.mergeTableCatalog(
- schema,
- sourceSchemaCatalog ??
- create(SchemaCatalogSchema, { name: schema.name }),
- targetSchemaCatalog ??
- create(SchemaCatalogSchema, { name: schema.name })
- );
- }
- }
- targetCatalog.schemas = mergedSchemaCatalogs;
- this.timer.end("mergeSchemaCatalog", targetCatalog.schemas.length);
- }
- mergeTableCatalog(
- schema: SchemaMetadata,
- source: SchemaCatalog,
- target: SchemaCatalog
- ) {
- const { context, database, sourceTableCatalogMap, targetTableCatalogMap } =
- this;
- this.timer.begin("mergeTableCatalog");
- mapTableCatalog({
- database: database.name,
- schema: source.name,
- tables: source.tables,
- map: sourceTableCatalogMap,
- });
- mapTableCatalog({
- database: database.name,
- schema: target.name,
- tables: target.tables,
- map: targetTableCatalogMap,
- });
- const mergedTableCatalogs: TableCatalog[] = [];
- for (let i = 0; i < schema.tables.length; i++) {
- const table = schema.tables[i];
- const key = keyForResourceName({
- database: database.name,
- schema: schema.name,
- table: table.name,
- });
- const sourceTableCatalog = sourceTableCatalogMap.get(key);
- const targetTableCatalog = targetTableCatalogMap.get(key);
- const tableStatus = context.getEditStatusByKey(key);
- if (tableStatus === "dropped") {
- // copy source table catalog for further restoring
- if (sourceTableCatalog) {
- mergedTableCatalogs.push(cloneDeep(sourceTableCatalog));
- }
- } else if (tableStatus === "created") {
- // use newly created table catalog
- if (targetTableCatalog) {
- mergedTableCatalogs.push(targetTableCatalog);
- }
- } else {
- // use the updated table catalog and diff recursively
- if (targetTableCatalog) {
- mergedTableCatalogs.push(targetTableCatalog);
- }
- this.mergeColumnCatalog(
- schema.name,
- table,
- sourceTableCatalog ??
- create(TableCatalogSchema, {
- name: table.name,
- kind: {
- case: "columns",
- value: create(TableCatalog_ColumnsSchema, {}),
- },
- }),
- targetTableCatalog ??
- create(TableCatalogSchema, {
- name: table.name,
- kind: {
- case: "columns",
- value: create(TableCatalog_ColumnsSchema, {}),
- },
- })
- );
- }
- }
- target.tables = mergedTableCatalogs;
- this.timer.end("mergeTableCatalog", schema.tables.length);
- }
- mergeColumnCatalog(
- schema: string,
- table: TableMetadata,
- source: TableCatalog,
- target: TableCatalog
- ) {
- const {
- context,
- database,
- sourceColumnCatalogMap,
- targetColumnCatalogMap,
- } = this;
- this.timer.begin("mergeColumnCatalog");
- mapColumnCatalog({
- database: database.name,
- schema,
- table: table.name,
- columns: source.kind?.case === "columns" ? source.kind.value.columns : [],
- map: sourceColumnCatalogMap,
- });
- mapColumnCatalog({
- database: database.name,
- schema,
- table: table.name,
- columns: target.kind?.case === "columns" ? target.kind.value.columns : [],
- map: targetColumnCatalogMap,
- });
- const mergedColumnCatalogs: ColumnCatalog[] = [];
- for (let i = 0; i < table.columns.length; i++) {
- const column = table.columns[i];
- const key = keyForResourceName({
- database: database.name,
- schema,
- table: table.name,
- column: column.name,
- });
- const sourceColumnCatalog = sourceColumnCatalogMap.get(key);
- const targetColumnCatalog = targetColumnCatalogMap.get(key);
- const columnStatus = context.getEditStatusByKey(key);
- if (columnStatus === "dropped") {
- // copy source column catalog for further restoring
- if (sourceColumnCatalog) {
- mergedColumnCatalogs.push(cloneDeep(sourceColumnCatalog));
- }
- } else if (columnStatus === "created") {
- // use newly created column catalog
- if (targetColumnCatalog) {
- mergedColumnCatalogs.push(targetColumnCatalog);
- }
- } else {
- // use the updated column catalog and diff recursively
- if (targetColumnCatalog) {
- mergedColumnCatalogs.push(targetColumnCatalog);
- }
- this.diffColumnCatalog(
- schema,
- table.name,
- sourceColumnCatalog ??
- create(ColumnCatalogSchema, { name: column.name }),
- targetColumnCatalog ??
- create(ColumnCatalogSchema, { name: column.name })
- );
- }
- }
- target.kind = {
- case: "columns",
- value: create(TableCatalog_ColumnsSchema, {
- columns: mergedColumnCatalogs,
- }),
- };
- this.timer.end("mergeColumnCatalog", table.columns.length);
- }
- diffColumnCatalog(
- schema: string,
- table: string,
- source: ColumnCatalog,
- target: ColumnCatalog
- ) {
- this.timer.begin("diffColumnCatalog");
-
- if (!isEqual(source, target)) {
- const key = keyForResourceName({
- database: this.database.name,
- schema,
- table,
- column: target.name,
- });
- const status = this.context.getEditStatusByKey(key);
- if (status !== "created" && status !== "dropped") {
- this.context.markEditStatusByKey(key, "updated");
- }
- }
- this.timer.end("diffColumnCatalog", 1);
- }
}
// database schema
@@ -1045,64 +790,3 @@ const mapFunctions = (
map.set(key, fn);
});
};
-// database catalog
-const mapSchemaCatalog = ({
- database,
- schemas,
- map,
-}: {
- database: string;
- schemas: SchemaCatalog[];
- map: Map<string, SchemaCatalog>;
-}) => {
- schemas.forEach((schemaCatalog) => {
- const key = keyForResourceName({
- database,
- schema: schemaCatalog.name,
- });
- map.set(key, schemaCatalog);
- });
-};
-const mapTableCatalog = ({
- database,
- schema,
- tables,
- map,
-}: {
- database: string;
- schema: string;
- tables: TableCatalog[];
- map: Map<string, TableCatalog>;
-}) => {
- tables.forEach((tableCatalog) => {
- const key = keyForResourceName({
- database,
- schema,
- table: tableCatalog.name,
- });
- map.set(key, tableCatalog);
- });
-};
-const mapColumnCatalog = ({
- database,
- schema,
- table,
- columns,
- map,
-}: {
- database: string;
- schema: string;
- table: string;
- columns: ColumnCatalog[];
- map: Map<string, ColumnCatalog>;
-}) => {
- columns.forEach((columnCatalog) => {
- const key = keyForResourceName({
- database,
- schema,
- table,
- column: columnCatalog.name,
- });
- map.set(key, columnCatalog);
- });
-};
diff --git a/frontend/src/components/SchemaEditorLite/algorithm/rebuild.ts b/frontend/src/components/SchemaEditorLite/algorithm/rebuild.ts
index eeeb6ec5e7..b5acd0f673 100644
--- a/frontend/src/components/SchemaEditorLite/algorithm/rebuild.ts
+++ b/frontend/src/components/SchemaEditorLite/algorithm/rebuild.ts
@@ -14,15 +14,12 @@ export const useRebuildMetadataEdit = (context: SchemaEditorContext) => {
) => {
clearEditStatus();
- const { database, catalog, baselineCatalog, metadata, baselineMetadata } =
- target;
+ const { database, metadata, baselineMetadata } = target;
const dm = new DiffMerge({
context,
database,
sourceMetadata: baselineMetadata,
targetMetadata: metadata,
- sourceCatalog: baselineCatalog,
- targetCatalog: catalog,
});
dm.merge();
dm.timer.printAll();
diff --git a/frontend/src/components/SchemaEditorLite/context/config.ts b/frontend/src/components/SchemaEditorLite/context/config.ts
deleted file mode 100644
index f1ffd29a3a..0000000000
--- a/frontend/src/components/SchemaEditorLite/context/config.ts
+++ /dev/null
@@ -1,325 +0,0 @@
-import { create } from "@bufbuild/protobuf";
-import type { Ref } from "vue";
-import { reactive, watch } from "vue";
-import type {
- ColumnCatalog,
- DatabaseCatalog,
- TableCatalog,
-} from "@/types/proto-es/v1/database_catalog_service_pb";
-import {
- ColumnCatalogSchema,
- DatabaseCatalogSchema,
- SchemaCatalogSchema,
- TableCatalog_ColumnsSchema,
- TableCatalogSchema,
-} from "@/types/proto-es/v1/database_catalog_service_pb";
-import { keyForResourceName } from "./common";
-
-export const useEditCatalogs = (
- targets: Ref<{ database: string; catalog: DatabaseCatalog }[]>
-) => {
- // Build maps from keys to metadata objects for acceleration
- const buildMaps = (
- targets: { database: string; catalog: DatabaseCatalog }[]
- ) => {
- const databaseCatalog = reactive(
- new Map(
- targets.map((target) => {
- const key = keyForResourceName({
- database: target.database,
- });
- return [key, target.catalog];
- })
- )
- );
- const tableCatalog = reactive(
- new Map(
- targets.flatMap((target) => {
- return target.catalog.schemas.flatMap((schemaCatalog) => {
- return schemaCatalog.tables.map((tableCatalog) => {
- const key = keyForResourceName({
- database: target.database,
- schema: schemaCatalog.name,
- table: tableCatalog.name,
- });
- return [key, tableCatalog];
- });
- });
- })
- )
- );
- const columnCatalog = reactive(
- new Map(
- targets.flatMap((target) => {
- return target.catalog.schemas.flatMap((schemaCatalog) => {
- return schemaCatalog.tables.flatMap((tableCatalog) => {
- return (
- tableCatalog.kind?.case === "columns"
- ? tableCatalog.kind.value.columns
- : []
- ).map((columnCatalog) => {
- const key = keyForResourceName({
- database: target.database,
- schema: schemaCatalog.name,
- table: tableCatalog.name,
- column: columnCatalog.name,
- });
- return [key, columnCatalog];
- });
- });
- });
- })
- )
- );
- return { databaseCatalog, tableCatalog, columnCatalog };
- };
-
- const maps = reactive(buildMaps(targets.value));
- watch(
- targets,
- (targets) => {
- Object.assign(maps, buildMaps(targets));
- },
- {
- deep: true,
- }
- );
-
- const getDatabaseCatalog = (database: string) => {
- const databaseKey = keyForResourceName({
- database,
- });
- let databaseCatalog = maps.databaseCatalog.get(databaseKey);
- if (!databaseCatalog) {
- databaseCatalog = create(DatabaseCatalogSchema, {
- name: database,
- });
- maps.databaseCatalog.set(databaseKey, databaseCatalog);
- }
- return databaseCatalog;
- };
-
- // Table catalog
- const getTableCatalog = ({
- database,
- schema,
- table,
- }: {
- database: string;
- schema: string;
- table: string;
- }) => {
- const key = keyForResourceName({
- database,
- schema,
- table,
- });
- return maps.tableCatalog.get(key);
- };
- const insertTableCatalog = ({
- database,
- schema,
- table,
- }: {
- database: string;
- schema: string;
- table: TableCatalog;
- }) => {
- const databaseCatalog = getDatabaseCatalog(database);
- let schemaCatalog = databaseCatalog.schemas.find(
- (sc) => sc.name === schema
- );
- if (!schemaCatalog) {
- schemaCatalog = create(SchemaCatalogSchema, {
- name: schema,
- tables: [],
- });
- databaseCatalog.schemas.push(schemaCatalog);
- }
- schemaCatalog.tables.push(table);
-
- const key = keyForResourceName({
- database,
- schema,
- table: table.name,
- });
- maps.tableCatalog.set(key, table);
- };
- const removeTableCatalog = ({
- database,
- schema,
- table,
- }: {
- database: string;
- schema: string;
- table: string;
- }) => {
- const databaseCatalog = getDatabaseCatalog(database);
- const schemaCatalog = databaseCatalog.schemas.find(
- (sc) => sc.name === schema
- );
- if (schemaCatalog) {
- schemaCatalog.tables = schemaCatalog.tables.filter(
- (tableCatalog) => tableCatalog.name !== table
- );
- }
- };
- const upsertTableCatalog = (
- {
- database,
- schema,
- table,
- }: {
- database: string;
- schema: string;
- table: string;
- },
- update: (catalog: TableCatalog) => void
- ) => {
- let tableCatalog = getTableCatalog({
- database,
- schema,
- table,
- });
- if (!tableCatalog) {
- tableCatalog = create(TableCatalogSchema, {
- name: table,
- kind: {
- case: "columns",
- value: create(TableCatalog_ColumnsSchema, {}),
- },
- });
- insertTableCatalog({
- database,
- schema,
- table: tableCatalog,
- });
- }
- if (tableCatalog.kind?.case !== "columns") {
- tableCatalog.kind = {
- case: "columns",
- value: create(TableCatalog_ColumnsSchema, {}),
- };
- }
- update(tableCatalog);
- };
-
- // Column catalog
- const getColumnCatalog = ({
- database,
- schema,
- table,
- column,
- }: {
- database: string;
- schema: string;
- table: string;
- column: string;
- }) => {
- const key = keyForResourceName({
- database,
- schema,
- table,
- column,
- });
- return maps.columnCatalog.get(key);
- };
- const insertColumnCatalog = ({
- database,
- schema,
- table,
- column,
- }: {
- database: string;
- schema: string;
- table: string;
- column: ColumnCatalog;
- }) => {
- upsertTableCatalog(
- {
- database,
- schema,
- table,
- },
- (tableCatalog) => {
- if (tableCatalog.kind?.case === "columns") {
- tableCatalog.kind.value.columns.push(column);
- }
- }
- );
- // Need not to maintain column catalog map here
- // since `upsertTableCatalog` did this already
- };
- const removeColumnCatalog = ({
- database,
- schema,
- table,
- column,
- }: {
- database: string;
- schema: string;
- table: string;
- column: string;
- }) => {
- const tableCatalog = getTableCatalog({
- database,
- schema,
- table,
- });
- if (!tableCatalog) {
- return;
- }
- if (tableCatalog.kind?.case !== "columns") {
- tableCatalog.kind = {
- case: "columns",
- value: create(TableCatalog_ColumnsSchema, {}),
- };
- }
- tableCatalog.kind.value.columns = tableCatalog.kind.value.columns.filter(
- (columnCatalog) => columnCatalog.name !== column
- );
- };
- const upsertColumnCatalog = (
- {
- database,
- schema,
- table,
- column,
- }: {
- database: string;
- schema: string;
- table: string;
- column: string;
- },
- update: (catalog: ColumnCatalog) => void
- ) => {
- let columnCatalog = getColumnCatalog({
- database,
- schema,
- table,
- column,
- });
- if (!columnCatalog) {
- columnCatalog = create(ColumnCatalogSchema, {
- name: column,
- });
- insertColumnCatalog({
- database,
- schema,
- table,
- column: columnCatalog,
- });
- }
- update(columnCatalog);
- };
-
- return {
- getDatabaseCatalog,
- getTableCatalog,
- upsertTableCatalog,
- removeTableCatalog,
- getColumnCatalog,
- removeColumnCatalog,
- upsertColumnCatalog,
- };
-};
diff --git a/frontend/src/components/SchemaEditorLite/context/index.ts b/frontend/src/components/SchemaEditorLite/context/index.ts
index 4643b47408..4f7e2c083f 100644
--- a/frontend/src/components/SchemaEditorLite/context/index.ts
+++ b/frontend/src/components/SchemaEditorLite/context/index.ts
@@ -1,11 +1,10 @@
import Emittery from "emittery";
import type { Ref } from "vue";
-import { inject, provide, computed } from "vue";
+import { inject, provide } from "vue";
import type { DatabaseMetadata } from "@/types/proto-es/v1/database_service_pb";
import type { Project } from "@/types/proto-es/v1/project_service_pb";
import type { RebuildMetadataEditReset } from "../algorithm/rebuild";
import type { EditTarget, RolloutObject } from "../types";
-import { useEditCatalogs } from "./config";
import { useEditStatus } from "./edit";
import { useScrollStatus } from "./scroll";
import { useSelection } from "./selection";
@@ -44,14 +43,6 @@ export const provideSchemaEditorContext = (params: {
...params,
...useTabs(events),
...useEditStatus(),
- ...useEditCatalogs(
- computed(() =>
- params.targets.value.map((target) => ({
- database: target.database.name,
- catalog: target.catalog,
- }))
- )
- ),
...useScrollStatus(),
...useSelection(params.selectedRolloutObjects, events),
};
diff --git a/frontend/src/components/SchemaEditorLite/types.ts b/frontend/src/components/SchemaEditorLite/types.ts
index b4cee01bca..7cde253a7c 100644
--- a/frontend/src/components/SchemaEditorLite/types.ts
+++ b/frontend/src/components/SchemaEditorLite/types.ts
@@ -1,5 +1,4 @@
import type { ComposedDatabase } from "@/types";
-import type { DatabaseCatalog } from "@/types/proto-es/v1/database_catalog_service_pb";
import type {
ColumnMetadata,
DatabaseMetadata,
@@ -14,8 +13,6 @@ export type EditTarget = {
database: ComposedDatabase;
metadata: DatabaseMetadata;
baselineMetadata: DatabaseMetadata;
- catalog: DatabaseCatalog;
- baselineCatalog: DatabaseCatalog;
};
export type TabType = "database" | "table" | "view" | "procedure" | "function";