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((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): boolean { + return isView ? options.views : options.tables; +} + export async function mapWithConcurrency(items: readonly T[], limit: number, worker: (item: T, index: number) => Promise): Promise { const workerCount = Math.min(normalizeConcurrencyLimit(limit), items.length); if (workerCount === 0) return [];