From 91c25b2c15f905a1621bb82d0d1e633f465b154a Mon Sep 17 00:00:00 2001 From: Mannu Date: Sat, 30 May 2026 01:11:01 +0530 Subject: [PATCH] Add error_events to debug-migration hot-apply steps Migration 0010 (error_events) didn't land via the drizzle journal on prod, so add an idempotent CREATE TABLE + indexes to the /api/debug-migration steps so the table can be created instantly via the documented hot-apply endpoint. Co-Authored-By: Claude Opus 4.8 --- src/app/api/debug-migration/route.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/app/api/debug-migration/route.ts b/src/app/api/debug-migration/route.ts index 83bd886..a8ec492 100644 --- a/src/app/api/debug-migration/route.ts +++ b/src/app/api/debug-migration/route.ts @@ -71,6 +71,11 @@ export async function POST(req: Request) { `CREATE TABLE IF NOT EXISTS notifications (id UUID PRIMARY KEY DEFAULT gen_random_uuid(), family_id UUID NOT NULL REFERENCES families(id) ON DELETE CASCADE, child_id UUID REFERENCES children(id) ON DELETE CASCADE, type VARCHAR(80) NOT NULL, title TEXT NOT NULL, message TEXT NOT NULL, action_url TEXT, is_read BOOLEAN NOT NULL DEFAULT false, scheduled_for DATE NOT NULL, metadata JSONB, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW())`, `CREATE UNIQUE INDEX IF NOT EXISTS notifications_unique_slot ON notifications(family_id, child_id, type, scheduled_for)`, `CREATE INDEX IF NOT EXISTS notifications_family_child_idx ON notifications(family_id, child_id, is_read, created_at DESC)`, + // 0010 — error_events table (admin error/crash tracker) + `CREATE TABLE IF NOT EXISTS error_events (id uuid PRIMARY KEY DEFAULT gen_random_uuid(), level varchar(20) NOT NULL DEFAULT 'error', source varchar(20) NOT NULL DEFAULT 'client', message text NOT NULL, stack text, url text, digest varchar(120), user_id uuid, family_id uuid, user_agent text, metadata jsonb DEFAULT '{}', created_at timestamptz NOT NULL DEFAULT now())`, + `CREATE INDEX IF NOT EXISTS idx_error_events_created ON error_events (created_at DESC)`, + `CREATE INDEX IF NOT EXISTS idx_error_events_source ON error_events (source)`, + `CREATE INDEX IF NOT EXISTS idx_error_events_message ON error_events (message)`, ]; const results: string[] = [];