feat(schema-diff): named config selector and mapping UX

This commit is contained in:
Mo-Moore authored and GitHub committed 2026-09-14 12:37:39 +08:00
1 parent 2808996526
commit 18e34bf33a
15 files changed
+282 -15

No files matched your search

@@ -46,6 +46,22 @@ describe("schema diff table mappings", () => {
expect(buildSchemaDiffTableMatches(["a"], ["a", "a_new"], [{ sourceTable: "a", targetTable: "a_new" }])).toEqual([{ sourceTable: "a", targetTable: "a_new", kind: "manual" }]);
});
it("treats reconciled same-name mappings as automatic", () => {
expect(
buildSchemaDiffTableMatches(
["a", "b"],
["a", "b"],
[
{ sourceTable: "a", targetTable: "a" },
{ sourceTable: "b", targetTable: "b" },
],
),
).toEqual([
{ sourceTable: "a", targetTable: "a", kind: "automatic" },
{ sourceTable: "b", targetTable: "b", kind: "automatic" },
]);
});
it("removes mappings for deselected sources and automatically matches new sources", () => {
const mappings = [
{ sourceTable: "a", targetTable: "a" },
@@ -90,13 +90,13 @@ export function reconcileSchemaDiffTableMappings(selectedTables: readonly string
export function buildSchemaDiffTableMatches(selectedTables: readonly string[], targetTables: readonly string[], mappings: readonly SchemaDiffTableMapping[], ignoreTableNameCase = false): SchemaDiffTableMatch[] {
const reconciled = reconcileSchemaDiffTableMappings(selectedTables, targetTables, mappings, ignoreTableNameCase);
const targetBySource = new Map(reconciled.map((mapping) => [mapping.sourceTable, mapping.targetTable]));
const explicitSources = new Set(firstMappingBySource(mappings).keys());
return selectedTables.map((sourceTable) => {
const targetTable = targetBySource.get(sourceTable);
let kind: SchemaDiffTableMatchKind;
if (!targetTable) kind = "unmatched";
else if (!explicitSources.has(sourceTable) && identifiersEqual(targetTable, sourceTable, ignoreTableNameCase)) kind = "automatic";
// Same-name (incl. ignore-case) stays automatic even after reconcile persists the pair in mappings.
else if (identifiersEqual(targetTable, sourceTable, ignoreTableNameCase)) kind = "automatic";
else kind = "manual";
return { sourceTable, targetTable, kind };
});