{
- if (!sourceConnectionId.value || !sourceDatabase.value || !sourceSchema.value || !table) return [];
- const columns = sourceColumnCache ? await loadColumnsWithCache(sourceColumnCache, sourceConnectionId.value, sourceDatabase.value, sourceSchema.value, table) : (((await api.getColumns(sourceConnectionId.value, sourceDatabase.value, sourceSchema.value, table)) as CompareColumn[]) ?? []);
- return inferCompareKeyColumns(columns);
-}
-
-async function inferKeyColumns() {
- const table = selectedSourceTableNames.value.length === 1 ? selectedSourceTableNames.value[0] : "";
- if (!table) return;
- const inferred = await inferKeyColumnsForTable(table);
- keyColumnsText.value = inferred.join(", ");
-}
-
function resultStatusLabel(status: DataCompareTableStatus): string {
if (status === "different") return t("dataCompare.statusDifferent");
if (status === "same") return t("dataCompare.statusSame");
@@ -535,7 +720,7 @@ function startCompare(): void {
targetSchemas: [...targetSchemas.value],
targetTables: [...targetTables.value],
targetTable: targetTable.value,
- keyColumns: [...keyColumns.value],
+ keyColumnsByTable: buildSessionKeyColumnsByTable(),
label: `${comparisonEndpointLabel(sourceConnectionId.value, sourceDatabase.value, sourceSchema.value)} → ${comparisonEndpointLabel(targetConnectionId.value, targetDatabase.value, targetSchema.value)}`,
},
tasks,
@@ -651,6 +836,8 @@ watch(sourceConnectionId, (id) => {
sourceTables.value = [];
sourceTable.value = "";
resetSelectedSourceTables([]);
+ // Column metadata and match columns belong to the previous source endpoint.
+ resetTableColumnMetadata();
loadDatabases(id, "source").catch((e) => toast(String(e), 5000));
});
watch(targetConnectionId, (id) => {
@@ -671,6 +858,7 @@ watch(sourceDatabase, () => {
sourceTables.value = [];
sourceTable.value = "";
resetSelectedSourceTables([]);
+ resetTableColumnMetadata();
loadSchemas("source", props.prefillSchema).catch((e) => toast(String(e), 5000));
});
watch(targetDatabase, () => {
@@ -688,6 +876,7 @@ watch(sourceSchema, () => {
sourceTables.value = [];
sourceTable.value = "";
resetSelectedSourceTables([]);
+ resetTableColumnMetadata();
if (sourceSchema.value) loadTables("source").catch((e) => toast(String(e), 5000));
});
watch(targetSchema, () => {
@@ -700,9 +889,12 @@ watch(targetSchema, () => {
watch(selectedSourceTableNames, (tables, previous) => {
if (initializingPrefill) return;
clearResult();
+ // Drop the match columns and metadata of tables that are no longer compared,
+ // so a table that is selected again starts from its own primary key.
+ pruneKeyColumnState(tables);
sourceTable.value = tables.length === 1 ? tables[0] : "";
if (tables.length !== 1) {
- keyColumnsText.value = "";
+ void prefetchSelectedTableColumns(tables);
return;
}
const table = tables[0];
@@ -711,10 +903,7 @@ watch(selectedSourceTableNames, (tables, previous) => {
} else if (previous?.length === 1 && targetTable.value === previous[0]) {
targetTable.value = "";
}
- if (table !== previous?.[0]) {
- keyColumnsText.value = "";
- }
- inferKeyColumns().catch(() => {});
+ void prefetchSelectedTableColumns(tables);
});
watch(targetTable, () => {
if (initializingPrefill) return;
@@ -748,6 +937,7 @@ watch(
if (sourceTables.value.includes(props.prefillTable)) {
resetSelectedSourceTables([props.prefillTable]);
sourceTable.value = props.prefillTable;
+ await loadTableColumns(props.prefillTable);
}
}
} finally {
@@ -917,10 +1107,59 @@ onBeforeUnmount(() => {
-
-
-
- {{ t("dataCompare.keyColumnsAutoHint") }}
+
+
+
+ {{ singleKeyColumnRow.manual ? t("dataCompare.keyColumnsStatusManual") : t("dataCompare.keyColumnsStatusAuto") }}
+
+
+
+
+
+ {{ t("dataCompare.keyColumnsSelectTableHint") }}
+
+
+
+
+
setTableKeyColumns(singleKeyColumnRow!.table, columns)" />
+
+ {{ singleKeyColumnRow.hint }}
+
+
+
+
+
+
+
+ {{ t("dataCompare.keyColumnsPerTableHint") }}
+
+
+
+
+
+
setTableKeyColumns(row.table, columns)" />
+
+ {{ row.hint }}
+
+
+
+
+
+
diff --git a/apps/desktop/src/components/diff/TableMultiSelect.vue b/apps/desktop/src/components/diff/TableMultiSelect.vue
index 92648930bb..beb216f85a 100644
--- a/apps/desktop/src/components/diff/TableMultiSelect.vue
+++ b/apps/desktop/src/components/diff/TableMultiSelect.vue
@@ -79,7 +79,7 @@ function toggleSelectAll() {
{{ emptyText || t("tableMultiSelect.noTables") }}
-