fix: use drizzle sql
This commit is contained in:
parent
d6a7f7560e
commit
ab9aa1052e
1 changed files with 7 additions and 11 deletions
|
|
@ -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 });
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue