From 7a2739093600b336a542fd0848f0280254d62514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Thu, 14 May 2026 11:49:23 +0200 Subject: [PATCH] feat(schema): admin-default user timezone (migration 0043) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit v1.4.25 W7 phase 1 — adds AppSettings.defaultUserTimezone for the per-user-timezone feature (Option B from .planning/feature-user-timezone.md §4). User.timezone already exists in the schema as a NOT NULL column with 'Europe/Berlin' default — it is the canonical per-user display zone and needs no change. The only new piece is the server-wide default for new accounts that don't carry a browser-detected zone in the registration payload. Nullable so the resolver can fall back to 'Europe/Berlin' on every existing instance without an admin touching anything. Forward-only ALTER TABLE ADD COLUMN, no NOT NULL, no rename, no drop. --- .../0043_per_user_timezone/migration.sql | 23 +++++++++++++++++++ prisma/schema.prisma | 11 +++++++++ 2 files changed, 34 insertions(+) create mode 100644 prisma/migrations/0043_per_user_timezone/migration.sql diff --git a/prisma/migrations/0043_per_user_timezone/migration.sql b/prisma/migrations/0043_per_user_timezone/migration.sql new file mode 100644 index 000000000..2cdffe185 --- /dev/null +++ b/prisma/migrations/0043_per_user_timezone/migration.sql @@ -0,0 +1,23 @@ +-- v1.4.25 W7 — per-user timezone feature (Option B from +-- `.planning/feature-user-timezone.md`). +-- +-- HealthLog already ships a `users.timezone` column (default +-- 'Europe/Berlin', NOT NULL) from the original schema, so the +-- per-user side of this feature is non-additive at the storage +-- layer: the existing column is the canonical "display timezone" +-- that the resolver in `src/lib/tz/resolver.ts` reads. No change is +-- required on `users`. +-- +-- The admin-managed default for *new* accounts is the only new +-- column. It lives on the singleton `app_settings` row and is +-- nullable so the resolver can fall back to "Europe/Berlin" when an +-- operator never touches the setting. Validated against +-- `Intl.supportedValuesOf('timeZone')` upstream — the column is just +-- a varchar(64) bag. +-- +-- Forward-only / additive: ALTER TABLE ADD COLUMN with a nullable +-- type and no default. Existing rows are untouched. Rollback would +-- be a manual DROP COLUMN. + +ALTER TABLE "app_settings" + ADD COLUMN IF NOT EXISTS "default_user_timezone" VARCHAR(64); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index db7541429..a2cb3b6b7 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -621,6 +621,17 @@ model AppSettings { // Null = aggregator hasn't run yet OR there's no feedback in the window. adminAiInsightsFeedbackSummary Json? @map("admin_ai_insights_feedback_summary") + // v1.4.25 W7 — server-wide default timezone for new accounts that + // don't carry a browser-detected zone in the registration payload. + // The resolver in `src/lib/tz/resolver.ts` falls back to + // "Europe/Berlin" when this column is NULL, so existing instances + // keep behaving identically to v1.4.24 without an admin touching + // anything. Validated against `Intl.supportedValuesOf('timeZone')` + // at the admin write path. Length cap matches IANA's longest + // canonical zone identifier ("America/Argentina/ComodRivadavia" at + // 32 chars) plus headroom. + defaultUserTimezone String? @map("default_user_timezone") @db.VarChar(64) + @@map("app_settings") }