fix: simplify setup
This commit is contained in:
parent
b4dc29fa3d
commit
d6a7f7560e
1 changed files with 5 additions and 69 deletions
|
|
@ -7,77 +7,13 @@ export async function GET() {
|
|||
const client = postgres(connectionString);
|
||||
|
||||
try {
|
||||
await client.unsafe(`
|
||||
CREATE TYPE IF NOT EXISTS child_sex AS ENUM('male', 'female', 'other');
|
||||
CREATE TYPE IF NOT EXISTS child_stage AS ENUM('newborn', 'infant', 'solids_start', 'toddler_early', 'toddler_late', 'preschool');
|
||||
CREATE TYPE IF NOT EXISTS member_role AS ENUM('admin', 'caregiver', 'viewer');
|
||||
`);
|
||||
|
||||
await client.unsafe(`
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
name text, email text NOT NULL UNIQUE,
|
||||
email_verified timestamp, image text,
|
||||
created_at timestamp DEFAULT now(),
|
||||
updated_at timestamp DEFAULT now()
|
||||
)
|
||||
`);
|
||||
|
||||
await client.unsafe(`
|
||||
CREATE TABLE IF NOT EXISTS sessions (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
session_token text NOT NULL UNIQUE,
|
||||
user_id uuid NOT NULL, expires timestamp NOT NULL
|
||||
)
|
||||
`);
|
||||
|
||||
await client.unsafe(`
|
||||
CREATE TABLE IF NOT EXISTS accounts (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
user_id uuid NOT NULL, type text NOT NULL,
|
||||
provider text NOT NULL, provider_account_id text NOT NULL,
|
||||
refresh_token text, access_token text, expires_at timestamp,
|
||||
token_type text, scope text, id_token text, session_state text
|
||||
)
|
||||
`);
|
||||
|
||||
await client.unsafe(`
|
||||
CREATE TABLE IF NOT EXISTS verification_tokens (
|
||||
identifier text NOT NULL, token text NOT NULL,
|
||||
expires timestamp NOT NULL, PRIMARY KEY (identifier, token)
|
||||
)
|
||||
`);
|
||||
|
||||
await client.unsafe(`
|
||||
CREATE TABLE IF NOT EXISTS families (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
name text DEFAULT 'The Gupta Family', pediatrician_phone text,
|
||||
created_at timestamp DEFAULT now(), updated_at timestamp DEFAULT now()
|
||||
)
|
||||
`);
|
||||
|
||||
await client.unsafe(`
|
||||
CREATE TABLE IF NOT EXISTS family_members (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
family_id uuid NOT NULL, user_id uuid NOT NULL,
|
||||
role member_role DEFAULT 'caregiver', display_name text NOT NULL,
|
||||
created_at timestamp DEFAULT now()
|
||||
)
|
||||
`);
|
||||
|
||||
await client.unsafe(`
|
||||
CREATE TABLE IF NOT EXISTS children (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
family_id uuid NOT NULL, name text NOT NULL,
|
||||
birth_date timestamp NOT NULL, sex child_sex NOT NULL,
|
||||
current_stage child_stage, stage_overrides jsonb DEFAULT '{}',
|
||||
profile_photo_url text, created_at timestamp DEFAULT now(),
|
||||
updated_at timestamp DEFAULT now()
|
||||
)
|
||||
`);
|
||||
// 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')");
|
||||
|
||||
await client.end();
|
||||
return NextResponse.json({ success: true });
|
||||
return NextResponse.json({ step1: "types created" });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ error: String(error) }, { status: 500 });
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue