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 { NextResponse } from "next/server";
|
||||||
import postgres from "postgres";
|
import { db } from "@/db";
|
||||||
|
import { sql } from "drizzle-orm/postgres-js";
|
||||||
const connectionString = process.env.DATABASE_URL!;
|
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
const client = postgres(connectionString);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Create types first
|
// Create enums
|
||||||
await client.unsafe("CREATE TYPE IF NOT EXISTS child_sex AS ENUM('male', 'female', 'other')");
|
await db.execute(sql`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 db.execute(sql`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')");
|
await db.execute(sql`CREATE TYPE IF NOT EXISTS member_role AS ENUM('admin', 'caregiver', 'viewer')`);
|
||||||
|
|
||||||
await client.end();
|
return NextResponse.json({ success: true, message: "Types created" });
|
||||||
return NextResponse.json({ step1: "types created" });
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return NextResponse.json({ error: String(error) }, { status: 500 });
|
return NextResponse.json({ error: String(error) }, { status: 500 });
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue