Files
paliad/internal/db/migrations/064_users_forum_pref.up.sql
m 06bd276a9c feat(users/forum-pref): persisted Fristenrechner inbox-channel column
Adds paliad.users.forum_pref so /tools/fristenrechner can pre-narrow
the proceeding picker to the user's typical inbox channel without
re-asking on every visit. The new column threads through the User
model, the userColumns SELECT, and UpdateProfileInput so the existing
PATCH /api/me handler accepts it without a new endpoint.

Allowed values mirror the channel chips m named in t-paliad-157:

  - cms          → UPC
  - bea          → national-DE
  - posteingang  → national-DE (slower channel, same forums)

NULL means "no preference, picker shows everything"; URL ?inbox=
overrides per-visit (frontend lands in the next commit). The CHECK
constraint enforces the 3-value enum at the DB layer; isValidForumPref
mirrors it in the service so callers see a typed error instead of a
raw pq violation. Empty string in the PATCH body clears the
preference, consistent with the EscalationContactID convention.

Migration 064 applied to the live Supabase pool; tracker bumped to
v64 so the boot-time runner skips re-applying.

Refs m/paliad#15.
2026-05-08 16:23:12 +02:00

33 lines
1.4 KiB
SQL

-- t-paliad-157 / m/paliad#15: persisted Fristenrechner inbox-channel
-- preference.
--
-- Stores the user's typical inbox channel (cms = UPC, bea = national-DE,
-- posteingang = national-DE — slower channel, same set of forums) so
-- /tools/fristenrechner can pre-narrow the proceeding picker without
-- re-asking on every visit. The chip on the page persists changes here
-- via the existing PATCH /api/me endpoint. URL ?inbox= overrides for
-- the current visit so a colleague can share a CMS-narrowed link
-- without flipping anyone's saved preference.
--
-- The 3-value CHECK keeps the schema honest while leaving room to add
-- epa / dpma channels later (the Fristenrechner already supports those
-- forums via the fine-grained B2 chips; the inbox-channel chip starts
-- with the channels m named explicitly in t-paliad-157).
--
-- NULL = no preference, picker shows everything. Default for existing
-- rows.
ALTER TABLE paliad.users
ADD COLUMN forum_pref text;
ALTER TABLE paliad.users
ADD CONSTRAINT users_forum_pref_check
CHECK (forum_pref IS NULL OR forum_pref IN ('cms', 'bea', 'posteingang'));
COMMENT ON COLUMN paliad.users.forum_pref IS
'Persisted Fristenrechner inbox-channel preference (#15). '
'cms = UPC; bea = national-DE; posteingang = national-DE (slower '
'channel, same forums). NULL = no preference (picker shows '
'everything). URL ?inbox= overrides for the current visit. Set via '
'PATCH /api/me.';