diff --git a/src/app/api/setup/route.ts b/src/app/api/setup/route.ts index f87fd92..f78dcd3 100644 --- a/src/app/api/setup/route.ts +++ b/src/app/api/setup/route.ts @@ -1,19 +1,15 @@ import { NextResponse } from "next/server"; -import postgres from "postgres"; - -const connectionString = process.env.DATABASE_URL!; +import { db } from "@/db"; +import { sql } from "drizzle-orm/postgres-js"; export async function GET() { - const client = postgres(connectionString); - try { - // Create types first - await client.unsafe("CREATE TYPE IF NOT EXISTS child_sex AS ENUM('male', 'female', 'other')"); - await client.unsafe("CREATE TYPE IF NOT EXISTS child_stage AS ENUM('newborn', 'infant', 'solids_start', 'toddler_early', 'toddler_late', 'preschool')"); - await client.unsafe("CREATE TYPE IF NOT EXISTS member_role AS ENUM('admin', 'caregiver', 'viewer')"); + // Create enums + await db.execute(sql`CREATE TYPE IF NOT EXISTS child_sex AS ENUM('male', 'female', 'other')`); + await db.execute(sql`CREATE TYPE IF NOT EXISTS child_stage AS ENUM('newborn', 'infant', 'solids_start', 'toddler_early', 'toddler_late', 'preschool')`); + await db.execute(sql`CREATE TYPE IF NOT EXISTS member_role AS ENUM('admin', 'caregiver', 'viewer')`); - await client.end(); - return NextResponse.json({ step1: "types created" }); + return NextResponse.json({ success: true, message: "Types created" }); } catch (error) { console.error(error); return NextResponse.json({ error: String(error) }, { status: 500 });