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。

fix(schema-diff): skip view DDL when disabled

digyear3e8e7a4146c7
diff --git a/apps/desktop/src/components/diff/SchemaDiffDialog.vue b/apps/desktop/src/components/diff/SchemaDiffDialog.vue
index d01153f179..0afd7ea98e 100644
--- a/apps/desktop/src/components/diff/SchemaDiffDialog.vue
+++ b/apps/desktop/src/components/diff/SchemaDiffDialog.vue
@@ -16,7 +16,7 @@ import SchemaDiffDeployStep from "@/components/diff/SchemaDiffDeployStep.vue";
import SchemaDiffOptionsPanel from "@/components/diff/SchemaDiffOptionsPanel.vue";
import { getSchemaDiffOptionsForDbType } from "@/lib/schema/schemaDiffOptions";
-import { createConcurrencyLimiter, mapWithConcurrency, schemaDiffMetadataConcurrency } from "@/lib/schema/schemaDiffMetadataLoad";
+import { createConcurrencyLimiter, mapWithConcurrency, schemaDiffMetadataConcurrency, shouldFetchSchemaDiffDdl } from "@/lib/schema/schemaDiffMetadataLoad";
import { normalizeSchemaDiffCompareOptions } from "@/types/schemaDiff";
import type { SchemaDiffCompareOptions, SchemaDiffConfig } from "@/types/schemaDiff";
import type { ObjectSourceKind, TableInfo } from "@/types/database";
@@ -306,12 +306,14 @@ async function loadSchemaDetails(tables: TableInfo[], context: SchemaDetailLoadC
return mapWithConcurrency(tables, concurrency, async (table) => {
const objectType = isViewOrMaterializedView(table.table_type);
+ const shouldFetchDdl = shouldFetchSchemaDiffDdl(Boolean(objectType), context.options);
+ const ddlPromise = shouldFetchDdl ? runMetadataQuery(() => api.getTableDdl(context.connectionId, context.database, context.schema, table.name, objectType)) : Promise.resolve("");
const [columns, indexes, foreignKeys, triggers, ddl] = await Promise.all([
runMetadataQuery(() => api.getColumns(context.connectionId, context.database, context.schema, table.name)),
shouldLoadIndexes(context.options) ? runMetadataQuery(() => api.listIndexes(context.connectionId, context.database, context.schema, table.name)) : Promise.resolve([]),
context.options.foreignKeys ? runMetadataQuery(() => api.listForeignKeys(context.connectionId, context.database, context.schema, table.name)) : Promise.resolve([]),
context.options.triggers ? runMetadataQuery(() => api.listTriggers(context.connectionId, context.database, context.schema, table.name)) : Promise.resolve([]),
- runMetadataQuery(() => api.getTableDdl(context.connectionId, context.database, context.schema, table.name, objectType)),
+ ddlPromise,
]);
return { name: table.name, columns, indexes, foreignKeys, triggers, ddl };
diff --git a/apps/desktop/src/lib/__tests__/schema/schemaDiffMetadataLoad.spec.ts b/apps/desktop/src/lib/__tests__/schema/schemaDiffMetadataLoad.spec.ts
index 24e0a24478..1c795e8694 100644
--- a/apps/desktop/src/lib/__tests__/schema/schemaDiffMetadataLoad.spec.ts
+++ b/apps/desktop/src/lib/__tests__/schema/schemaDiffMetadataLoad.spec.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
-import { createConcurrencyLimiter, mapWithConcurrency, schemaDiffMetadataConcurrency } from "@/lib/schema/schemaDiffMetadataLoad";
+import { createConcurrencyLimiter, mapWithConcurrency, schemaDiffMetadataConcurrency, shouldFetchSchemaDiffDdl } from "@/lib/schema/schemaDiffMetadataLoad";
function wait(ms: number) {
return new Promise<void>((resolve) => setTimeout(resolve, ms));
@@ -17,6 +17,13 @@ describe("schemaDiffMetadataLoad", () => {
expect(schemaDiffMetadataConcurrency(undefined)).toBe(6);
});
+ it("skips view DDL when views are disabled while preserving table DDL options", () => {
+ expect(shouldFetchSchemaDiffDdl(true, { tables: true, views: false })).toBe(false);
+ expect(shouldFetchSchemaDiffDdl(true, { tables: false, views: true })).toBe(true);
+ expect(shouldFetchSchemaDiffDdl(false, { tables: false, views: true })).toBe(false);
+ expect(shouldFetchSchemaDiffDdl(false, { tables: true, views: false })).toBe(true);
+ });
+
it("maps items with limited concurrency and preserves output order", async () => {
let active = 0;
let maxActive = 0;
diff --git a/apps/desktop/src/lib/schema/schemaDiffMetadataLoad.ts b/apps/desktop/src/lib/schema/schemaDiffMetadataLoad.ts
index 8973ffcc02..754dfd274c 100644
--- a/apps/desktop/src/lib/schema/schemaDiffMetadataLoad.ts
+++ b/apps/desktop/src/lib/schema/schemaDiffMetadataLoad.ts
@@ -1,3 +1,5 @@
+import type { SchemaDiffCompareOptions } from "@/types/schemaDiff";
+
const MYSQL_LARGE_SCHEMA_DIFF_METADATA_CONCURRENCY = 2;
const MYSQL_SMALL_SCHEMA_DIFF_METADATA_CONCURRENCY = 4;
const MYSQL_SMALL_SCHEMA_TABLE_LIMIT = 30;
@@ -18,6 +20,10 @@ export function schemaDiffMetadataConcurrency(dbType: string | null | undefined,
return DEFAULT_SCHEMA_DIFF_METADATA_CONCURRENCY;
}
+export function shouldFetchSchemaDiffDdl(isView: boolean, options: Pick<SchemaDiffCompareOptions, "tables" | "views">): boolean {
+ return isView ? options.views : options.tables;
+}
+
export async function mapWithConcurrency<T, R>(items: readonly T[], limit: number, worker: (item: T, index: number) => Promise<R>): Promise<R[]> {
const workerCount = Math.min(normalizeConcurrencyLimit(limit), items.length);
if (workerCount === 0) return [];