feat(fase-9): migration 015 — users.theme column for dark mode
Adds `theme text not null default 'system' check (theme in
('light','dark','system'))` to public.users. New users get 'system' so
the UI follows the OS preference until they opt in; existing rows
backfill via the default.
Includes pgTAP test 009 (8 assertions covering column existence/type,
default value, valid transitions, and the check constraint rejecting
unknown values). Wires the theme field into the hand-curated
database.ts type so PostgREST queries stay typed.
Also hardens `just db-types` to bail out (instead of truncating
database.ts) when the supabase CLI is missing — the recipe was silently
wiping the file on this dev machine.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
16
supabase/migrations/015_user_theme.sql
Normal file
16
supabase/migrations/015_user_theme.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
-- Migration 015: theme preference on public.users (Fase 9.1)
|
||||
--
|
||||
-- Stores the user's chosen UI theme: 'light' | 'dark' | 'system'.
|
||||
-- New users (and existing rows on upgrade) default to 'system' so the UI
|
||||
-- inherits the OS preference until they explicitly opt in.
|
||||
--
|
||||
-- The JWT minted by GoTrue caches `auth.users` (not `public.users`), so
|
||||
-- adding this column does NOT invalidate existing sessions — clients read
|
||||
-- the value via PostgREST `SELECT theme FROM users WHERE id = auth.uid()`.
|
||||
|
||||
ALTER TABLE public.users
|
||||
ADD COLUMN theme text NOT NULL DEFAULT 'system'
|
||||
CHECK (theme IN ('light', 'dark', 'system'));
|
||||
|
||||
COMMENT ON COLUMN public.users.theme IS
|
||||
'UI theme preference. ''system'' follows prefers-color-scheme.';
|
||||
Reference in New Issue
Block a user