Files
HealthLog/prisma/migrations/0499_user_nutrient_targets/migration.sql
T
Marc-André Bombeck a68ec9421f feat(nutrients): store daily nutrient targets per account
A nullable users.nutrient_targets_json column (migration 0499) holds a
target or limit per catalog code in the code's canonical unit. GET and
PATCH /api/nutrients/targets read and merge it behind the nutrients
module; PATCH refuses unknown codes and values above the code's
plausibility cap, and audits the codes set, never the amounts.
2026-11-17 18:46:48 +01:00

20 lines
756 B
SQL

-- Optional daily nutrient targets a person sets for themselves (#1402):
-- energy, protein and the other catalog codes, each a value in the code's
-- canonical unit and a direction (an amount to reach or one to stay under).
--
-- Nullable, no default, no backfill: null reads as "no target set", which is
-- every account's state today. IF NOT EXISTS keeps a replay on a database
-- that already ran a build carrying the column harmless. Reversibility:
-- dropping the column removes the targets; the charts fall back to the
-- dietary reference.
--
-- @retry-on-lock-timeout
DO $migration$
BEGIN
PERFORM set_config('lock_timeout', '5s', true);
ALTER TABLE "users"
ADD COLUMN IF NOT EXISTS "nutrient_targets_json" JSONB;
END
$migration$;