Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

feat(diff): show schema comparison progress and next step

skyler1d71a5fc230d
diff --git a/apps/desktop/src/components/diff/SchemaDiffDialog.vue b/apps/desktop/src/components/diff/SchemaDiffDialog.vue
index 3b367b3e58..c486059f61 100644
--- a/apps/desktop/src/components/diff/SchemaDiffDialog.vue
+++ b/apps/desktop/src/components/diff/SchemaDiffDialog.vue
@@ -18,11 +18,12 @@ import SchemaDiffOptionsPanel from "@/components/diff/SchemaDiffOptionsPanel.vue
import { getSchemaDiffOptionsForDbType } from "@/lib/schema/schemaDiffOptions";
import { buildDeployTxResult } from "@/lib/schema/deployTxResult";
-import { createConcurrencyLimiter, mapWithConcurrency, schemaDiffMetadataConcurrency, schemaDiffMetadataLoadPlan } from "@/lib/schema/schemaDiffMetadataLoad";
+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 { DatabaseType, ObjectSourceKind, TableInfo } from "@/types/database";
+import type { DatabaseType, ObjectSourceKind } from "@/types/database";
import {
convertToSchemaDiffObjects,
detectDestructiveSchemaDiffStatements,
@@ -46,13 +47,12 @@ import {
type SchemaDiffPreparation,
type MissingRollbackObject,
type RollbackCompleteness,
- type TableSchemaDetail,
type RenameCandidate,
type CompatibilityWarning,
type PermissionDiff,
type DependencyGraph,
} from "@/lib/schema/schemaDiff";
-import { compileSchemaDiffTableFilter, filterSchemaDiffTables, isSchemaDiffView } from "@/lib/schema/schemaDiffTableFilter";
+import { compileSchemaDiffTableFilter, filterSchemaDiffTables } from "@/lib/schema/schemaDiffTableFilter";
import { Splitpanes, Pane } from "splitpanes";
import "splitpanes/dist/splitpanes.css";
@@ -105,7 +105,17 @@ const optionTree = computed(() => {
});
// Compare state
+interface SchemaDiffProgress {
+ phase: SchemaDiffProgressPhase;
+ current?: number;
+ total?: number;
+ objectName?: string;
+}
+
const loading = ref(false);
+const schemaDiffProgress = ref<SchemaDiffProgress | null>(null);
+const schemaDiffHasExtraObjectPhase = ref(false);
+let comparisonRequestId = 0;
const diffObjects = ref<SchemaDiffObject[]>([]);
const diffGroups = ref<OperationGroup[]>([]);
const selectedObjectId = ref<string | null>(null);
@@ -278,9 +288,47 @@ const canDeploy = computed(() => {
return selectedSchemaDiffObjects(diffObjects.value).length > 0;
});
+const schemaDiffProgressCount = computed(() => {
+ const progress = schemaDiffProgress.value;
+ return progress && progress.total !== undefined && progress.total > 0 && progress.current !== undefined ? { current: progress.current, total: progress.total } : null;
+});
+
+const schemaDiffProgressPercent = computed(() => {
+ const count = schemaDiffProgressCount.value;
+ return count ? Math.min(100, Math.round((count.current / count.total) * 100)) : null;
+});
+
+const schemaDiffProgressLabel = computed(() => {
+ switch (schemaDiffProgress.value?.phase) {
+ case "loading-table-lists":
+ return t("diff.progress.loadingObjects");
+ case "loading-source-details":
+ return t("diff.progress.loadingSourceDetails");
+ case "loading-target-details":
+ return t("diff.progress.loadingTargetDetails");
+ case "loading-extra-objects":
+ return t("diff.progress.loadingExtraObjects");
+ case "comparing":
+ return t("diff.progress.comparing");
+ case "generating":
+ return t("diff.progress.generating");
+ default:
+ return "";
+ }
+});
+
+const schemaDiffNextProgressLabel = computed(() => {
+ const nextStep = getSchemaDiffNextProgressStep(schemaDiffProgress.value?.phase, schemaDiffHasExtraObjectPhase.value);
+ return nextStep ? t("diff.progress.next", { step: t(`diff.progress.${nextStep}`) }) : "";
+});
+
function resetComparisonResultState() {
+ comparisonRequestId++;
selectedDeploySqlGeneration++;
focusedDeploySqlGeneration++;
+ loading.value = false;
+ schemaDiffProgress.value = null;
+ schemaDiffHasExtraObjectPhase.value = false;
step.value = "config";
diffObjects.value = [];
diffGroups.value = [];
@@ -320,6 +368,11 @@ watch(
sourceSchema.value = props.prefillSchema;
}
}
+ } else {
+ comparisonRequestId++;
+ loading.value = false;
+ schemaDiffProgress.value = null;
+ schemaDiffHasExtraObjectPhase.value = false;
}
},
{ immediate: true },
@@ -385,51 +438,14 @@ function handleFieldMappingsUpdate(mappings: FieldMappingEntry[]) {
}
}
-/** Map a JDBC table_type to an ObjectSourceKind for getTableDdl routing.
- * Views and materialized views need the object_type parameter so the
- * backend can call DBMS_METADATA.GET_DDL with the correct type. */
-function isViewOrMaterializedView(tableType: string): ObjectSourceKind | undefined {
- switch (tableType.toUpperCase().replace(/\s+/g, "_")) {
- case "VIEW":
- return "VIEW";
- case "MATERIALIZED_VIEW":
- return "MATERIALIZED_VIEW";
- default:
- return undefined;
- }
-}
-
-interface SchemaDetailLoadContext {
- connectionId: string;
- database: string;
- schema: string;
- dbType: string;
- options: SchemaDiffCompareOptions;
-}
-
-async function loadSchemaDetails(tables: TableInfo[], context: SchemaDetailLoadContext): Promise<TableSchemaDetail[]> {
- const concurrency = schemaDiffMetadataConcurrency(context.dbType, tables.length);
- const runMetadataQuery = createConcurrencyLimiter(concurrency);
-
- return mapWithConcurrency(tables, concurrency, async (table) => {
- const objectType = isViewOrMaterializedView(table.table_type);
- const loadPlan = schemaDiffMetadataLoadPlan(isSchemaDiffView(table), context.options);
- const ddlPromise = loadPlan.ddl ? runMetadataQuery(() => api.getTableDdl(context.connectionId, context.database, context.schema, table.name, objectType)) : Promise.resolve("");
- const [columns, indexes, foreignKeys, triggers, ddl] = await Promise.all([
- loadPlan.columns ? runMetadataQuery(() => api.getColumns(context.connectionId, context.database, context.schema, table.name)) : Promise.resolve([]),
- loadPlan.indexes ? runMetadataQuery(() => api.listIndexes(context.connectionId, context.database, context.schema, table.name)) : Promise.resolve([]),
- loadPlan.foreignKeys ? runMetadataQuery(() => api.listForeignKeys(context.connectionId, context.database, context.schema, table.name)) : Promise.resolve([]),
- loadPlan.triggers ? runMetadataQuery(() => api.listTriggers(context.connectionId, context.database, context.schema, table.name)) : Promise.resolve([]),
- ddlPromise,
- ]);
-
- return { name: table.name, columns, indexes, foreignKeys, triggers, ddl };
- });
-}
-
async function handleCompare() {
+ const requestId = ++comparisonRequestId;
+ const isCurrentRequest = () => requestId === comparisonRequestId;
+
loading.value = true;
step.value = "compare";
+ schemaDiffProgress.value = { phase: "loading-table-lists" };
+ schemaDiffHasExtraObjectPhase.value = false;
// Reset Phase 4 state to prevent stale data from previous compares
rollbackSql.value = "";
@@ -446,6 +462,9 @@ async function handleCompare() {
const dbType = targetConfig?.db_type || "mysql";
const sourceDbType = sourceConfig?.db_type || dbType;
const opts = normalizeSchemaDiffCompareOptions(activeConfig.value?.options, dbType);
+ const isPostgresLike = isSchemaDiffPostgresLike(dbType);
+ const hasExtraObjectPhase = shouldLoadSchemaDiffExtraObjects(dbType, opts);
+ schemaDiffHasExtraObjectPhase.value = hasExtraObjectPhase;
const tableFilter = compileSchemaDiffTableFilter(opts);
const sourceTableIdentity: SchemaDiffTableIdentity = { connectionId: sourceConnectionId.value, database: sourceDatabase.value, schema: sourceSchema.value };
@@ -453,28 +472,45 @@ async function handleCompare() {
// The dialog can remain open while either database changes, so Compare must not reuse
// the table list cached while configuring the comparison.
const [srcTables, tgtTables] = await Promise.all([schemaDiffTableListLoader.load(sourceTableIdentity, { refresh: true }), schemaDiffTableListLoader.load(targetTableIdentity, { refresh: true })]);
+ if (!isCurrentRequest()) return;
// Explicit (visual) table selection is applied here, BEFORE any per-table
// metadata details are loaded, so metadata requests only happen for the
// final table set. `undefined`/empty means no restriction (legacy path).
const { sourceTables, targetTables } = filterSchemaDiffTables(srcTables, tgtTables, tableFilter, opts, opts.selectedTables);
- const sourceDetails = await loadSchemaDetails(sourceTables, {
- connectionId: sourceConnectionId.value,
- database: sourceDatabase.value,
- schema: sourceSchema.value,
- dbType: sourceDbType,
- options: opts,
- });
-
- const targetDetails = await loadSchemaDetails(targetTables, {
- connectionId: targetConnectionId.value,
- database: targetDatabase.value,
- schema: targetSchema.value,
- dbType,
- options: opts,
- });
+ schemaDiffProgress.value = { phase: "loading-source-details", current: 0, total: sourceTables.length };
+ const sourceDetails = await loadSchemaDetails(
+ sourceTables,
+ {
+ connectionId: sourceConnectionId.value,
+ database: sourceDatabase.value,
+ schema: sourceSchema.value,
+ dbType: sourceDbType,
+ options: opts,
+ onProgress: (progress) => {
+ if (isCurrentRequest()) schemaDiffProgress.value = { phase: "loading-source-details", ...progress };
+ },
+ },
+ api,
+ );
+ if (!isCurrentRequest()) return;
- const isPostgresLike = dbType === "postgres" || dbType === "opengauss";
+ schemaDiffProgress.value = { phase: "loading-target-details", current: 0, total: targetTables.length };
+ const targetDetails = await loadSchemaDetails(
+ targetTables,
+ {
+ connectionId: targetConnectionId.value,
+ database: targetDatabase.value,
+ schema: targetSchema.value,
+ dbType,
+ options: opts,
+ onProgress: (progress) => {
+ if (isCurrentRequest()) schemaDiffProgress.value = { phase: "loading-target-details", ...progress };
+ },
+ },
+ api,
+ );
+ if (!isCurrentRequest()) return;
// Fetch new object types for PostgreSQL-like databases
const promises: Promise<any>[] = [];
@@ -495,7 +531,9 @@ async function handleCompare() {
promises.push(api.listOwners(targetConnectionId.value, targetDatabase.value, targetSchema.value));
}
+ if (hasExtraObjectPhase) schemaDiffProgress.value = { phase: "loading-extra-objects" };
const results = await Promise.all(promises);
+ if (!isCurrentRequest()) return;
let idx = 0;
const srcFunctions = opts?.functions && isPostgresLike ? results[idx++] : [];
const tgtFunctions = opts?.functions && isPostgresLike ? results[idx++] : [];
@@ -506,6 +544,7 @@ async function handleCompare() {
const srcOwners = opts?.owners && isPostgresLike ? results[idx++] : [];
const tgtOwners = opts?.owners && isPostgresLike ? results[idx++] : [];
+ schemaDiffProgress.value = { phase: "comparing" };
const result = await api.prepareSchemaDiff({
sourceTables,
targetTables,
@@ -545,6 +584,7 @@ async function handleCompare() {
customParams: m.customParams,
})) || [],
});
+ if (!isCurrentRequest()) return;
// Extract new result fields
rollbackSql.value = result.rollbackSyncSql ?? "";
@@ -565,15 +605,21 @@ async function handleCompare() {
// current selection projection below rather than from the initial full SQL.
lastDiffResult.value = result;
deploySqlMode.value = "forward";
+ schemaDiffProgress.value = { phase: "generating" };
await regenerateSelectedDeploySql();
await regenerateFocusedDeploySql();
+ if (!isCurrentRequest()) return;
+ schemaDiffProgress.value = null;
step.value = "result";
} catch (e: any) {
+ if (!isCurrentRequest()) return;
+ schemaDiffProgress.value = null;
+ schemaDiffHasExtraObjectPhase.value = false;
toast(e?.message || String(e), 5000);
step.value = "config";
} finally {
- loading.value = false;
+ if (isCurrentRequest()) loading.value = false;
}
}
@@ -1021,8 +1067,31 @@ const targetConnectionInfo = computed(() => {
<!-- Compare Loading -->
<div v-else-if="step === 'compare'" class="flex items-center justify-center py-20">
- <Loader2 class="w-6 h-6 animate-spin mr-2" />
- <span class="text-sm text-muted-foreground">{{ t("diff.comparing") }}</span>
+ <div class="w-full max-w-md px-6 space-y-3">
+ <div class="flex items-center justify-center gap-2 text-sm text-muted-foreground">
+ <Loader2 class="w-5 h-5 animate-spin text-primary" />
+ <span>{{ schemaDiffProgressLabel }}</span>
+ </div>
+ <div v-if="schemaDiffProgressCount" class="flex items-center justify-between text-xs tabular-nums text-muted-foreground">
+ <span>{{ t("diff.progress.count", schemaDiffProgressCount) }}</span>
+ <span>{{ schemaDiffProgressPercent }}%</span>
+ </div>
+ <div class="h-2 overflow-hidden rounded-full bg-muted" role="progressbar" :aria-label="schemaDiffProgressLabel || t('diff.progress.comparing')">
+ <div
+ v-if="schemaDiffProgressPercent !== null"
+ class="h-full rounded-full bg-primary transition-[width] duration-200"
+ :aria-valuemin="0"
+ :aria-valuemax="schemaDiffProgressCount?.total"
+ :aria-valuenow="schemaDiffProgressCount?.current"
+ :style="{ width: `${schemaDiffProgressPercent}%` }"
+ />
+ <div v-else class="h-full w-full overflow-hidden rounded-full">
+ <div class="schema-diff-progress-indeterminate h-full rounded-full bg-primary" />
+ </div>
+ </div>
+ <div v-if="schemaDiffProgress?.objectName" class="truncate text-center text-xs text-muted-foreground" :title="schemaDiffProgress.objectName">{{ schemaDiffProgress.objectName }}</div>
+ <div v-if="schemaDiffNextProgressLabel" class="text-center text-xs text-muted-foreground">{{ schemaDiffNextProgressLabel }}</div>
+ </div>
</div>
<!-- Result Step -->
@@ -1278,6 +1347,23 @@ const targetConnectionInfo = computed(() => {
</template>
<style scoped>
+.schema-diff-progress-indeterminate {
+ width: 42%;
+ animation: schema-diff-progress-slide 1.15s ease-in-out infinite;
+}
+
+@keyframes schema-diff-progress-slide {
+ 0% {
+ transform: translateX(-110%);
+ }
+ 50% {
+ transform: translateX(190%);
+ }
+ 100% {
+ transform: translateX(290%);
+ }
+}
+
:deep(.splitpanes--horizontal > .splitpanes__splitter) {
height: 8px;
background: var(--border);
diff --git a/apps/desktop/src/components/diff/__tests__/SchemaDiffDialog.spec.ts b/apps/desktop/src/components/diff/__tests__/SchemaDiffDialog.spec.ts
index 0ebf6639f5..56128a8b60 100644
--- a/apps/desktop/src/components/diff/__tests__/SchemaDiffDialog.spec.ts
+++ b/apps/desktop/src/components/diff/__tests__/SchemaDiffDialog.spec.ts
@@ -41,11 +41,46 @@ describe("SchemaDiffDialog fullscreen layout", () => {
expect(dialogSource).toMatch(/<SchemaDiffConfigStep\n[\s\S]*?class="shrink-0"/);
});
- it("clears stale result state whenever a new dialog session opens", () => {
+ it("clears stale result and progress state whenever a new dialog session opens", () => {
expect(dialogSource).toContain("function resetComparisonResultState() {");
expect(dialogSource).toMatch(/if \(isOpen\) \{\s+resetComparisonResultState\(\);/);
expect(dialogSource).toContain("diffObjects.value = [];");
expect(dialogSource).toContain("lastDiffResult.value = null;");
+ expect(dialogSource).toContain("schemaDiffProgress.value = null;");
+ });
+
+ it("shows real metadata progress and indeterminate comparison phases without fabricated percentages", () => {
+ expect(dialogSource).toContain('phase: "loading-table-lists"');
+ expect(dialogSource).toContain('phase: "loading-source-details"');
+ expect(dialogSource).toContain('phase: "loading-target-details"');
+ expect(dialogSource).toContain('phase: "loading-extra-objects"');
+ expect(dialogSource).toContain('phase: "comparing"');
+ expect(dialogSource).toContain('phase: "generating"');
+ expect(dialogSource).toContain("onProgress: (progress) =>");
+ expect(dialogSource).toContain("schemaDiffProgressCount");
+ expect(dialogSource).toContain('role="progressbar"');
+ expect(dialogSource).toContain("schema-diff-progress-indeterminate");
+ expect(dialogSource).not.toMatch(/\b(?:20|40|60|80)%/);
+ });
+
+ it("renders a localized next-step label alongside the current progress state", () => {
+ expect(dialogSource).toContain("getSchemaDiffNextProgressStep");
+ expect(dialogSource).toContain("schemaDiffNextProgressLabel");
+ expect(dialogSource).toContain('t("diff.progress.next"');
+ expect(dialogSource).toContain('v-if="schemaDiffNextProgressLabel"');
+ expect(dialogSource).toContain("shouldLoadSchemaDiffExtraObjects");
+ });
+
+ it("clears progress before preserving the existing comparison error flow", () => {
+ expect(dialogSource).toMatch(/\} catch \(e: any\) \{\s+if \(!isCurrentRequest\(\)\) return;\s+schemaDiffProgress\.value = null;/);
+ expect(dialogSource).toContain("toast(e?.message || String(e), 5000);");
+ expect(dialogSource).toContain('step.value = "config";');
+ });
+
+ it("invalidates an active comparison when the dialog closes", () => {
+ expect(dialogSource).toContain("const requestId = ++comparisonRequestId;");
+ expect(dialogSource).toContain("if (!isCurrentRequest()) return;");
+ expect(dialogSource).toMatch(/\} else \{\s+comparisonRequestId\+\+;\s+loading\.value = false;\s+schemaDiffProgress\.value = null;/);
});
it("does not restore persisted table matches before source and target identities are ready", () => {
diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.ts
index 08fc0d6909..e418fee6f1 100644
--- a/apps/desktop/src/i18n/locales/en.ts
+++ b/apps/desktop/src/i18n/locales/en.ts
@@ -5753,6 +5753,22 @@ export default {
collapseAll: "Collapse all",
},
diff: {
+ progress: {
+ loadingObjects: "Reading source and target database objects...",
+ loadingSourceDetails: "Reading source database table structures",
+ loadingTargetDetails: "Reading target database table structures",
+ loadingExtraObjects: "Reading other database objects...",
+ comparing: "Analyzing schema differences...",
+ generating: "Generating comparison result...",
+ next: "Next: {step}",
+ nextSourceDetails: "Read source database table structures",
+ nextTargetDetails: "Read target database table structures",
+ nextExtraObjects: "Read other database objects",
+ nextComparing: "Analyze schema differences",
+ nextGenerating: "Generate comparison result",
+ nextComplete: "Complete",
+ count: "{current} / {total}",
+ },
title: "Compare Schemas",
source: "Source",
target: "Target",
diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.ts
index c331ef0932..db1a6f2e44 100644
--- a/apps/desktop/src/i18n/locales/es.ts
+++ b/apps/desktop/src/i18n/locales/es.ts
@@ -5465,6 +5465,22 @@ export default withEnglishFallback({
totalFiles: "{count} archivos",
},
diff: {
+ progress: {
+ loadingObjects: "Leyendo los objetos de las bases de datos de origen y destino...",
+ loadingSourceDetails: "Leyendo la estructura de tablas de la base de datos de origen",
+ loadingTargetDetails: "Leyendo la estructura de tablas de la base de datos de destino",
+ loadingExtraObjects: "Leyendo otros objetos de la base de datos...",
+ comparing: "Analizando las diferencias del esquema...",
+ generating: "Generando el resultado de la comparación...",
+ next: "Siguiente paso: {step}",
+ nextSourceDetails: "Leer la estructura de tablas de la base de datos de origen",
+ nextTargetDetails: "Leer la estructura de tablas de la base de datos de destino",
+ nextExtraObjects: "Leer otros objetos de la base de datos",
+ nextComparing: "Analizar las diferencias del esquema",
+ nextGenerating: "Generar el resultado de la comparación",
+ nextComplete: "Completar",
+ count: "{current} / {total}",
+ },
title: "Comparar esquemas",
source: "Origen",
target: "Destino",
diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.ts
index 814d76f62a..443593bd9d 100644
--- a/apps/desktop/src/i18n/locales/it.ts
+++ b/apps/desktop/src/i18n/locales/it.ts
@@ -5465,6 +5465,22 @@ export default withEnglishFallback({
restoreSummary: "Ripristina tabella riepilogativa",
},
diff: {
+ progress: {
+ loadingObjects: "Lettura degli oggetti dei database sorgente e di destinazione...",
+ loadingSourceDetails: "Lettura della struttura delle tabelle del database sorgente",
+ loadingTargetDetails: "Lettura della struttura delle tabelle del database di destinazione",
+ loadingExtraObjects: "Lettura degli altri oggetti del database...",
+ comparing: "Analisi delle differenze dello schema...",
+ generating: "Generazione del risultato del confronto...",
+ next: "Passo successivo: {step}",
+ nextSourceDetails: "Leggere la struttura delle tabelle del database sorgente",
+ nextTargetDetails: "Leggere la struttura delle tabelle del database di destinazione",
+ nextExtraObjects: "Leggere gli altri oggetti del database",
+ nextComparing: "Analizzare le differenze dello schema",
+ nextGenerating: "Generare il risultato del confronto",
+ nextComplete: "Completare",
+ count: "{current} / {total}",
+ },
title: "Confronta Schemi",
source: "Sorgente",
target: "Destinazione",
diff --git a/apps/desktop/src/i18n/locales/ja.ts b/apps/desktop/src/i18n/locales/ja.ts
index 6446d50167..4a1570f3fe 100644
--- a/apps/desktop/src/i18n/locales/ja.ts
+++ b/apps/desktop/src/i18n/locales/ja.ts
@@ -5503,6 +5503,22 @@ export default withEnglishFallback({
restoreSummary: "復元統計表",
},
diff: {
+ progress: {
+ loadingObjects: "ソースとターゲットのデータベースオブジェクトを読み込み中...",
+ loadingSourceDetails: "ソースデータベースのテーブル構造を読み込み中",
+ loadingTargetDetails: "ターゲットデータベースのテーブル構造を読み込み中",
+ loadingExtraObjects: "その他のデータベースオブジェクトを読み込み中...",
+ comparing: "スキーマの差分を分析中...",
+ generating: "比較結果を生成中...",
+ next: "次のステップ: {step}",
+ nextSourceDetails: "ソースデータベースのテーブル構造を読み込む",
+ nextTargetDetails: "ターゲットデータベースのテーブル構造を読み込む",
+ nextExtraObjects: "その他のデータベースオブジェクトを読み込む",
+ nextComparing: "スキーマの差分を分析",
+ nextGenerating: "比較結果を生成",
+ nextComplete: "完了",
+ count: "{current} / {total}",
+ },
title: "スキーマを比較",
source: "ソース",
target: "対象",
diff --git a/apps/desktop/src/i18n/locales/ko.ts b/apps/desktop/src/i18n/locales/ko.ts
index 557952f5b3..83869dc21c 100644
--- a/apps/desktop/src/i18n/locales/ko.ts
+++ b/apps/desktop/src/i18n/locales/ko.ts
@@ -5178,6 +5178,22 @@ export default withEnglishFallback({
collapseAll: "모두 접기",
},
diff: {
+ progress: {
+ loadingObjects: "원본 및 대상 데이터베이스 객체를 읽는 중...",
+ loadingSourceDetails: "원본 데이터베이스 테이블 구조를 읽는 중",
+ loadingTargetDetails: "대상 데이터베이스 테이블 구조를 읽는 중",
+ loadingExtraObjects: "기타 데이터베이스 객체를 읽는 중...",
+ comparing: "스키마 차이를 분석하는 중...",
+ generating: "비교 결과를 생성하는 중...",
+ next: "다음 단계: {step}",
+ nextSourceDetails: "원본 데이터베이스 테이블 구조 읽기",
+ nextTargetDetails: "대상 데이터베이스 테이블 구조 읽기",
+ nextExtraObjects: "기타 데이터베이스 객체 읽기",
+ nextComparing: "스키마 차이 분석",
+ nextGenerating: "비교 결과 생성",
+ nextComplete: "완료",
+ count: "{current} / {total}",
+ },
title: "스키마 비교",
source: "소스",
target: "대상",
diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.ts
index ae518f1650..cf318e2183 100644
--- a/apps/desktop/src/i18n/locales/pt-BR.ts
+++ b/apps/desktop/src/i18n/locales/pt-BR.ts
@@ -5467,6 +5467,22 @@ export default withEnglishFallback({
restoreSummary: "Restaurar Tabela Estatística",
},
diff: {
+ progress: {
+ loadingObjects: "Lendo os objetos dos bancos de dados de origem e destino...",
+ loadingSourceDetails: "Lendo a estrutura das tabelas do banco de dados de origem",
+ loadingTargetDetails: "Lendo a estrutura das tabelas do banco de dados de destino",
+ loadingExtraObjects: "Lendo outros objetos do banco de dados...",
+ comparing: "Analisando as diferenças do esquema...",
+ generating: "Gerando o resultado da comparação...",
+ next: "Próxima etapa: {step}",
+ nextSourceDetails: "Ler a estrutura das tabelas do banco de dados de origem",
+ nextTargetDetails: "Ler a estrutura das tabelas do banco de dados de destino",
+ nextExtraObjects: "Ler outros objetos do banco de dados",
+ nextComparing: "Analisar as diferenças do esquema",
+ nextGenerating: "Gerar o resultado da comparação",
+ nextComplete: "Concluir",
+ count: "{current} / {total}",
+ },
title: "Comparar Esquemas",
source: "Origem",
target: "Destino",
diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.ts
index e57b34a876..754cd88f6d 100644
--- a/apps/desktop/src/i18n/locales/zh-CN.ts
+++ b/apps/desktop/src/i18n/locales/zh-CN.ts
@@ -5738,6 +5738,22 @@ export default withEnglishFallback({
collapseAll: "全部折叠",
},
diff: {
+ progress: {
+ loadingObjects: "正在读取源库和目标库对象…",
+ loadingSourceDetails: "正在读取源数据库表结构",
+ loadingTargetDetails: "正在读取目标数据库表结构",
+ loadingExtraObjects: "正在读取其他数据库对象…",
+ comparing: "正在分析结构差异…",
+ generating: "正在生成比较结果…",
+ next: "下一步:{step}",
+ nextSourceDetails: "读取源数据库表结构",
+ nextTargetDetails: "读取目标数据库表结构",
+ nextExtraObjects: "读取其他数据库对象",
+ nextComparing: "分析结构差异",
+ nextGenerating: "生成比较结果",
+ nextComplete: "完成",
+ count: "{current} / {total}",
+ },
title: "比较架构",
source: "源数据库",
target: "目标数据库",
diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.ts
index beeff271f2..e3e452165c 100644
--- a/apps/desktop/src/i18n/locales/zh-TW.ts
+++ b/apps/desktop/src/i18n/locales/zh-TW.ts
@@ -4789,6 +4789,22 @@ export default withEnglishFallback({
runInBackground: "背景執行",
},
diff: {
+ progress: {
+ loadingObjects: "正在讀取來源與目標資料庫物件……",
+ loadingSourceDetails: "正在讀取來源資料庫資料表結構",
+ loadingTargetDetails: "正在讀取目標資料庫資料表結構",
+ loadingExtraObjects: "正在讀取其他資料庫物件……",
+ comparing: "正在分析結構差異……",
+ generating: "正在產生比較結果……",
+ next: "下一步:{step}",
+ nextSourceDetails: "讀取來源資料庫資料表結構",
+ nextTargetDetails: "讀取目標資料庫資料表結構",
+ nextExtraObjects: "讀取其他資料庫物件",
+ nextComparing: "分析結構差異",
+ nextGenerating: "產生比較結果",
+ nextComplete: "完成",
+ count: "{current} / {total}",
+ },
title: "比較架構",
source: "來源資料庫",
target: "目標資料庫",
diff --git a/apps/desktop/src/lib/__tests__/schema/schemaDiffMetadataLoad.spec.ts b/apps/desktop/src/lib/__tests__/schema/schemaDiffMetadataLoad.spec.ts
index 6b3cb196f6..93d2402240 100644
--- a/apps/desktop/src/lib/__tests__/schema/schemaDiffMetadataLoad.spec.ts
+++ b/apps/desktop/src/lib/__tests__/schema/schemaDiffMetadataLoad.spec.ts
@@ -1,5 +1,8 @@
import { describe, expect, it } from "vitest";
-import { createConcurrencyLimiter, mapWithConcurrency, schemaDiffMetadataConcurrency, schemaDiffMetadataLoadPlan, shouldFetchSchemaDiffDdl } from "@/lib/schema/schemaDiffMetadataLoad";
+import { createConcurrencyLimiter, loadSchemaDetails, mapWithConcurrency, schemaDiffMetadataConcurrency, schemaDiffMetadataLoadPlan, shouldFetchSchemaDiffDdl, type SchemaDiffMetadataApi, type SchemaDiffMetadataProgress } from "../../schema/schemaDiffMetadataLoad";
+import { getSchemaDiffNextProgressStep, shouldLoadSchemaDiffExtraObjects } from "../../schema/schemaDiffProgress";
+import { DEFAULT_MYSQL_OPTIONS, DEFAULT_POSTGRES_OPTIONS } from "../../../types/schemaDiff";
+import type { TableInfo } from "../../../types/database";
function wait(ms: number) {
return new Promise<void>((resolve) => setTimeout(resolve, ms));
@@ -100,6 +103,40 @@ describe("schemaDiffMetadataLoad", () => {
expect(maxActive).toBeLessThanOrEqual(2);
});
+ it("reports each completed table while loading metadata", async () => {
+ const tables = ["orders", "customers", "events"].map((name) => ({ name, table_type: "TABLE" }) as TableInfo);
+ const progress: SchemaDiffMetadataProgress[] = [];
+ const api: SchemaDiffMetadataApi = {
+ getTableDdl: async (_connectionId, _database, _schema, table) => {
+ await wait(table === "orders" ? 10 : table === "customers" ? 1 : 5);
+ return `ddl:${table}`;
+ },
+ getColumns: async () => [],
+ listIndexes: async () => [],
+ listForeignKeys: async () => [],
+ listTriggers: async () => [],
+ };
+
+ const details = await loadSchemaDetails(
+ tables,
+ {
+ connectionId: "source",
+ database: "db",
+ schema: "public",
+ dbType: "mysql",
+ options: { ...DEFAULT_MYSQL_OPTIONS },
+ onProgress: (value) => progress.push(value),
+ },
+ api,
+ );
+
+ expect(details.map((detail) => detail.name)).toEqual(["orders", "customers", "events"]);
+ expect(details.map((detail) => detail.ddl)).toEqual(["ddl:orders", "ddl:customers", "ddl:events"]);
+ expect(progress.map((value) => value.current)).toEqual([1, 2, 3]);
+ expect(progress.map((value) => value.total)).toEqual([3, 3, 3]);
+ expect(new Set(progress.map((value) => value.objectName))).toEqual(new Set(["orders", "customers", "events"]));
+ });
+
it("propagates the first worker error and stops scheduling new work", async () => {
const started: number[] = [];
@@ -134,4 +171,31 @@ describe("schemaDiffMetadataLoad", () => {
expect(result).toEqual([0, 1, 2, 3]);
expect(maxActive).toBeLessThanOrEqual(2);
});
+
+ it("only enables extra objects for PostgreSQL-like databases with relevant options", () => {
+ expect(shouldLoadSchemaDiffExtraObjects("mysql", { ...DEFAULT_MYSQL_OPTIONS, functions: true })).toBe(false);
+ expect(shouldLoadSchemaDiffExtraObjects("postgres", DEFAULT_POSTGRES_OPTIONS)).toBe(true);
+ expect(shouldLoadSchemaDiffExtraObjects("opengauss", DEFAULT_POSTGRES_OPTIONS)).toBe(true);
+ expect(
+ shouldLoadSchemaDiffExtraObjects("postgres", {
+ ...DEFAULT_POSTGRES_OPTIONS,
+ functions: false,
+ sequences: false,
+ rules: false,
+ owners: false,
+ }),
+ ).toBe(false);
+ });
+
+ it("maps phases to the next step on the actual comparison path", () => {
+ expect(getSchemaDiffNextProgressStep("loading-table-lists", false)).toBe("nextSourceDetails");
+ expect(getSchemaDiffNextProgressStep("loading-source-details", false)).toBe("nextTargetDetails");
+ expect(getSchemaDiffNextProgressStep("loading-target-details", false)).toBe("nextComparing");
+ expect(getSchemaDiffNextProgressStep("loading-target-details", true)).toBe("nextExtraObjects");
+ expect(getSchemaDiffNextProgressStep("loading-extra-objects", true)).toBe("nextComparing");
+ expect(getSchemaDiffNextProgressStep("comparing", false)).toBe("nextGenerating");
+ expect(getSchemaDiffNextProgressStep("generating", false)).toBe("nextComplete");
+ expect(getSchemaDiffNextProgressStep("complete", false)).toBeNull();
+ expect(getSchemaDiffNextProgressStep(undefined, false)).toBeNull();
+ });
});
diff --git a/apps/desktop/src/lib/schema/schemaDiffMetadataLoad.ts b/apps/desktop/src/lib/schema/schemaDiffMetadataLoad.ts
index 58c990dc19..d1a4178801 100644
--- a/apps/desktop/src/lib/schema/schemaDiffMetadataLoad.ts
+++ b/apps/desktop/src/lib/schema/schemaDiffMetadataLoad.ts
@@ -1,4 +1,7 @@
+import type { ColumnInfo, ForeignKeyInfo, IndexInfo, ObjectSourceKind, TableInfo, TriggerInfo } from "@/types/database";
+import { isSchemaDiffView } from "@/lib/schema/schemaDiffTableFilter";
import type { SchemaDiffCompareOptions } from "@/types/schemaDiff";
+import type { TableSchemaDetail } from "@/lib/schema/schemaDiff";
const MYSQL_LARGE_SCHEMA_DIFF_METADATA_CONCURRENCY = 2;
const MYSQL_SMALL_SCHEMA_DIFF_METADATA_CONCURRENCY = 4;
@@ -115,3 +118,60 @@ export function createConcurrencyLimiter(limit: number) {
}
};
}
+
+export interface SchemaDiffMetadataApi {
+ getTableDdl(connectionId: string, database: string, schema: string, table: string, objectType?: ObjectSourceKind): Promise<string>;
+ getColumns(connectionId: string, database: string, schema: string, table: string): Promise<ColumnInfo[]>;
+ listIndexes(connectionId: string, database: string, schema: string, table: string): Promise<IndexInfo[]>;
+ listForeignKeys(connectionId: string, database: string, schema: string, table: string): Promise<ForeignKeyInfo[]>;
+ listTriggers(connectionId: string, database: string, schema: string, table: string): Promise<TriggerInfo[]>;
+}
+
+export interface SchemaDiffMetadataProgress {
+ current: number;
+ total: number;
+ objectName: string;
+}
+
+export interface SchemaDetailLoadContext {
+ connectionId: string;
+ database: string;
+ schema: string;
+ dbType: string;
+ options: SchemaDiffCompareOptions;
+ onProgress?: (progress: SchemaDiffMetadataProgress) => void;
+}
+
+function isViewOrMaterializedView(tableType: string): ObjectSourceKind | undefined {
+ switch (tableType.toUpperCase().replace(/\s+/g, "_")) {
+ case "VIEW":
+ return "VIEW";
+ case "MATERIALIZED_VIEW":
+ return "MATERIALIZED_VIEW";
+ default:
+ return undefined;
+ }
+}
+
+export async function loadSchemaDetails(tables: TableInfo[], context: SchemaDetailLoadContext, api: SchemaDiffMetadataApi): Promise<TableSchemaDetail[]> {
+ const concurrency = schemaDiffMetadataConcurrency(context.dbType, tables.length);
+ const runMetadataQuery = createConcurrencyLimiter(concurrency);
+ let completed = 0;
+
+ return mapWithConcurrency(tables, concurrency, async (table) => {
+ const objectType = isViewOrMaterializedView(table.table_type);
+ const loadPlan = schemaDiffMetadataLoadPlan(isSchemaDiffView(table), context.options);
+ const ddlPromise = loadPlan.ddl ? runMetadataQuery(() => api.getTableDdl(context.connectionId, context.database, context.schema, table.name, objectType)) : Promise.resolve("");
+ const [columns, indexes, foreignKeys, triggers, ddl] = await Promise.all([
+ loadPlan.columns ? runMetadataQuery(() => api.getColumns(context.connectionId, context.database, context.schema, table.name)) : Promise.resolve([]),
+ loadPlan.indexes ? runMetadataQuery(() => api.listIndexes(context.connectionId, context.database, context.schema, table.name)) : Promise.resolve([]),
+ loadPlan.foreignKeys ? runMetadataQuery(() => api.listForeignKeys(context.connectionId, context.database, context.schema, table.name)) : Promise.resolve([]),
+ loadPlan.triggers ? runMetadataQuery(() => api.listTriggers(context.connectionId, context.database, context.schema, table.name)) : Promise.resolve([]),
+ ddlPromise,
+ ]);
+
+ const detail = { name: table.name, columns, indexes, foreignKeys, triggers, ddl };
+ context.onProgress?.({ current: ++completed, total: tables.length, objectName: table.name });
+ return detail;
+ });
+}
diff --git a/apps/desktop/src/lib/schema/schemaDiffProgress.ts b/apps/desktop/src/lib/schema/schemaDiffProgress.ts
new file mode 100644
index 0000000000..40efc74acd
--- /dev/null
+++ b/apps/desktop/src/lib/schema/schemaDiffProgress.ts
@@ -0,0 +1,33 @@
+import type { SchemaDiffCompareOptions } from "@/types/schemaDiff";
+
+export type SchemaDiffProgressPhase = "loading-table-lists" | "loading-source-details" | "loading-target-details" | "loading-extra-objects" | "comparing" | "generating" | "complete";
+
+export type SchemaDiffNextProgressStep = "nextSourceDetails" | "nextTargetDetails" | "nextExtraObjects" | "nextComparing" | "nextGenerating" | "nextComplete";
+
+export function isSchemaDiffPostgresLike(dbType: string | null | undefined): boolean {
+ const normalizedDbType = (dbType || "").toLowerCase();
+ return normalizedDbType === "postgres" || normalizedDbType === "opengauss";
+}
+
+export function shouldLoadSchemaDiffExtraObjects(dbType: string | null | undefined, options: Pick<SchemaDiffCompareOptions, "functions" | "sequences" | "rules" | "owners">): boolean {
+ return isSchemaDiffPostgresLike(dbType) && (options.functions || options.sequences || options.rules || options.owners);
+}
+
+export function getSchemaDiffNextProgressStep(phase: SchemaDiffProgressPhase | undefined, hasExtraObjectPhase: boolean): SchemaDiffNextProgressStep | null {
+ switch (phase) {
+ case "loading-table-lists":
+ return "nextSourceDetails";
+ case "loading-source-details":
+ return "nextTargetDetails";
+ case "loading-target-details":
+ return hasExtraObjectPhase ? "nextExtraObjects" : "nextComparing";
+ case "loading-extra-objects":
+ return "nextComparing";
+ case "comparing":
+ return "nextGenerating";
+ case "generating":
+ return "nextComplete";
+ default:
+ return null;
+ }
+}