feat(diff): manual table mapping for schema compare
This commit is contained in:
1 parent
d5a511b719
commit
b5fcb3a832
28 files changed
+885
-122
No files matched your search
@@ -22,7 +22,7 @@ import { loadSchemaDetails } from "@/lib/schema/schemaDiffMetadataLoad";
|
||||
import { getSchemaDiffNextProgressStep, isSchemaDiffPostgresLike, shouldLoadSchemaDiffExtraObjects, type SchemaDiffProgressPhase } from "@/lib/schema/schemaDiffProgress";
|
||||
import { createSchemaDiffTableListLoader, type SchemaDiffTableIdentity } from "@/lib/schema/schemaDiffTableList";
|
||||
import { normalizeSchemaDiffCompareOptions } from "@/types/schemaDiff";
|
||||
import type { SchemaDiffCompareOptions, SchemaDiffConfig, FieldMappingEntry } from "@/types/schemaDiff";
|
||||
import type { SchemaDiffCompareOptions, SchemaDiffConfig, FieldMappingEntry, SchemaDiffTableMapping } from "@/types/schemaDiff";
|
||||
import type { DatabaseType, ObjectSourceKind } from "@/types/database";
|
||||
import {
|
||||
convertToSchemaDiffObjects,
|
||||
@@ -54,6 +54,7 @@ import {
|
||||
normalizeSchemaDiffDependencyGraph,
|
||||
} from "@/lib/schema/schemaDiff";
|
||||
import { compileSchemaDiffTableFilter, filterSchemaDiffTables } from "@/lib/schema/schemaDiffTableFilter";
|
||||
import { swapSchemaDiffTableMappings } from "@/lib/schema/schemaDiffTableMapping";
|
||||
import { Splitpanes, Pane } from "splitpanes";
|
||||
import "splitpanes/dist/splitpanes.css";
|
||||
|
||||
@@ -409,6 +410,22 @@ function getDbType(): DatabaseType {
|
||||
}
|
||||
|
||||
function handleSwap() {
|
||||
const currentOptions = normalizeSchemaDiffCompareOptions(activeConfig.value?.options, getDbType());
|
||||
const swappedMappings = swapSchemaDiffTableMappings(currentOptions.tableMappings ?? []);
|
||||
const swappedSelectedTables = Array.isArray(currentOptions.selectedTables) ? swappedMappings.map((mapping) => mapping.sourceTable) : undefined;
|
||||
if (activeConfig.value) {
|
||||
updateActiveConfigOptions(
|
||||
normalizeSchemaDiffCompareOptions(
|
||||
{
|
||||
...currentOptions,
|
||||
selectedTables: swappedSelectedTables,
|
||||
tableMappings: swappedMappings,
|
||||
},
|
||||
getDbType(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
const tempConn = sourceConnectionId.value;
|
||||
const tempDb = sourceDatabase.value;
|
||||
const tempSchema = sourceSchema.value;
|
||||
@@ -432,6 +449,12 @@ function handleSelectedTablesUpdate(value?: string[]) {
|
||||
}
|
||||
}
|
||||
|
||||
function handleTableMappingsUpdate(value: SchemaDiffTableMapping[]) {
|
||||
if (activeConfig.value) {
|
||||
updateActiveConfigOptions(normalizeSchemaDiffCompareOptions({ ...activeConfig.value.options, tableMappings: value }, getDbType()));
|
||||
}
|
||||
}
|
||||
|
||||
function handleFieldMappingsUpdate(mappings: FieldMappingEntry[]) {
|
||||
if (activeConfig.value) {
|
||||
const updated = { ...activeConfig.value.options, fieldMappings: mappings };
|
||||
@@ -559,6 +582,10 @@ async function handleCompare() {
|
||||
targetRules: tgtRules,
|
||||
sourceOwners: srcOwners,
|
||||
targetOwners: tgtOwners,
|
||||
// Mappings only apply to an explicit table selection; the all-tables path
|
||||
// (selectedTables === undefined) must stay mapping-free so the Rust side
|
||||
// cannot reclassify added/removed tables from stale persisted mappings.
|
||||
tableMappings: opts.selectedTables === undefined ? undefined : opts.tableMappings,
|
||||
databaseType: dbType,
|
||||
targetSchema: schemaDiffDeployTargetSchema(dbType, targetDatabase.value, targetSchema.value),
|
||||
ignoreComments: ignoreComments.value,
|
||||
@@ -915,7 +942,7 @@ function handleLoadHistoryConfig(config: SchemaDiffConfig) {
|
||||
targetDatabase.value = config.targetDatabase;
|
||||
targetSchema.value = config.targetSchema;
|
||||
if (config.options) {
|
||||
updateActiveConfigOptions(config.options);
|
||||
updateActiveConfigOptions(normalizeSchemaDiffCompareOptions(config.options, getDbType()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1057,8 +1084,8 @@ const targetConnectionInfo = computed(() => {
|
||||
v-model:ignore-comments="ignoreComments"
|
||||
:configs="configs"
|
||||
:active-config-id="activeConfigId"
|
||||
:options="activeConfig?.options"
|
||||
:selected-tables="activeConfig?.options?.selectedTables"
|
||||
:options="schemaDiffPanelOptions"
|
||||
:selected-tables="schemaDiffPanelOptions.selectedTables"
|
||||
:table-list-loader="schemaDiffTableListLoader"
|
||||
:loading="loading"
|
||||
:recent-configs="recentConfigs"
|
||||
@@ -1069,6 +1096,7 @@ const targetConnectionInfo = computed(() => {
|
||||
@load-history-config="handleLoadHistoryConfig"
|
||||
@delete-history-config="handleDeleteHistoryConfig"
|
||||
@update:field-mappings="handleFieldMappingsUpdate"
|
||||
@update:table-mappings="handleTableMappingsUpdate"
|
||||
@update:selected-tables="handleSelectedTablesUpdate"
|
||||
@open-field-mapping="showFieldMappingDialog = true"
|
||||
/>
|
||||
|
||||
Reference in new issue
Block a user