From f1ee76c99cfb901b762326786aad2b262ad52c88 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 18 Jun 2026 12:45:02 +0200 Subject: [PATCH] =?UTF-8?q?fix(db):=20crash=20on=20MySQL=20=E2=80=94=20rep?= =?UTF-8?q?lace=20onConflictDoNothing=20with=20dialect-neutral=20pre-filte?= =?UTF-8?q?r=20(#5995)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/db/migrations/seed.ts | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/packages/db/migrations/seed.ts b/packages/db/migrations/seed.ts index 56d765d4a..6ec906cec 100644 --- a/packages/db/migrations/seed.ts +++ b/packages/db/migrations/seed.ts @@ -647,9 +647,13 @@ const seedDemoUserAsync = async (db: Database) => { const seedDefaultCustomWidgetsAsync = async (db: Database) => { const seedIds = CUSTOM_WIDGET_SEEDS.map((s) => s.id); - const beforeCount = await db.$count(customWidgetDefinitions, inArray(customWidgetDefinitions.id, seedIds)); + const existing = await db.query.customWidgetDefinitions.findMany({ + columns: { id: true }, + where: inArray(customWidgetDefinitions.id, seedIds), + }); + const existingIds = new Set(existing.map((row) => row.id)); - const seedValues = CUSTOM_WIDGET_SEEDS.map((seed) => { + const seedValues = CUSTOM_WIDGET_SEEDS.filter((seed) => !existingIds.has(seed.id)).map((seed) => { const parsed = customWidgetImportSchema.parse(seed.data); return { id: seed.id, @@ -668,22 +672,14 @@ const seedDefaultCustomWidgetsAsync = async (db: Database) => { }; }); - if (seedValues.length === 0) return; - - await db - .insert(customWidgetDefinitions) - .values(seedValues) - .onConflictDoNothing({ target: customWidgetDefinitions.id }); - - const afterCount = await db.$count(customWidgetDefinitions, inArray(customWidgetDefinitions.id, seedIds)); - const createdCount = afterCount - beforeCount; - - if (createdCount === 0) { + if (seedValues.length === 0) { console.log("Skipping seeding of default custom widgets as they already exist"); return; } - console.log(`Created ${createdCount} default custom widgets through seeding process`); + await db.insert(customWidgetDefinitions).values(seedValues); + + console.log(`Created ${seedValues.length} default custom widgets through seeding process`); }; const seedBoardWidgetsAsync = async (db: Database) => {