diff --git a/dashboard/final-example/app/seed/route.ts b/dashboard/final-example/app/seed/route.ts index c6428b27..80053900 100644 --- a/dashboard/final-example/app/seed/route.ts +++ b/dashboard/final-example/app/seed/route.ts @@ -4,8 +4,11 @@ import { invoices, customers, revenue, users } from '../lib/placeholder-data'; const sql = postgres(process.env.POSTGRES_URL!, { ssl: 'require' }); -async function seedUsers() { +async function ensureExtension() { await sql`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`; +} + +async function seedUsers() { await sql` CREATE TABLE IF NOT EXISTS users ( id UUID DEFAULT uuid_generate_v4() PRIMARY KEY, @@ -30,8 +33,6 @@ async function seedUsers() { } async function seedInvoices() { - await sql`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`; - await sql` CREATE TABLE IF NOT EXISTS invoices ( id UUID DEFAULT uuid_generate_v4() PRIMARY KEY, @@ -56,8 +57,6 @@ async function seedInvoices() { } async function seedCustomers() { - await sql`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`; - await sql` CREATE TABLE IF NOT EXISTS customers ( id UUID DEFAULT uuid_generate_v4() PRIMARY KEY, @@ -103,12 +102,16 @@ async function seedRevenue() { export async function GET() { try { - const result = await sql.begin((sql) => [ - seedUsers(), - seedCustomers(), - seedInvoices(), - seedRevenue(), - ]); + // Ensure the extension is created before running the transaction + await ensureExtension(); + + // Run seeding within a transaction + const result = await sql.begin(async (sql) => { + await seedUsers(); + await seedCustomers(); + await seedInvoices(); + await seedRevenue(); + }); return Response.json({ message: 'Database seeded successfully' }); } catch (error) { diff --git a/dashboard/starter-example/app/seed/route.ts b/dashboard/starter-example/app/seed/route.ts index c6428b27..80053900 100644 --- a/dashboard/starter-example/app/seed/route.ts +++ b/dashboard/starter-example/app/seed/route.ts @@ -4,8 +4,11 @@ import { invoices, customers, revenue, users } from '../lib/placeholder-data'; const sql = postgres(process.env.POSTGRES_URL!, { ssl: 'require' }); -async function seedUsers() { +async function ensureExtension() { await sql`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`; +} + +async function seedUsers() { await sql` CREATE TABLE IF NOT EXISTS users ( id UUID DEFAULT uuid_generate_v4() PRIMARY KEY, @@ -30,8 +33,6 @@ async function seedUsers() { } async function seedInvoices() { - await sql`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`; - await sql` CREATE TABLE IF NOT EXISTS invoices ( id UUID DEFAULT uuid_generate_v4() PRIMARY KEY, @@ -56,8 +57,6 @@ async function seedInvoices() { } async function seedCustomers() { - await sql`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`; - await sql` CREATE TABLE IF NOT EXISTS customers ( id UUID DEFAULT uuid_generate_v4() PRIMARY KEY, @@ -103,12 +102,16 @@ async function seedRevenue() { export async function GET() { try { - const result = await sql.begin((sql) => [ - seedUsers(), - seedCustomers(), - seedInvoices(), - seedRevenue(), - ]); + // Ensure the extension is created before running the transaction + await ensureExtension(); + + // Run seeding within a transaction + const result = await sql.begin(async (sql) => { + await seedUsers(); + await seedCustomers(); + await seedInvoices(); + await seedRevenue(); + }); return Response.json({ message: 'Database seeded successfully' }); } catch (error) {