diff --git a/prisma/migrations/0098_app_settings_global_toggles_drift_fix/migration.sql b/prisma/migrations/0098_app_settings_global_toggles_drift_fix/migration.sql new file mode 100644 index 000000000..6aea03c79 --- /dev/null +++ b/prisma/migrations/0098_app_settings_global_toggles_drift_fix/migration.sql @@ -0,0 +1,20 @@ +-- 0098_app_settings_global_toggles_drift_fix +-- Four `app_settings` columns have been on `prisma/schema.prisma` since the +-- per-channel global notification toggles + admin default-locale work but +-- never landed in the migration history (applied via `prisma db push` to +-- existing environments but not committed as a migration). The drift is +-- invisible on a database kept in sync via `db push`, but a database built +-- from migrations alone is missing the columns — and the admin settings +-- read path (`/api/admin/settings`) selects `default_locale`, so a fresh +-- deploy reports `column "default_locale" does not exist` on first read. +-- +-- Same class of drift as 0025_user_locale_drift_fix. Each add uses +-- `IF NOT EXISTS` with the schema default, so the migration is a safe no-op +-- against any environment already carrying the columns and a clean add +-- against one built strictly from this migrations directory (CI test +-- containers, fresh deploys, demo seeds). +ALTER TABLE "app_settings" + ADD COLUMN IF NOT EXISTS "default_locale" TEXT NOT NULL DEFAULT 'de', + ADD COLUMN IF NOT EXISTS "telegram_global" BOOLEAN NOT NULL DEFAULT true, + ADD COLUMN IF NOT EXISTS "ntfy_global" BOOLEAN NOT NULL DEFAULT true, + ADD COLUMN IF NOT EXISTS "web_push_global" BOOLEAN NOT NULL DEFAULT true; diff --git a/scripts/seed-demo.ts b/scripts/seed-demo.ts index 529e543a8..44d4db708 100644 --- a/scripts/seed-demo.ts +++ b/scripts/seed-demo.ts @@ -247,14 +247,14 @@ async function seed() { const takenTime = new Date(date); takenTime.setHours(8, Math.floor(Math.random() * 45), 0); await client.query( - `INSERT INTO medication_intake_events (id, user_id, medication_id, scheduled_for, taken_at, skipped, source, created_at) - VALUES ($1, $2, $3, $4, $5, false, 'WEB', $5)`, + `INSERT INTO medication_intake_events (id, user_id, medication_id, scheduled_for, taken_at, skipped, source, created_at, updated_at) + VALUES ($1, $2, $3, $4, $5, false, 'WEB', $5, $5)`, [cuid(), userId, med1Id, date, takenTime], ); } else { await client.query( - `INSERT INTO medication_intake_events (id, user_id, medication_id, scheduled_for, taken_at, skipped, source, created_at) - VALUES ($1, $2, $3, $4, NULL, true, 'WEB', $4)`, + `INSERT INTO medication_intake_events (id, user_id, medication_id, scheduled_for, taken_at, skipped, source, created_at, updated_at) + VALUES ($1, $2, $3, $4, NULL, true, 'WEB', $4, $4)`, [cuid(), userId, med1Id, date], ); } @@ -265,14 +265,14 @@ async function seed() { const takenTime = new Date(date); takenTime.setHours(8, Math.floor(5 + Math.random() * 50), 0); await client.query( - `INSERT INTO medication_intake_events (id, user_id, medication_id, scheduled_for, taken_at, skipped, source, created_at) - VALUES ($1, $2, $3, $4, $5, false, 'WEB', $5)`, + `INSERT INTO medication_intake_events (id, user_id, medication_id, scheduled_for, taken_at, skipped, source, created_at, updated_at) + VALUES ($1, $2, $3, $4, $5, false, 'WEB', $5, $5)`, [cuid(), userId, med2Id, date, takenTime], ); } else { await client.query( - `INSERT INTO medication_intake_events (id, user_id, medication_id, scheduled_for, taken_at, skipped, source, created_at) - VALUES ($1, $2, $3, $4, NULL, true, 'WEB', $4)`, + `INSERT INTO medication_intake_events (id, user_id, medication_id, scheduled_for, taken_at, skipped, source, created_at, updated_at) + VALUES ($1, $2, $3, $4, NULL, true, 'WEB', $4, $4)`, [cuid(), userId, med2Id, date], ); } @@ -284,14 +284,14 @@ async function seed() { const takenTime = new Date(date); takenTime.setHours(20, Math.floor(Math.random() * 60), 0); await client.query( - `INSERT INTO medication_intake_events (id, user_id, medication_id, scheduled_for, taken_at, skipped, source, created_at) - VALUES ($1, $2, $3, $4, $5, false, 'WEB', $5)`, + `INSERT INTO medication_intake_events (id, user_id, medication_id, scheduled_for, taken_at, skipped, source, created_at, updated_at) + VALUES ($1, $2, $3, $4, $5, false, 'WEB', $5, $5)`, [cuid(), userId, med3Id, date, takenTime], ); } else { await client.query( - `INSERT INTO medication_intake_events (id, user_id, medication_id, scheduled_for, taken_at, skipped, source, created_at) - VALUES ($1, $2, $3, $4, NULL, true, 'WEB', $4)`, + `INSERT INTO medication_intake_events (id, user_id, medication_id, scheduled_for, taken_at, skipped, source, created_at, updated_at) + VALUES ($1, $2, $3, $4, NULL, true, 'WEB', $4, $4)`, [cuid(), userId, med3Id, date], ); }