From 71c8145b679c63c1893a3a09bc19cdfed5709b11 Mon Sep 17 00:00:00 2001 From: "Yoham Gabriel B. @Urbine" Date: Sat, 13 Jun 2026 14:20:15 -0600 Subject: [PATCH] fix: resolve duplicate extension race condition in seed route Fixes a PostgreSQL unique_violation error (23505) occurring during database seeding. The issue was caused by concurrent execution of `CREATE EXTENSION IF NOT EXISTS` across multiple functions inside a `sql.begin` block. This created a race condition where parallel transactions attempted to write to `pg_catalog.pg_extension` at the same time. Changes: - Moved extension creation outside and prior to the transaction block. - Streamlined seeding execution flow to prevent isolated database worker conflicts. Signed-off-by: Yoham Gabriel B. @Urbine --- dashboard/starter-example/app/seed/route.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dashboard/starter-example/app/seed/route.ts b/dashboard/starter-example/app/seed/route.ts index c6428b27..a38bc533 100644 --- a/dashboard/starter-example/app/seed/route.ts +++ b/dashboard/starter-example/app/seed/route.ts @@ -5,7 +5,7 @@ import { invoices, customers, revenue, users } from '../lib/placeholder-data'; const sql = postgres(process.env.POSTGRES_URL!, { ssl: 'require' }); async function seedUsers() { - await sql`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`; + await sql` CREATE TABLE IF NOT EXISTS users ( id UUID DEFAULT uuid_generate_v4() PRIMARY KEY, @@ -30,7 +30,6 @@ async function seedUsers() { } async function seedInvoices() { - await sql`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`; await sql` CREATE TABLE IF NOT EXISTS invoices ( @@ -56,7 +55,6 @@ async function seedInvoices() { } async function seedCustomers() { - await sql`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`; await sql` CREATE TABLE IF NOT EXISTS customers ( @@ -103,6 +101,9 @@ async function seedRevenue() { export async function GET() { try { + + await sql`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`; + const result = await sql.begin((sql) => [ seedUsers(), seedCustomers(),