fix: use drizzle sql

This commit is contained in:
Manohar Gupta 2026-05-10 05:04:43 +05:30
parent d6a7f7560e
commit ab9aa1052e

View file

@ -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 });