mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-15 23:12:04 +00:00
chore(release): v1.13.0 — per-user custom mood tags + catalogue hide
Let a user shape their own mood-tag set on top of the global catalogue: create custom tags (label encrypted at rest, icon from a fixed allow-list), and hide built-in tags per user. Custom tags live in `mood_tags` with a non-null `user_id` and a `custom:<uuid>` key; `GET /api/mood/tags` returns the effective per-user set (catalogue − hidden + own customs) with new `custom` + `label` fields, and `?include=hidden` surfaces hidden catalogue tags for the management screen. The write path resolves a `custom:` key only against the caller's own rows — a foreign custom key is dropped, never linked. Delete soft-deactivates by default (history intact); `?purge=true` removes the row and its links. BINARY-only for v1. New: POST/PATCH/DELETE /api/mood/tags/custom[/:key], PUT /api/mood/tags/:key/hidden, migration 0127 (user_id + label_encrypted columns, mood_tag_hidden table, `custom` category). Integration setup snapshots + restores the seeded catalogue because the new mood_tags→users FK makes TRUNCATE users CASCADE wipe it. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
09bdd49791
commit
f1329b24e1
21 files changed
+934
-121
No files matched your search
@@ -0,0 +1,52 @@
|
||||
-- v1.13.0 — per-user custom mood tags + per-user catalogue hide.
|
||||
--
|
||||
-- Additive, non-destructive:
|
||||
-- 1. `mood_tags` gains `user_id` (NULL = global catalogue, set = a user's
|
||||
-- custom tag carrying a `custom:<cuid>` key) and `label_encrypted`
|
||||
-- (AES-256-GCM ciphertext of a custom tag's free-text label; NULL for
|
||||
-- catalogue rows, which resolve `label_key` against the locale).
|
||||
-- 2. New `mood_tag_hidden` join: a per-user hide of a CATALOGUE tag.
|
||||
-- 3. Seed the global `custom` category every user's custom tags hang under.
|
||||
--
|
||||
-- Idempotent: ADD COLUMN IF NOT EXISTS, CREATE TABLE IF NOT EXISTS, and the
|
||||
-- category seed upserts by `key` (deterministic id `mtc_custom`).
|
||||
|
||||
-- ─── 1. mood_tags: owner + encrypted custom label ────────────────────
|
||||
ALTER TABLE "mood_tags" ADD COLUMN IF NOT EXISTS "user_id" TEXT;
|
||||
ALTER TABLE "mood_tags" ADD COLUMN IF NOT EXISTS "label_encrypted" TEXT;
|
||||
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "mood_tags"
|
||||
ADD CONSTRAINT "mood_tags_user_id_fkey"
|
||||
FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
EXCEPTION WHEN duplicate_object THEN NULL; END $$;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "mood_tags_user_id_idx" ON "mood_tags"("user_id");
|
||||
|
||||
-- ─── 2. mood_tag_hidden: per-user catalogue hide ─────────────────────
|
||||
CREATE TABLE IF NOT EXISTS "mood_tag_hidden" (
|
||||
"user_id" TEXT NOT NULL,
|
||||
"mood_tag_id" TEXT NOT NULL,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
CONSTRAINT "mood_tag_hidden_pkey" PRIMARY KEY ("user_id", "mood_tag_id")
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS "mood_tag_hidden_mood_tag_id_idx" ON "mood_tag_hidden"("mood_tag_id");
|
||||
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "mood_tag_hidden"
|
||||
ADD CONSTRAINT "mood_tag_hidden_user_id_fkey"
|
||||
FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
EXCEPTION WHEN duplicate_object THEN NULL; END $$;
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "mood_tag_hidden"
|
||||
ADD CONSTRAINT "mood_tag_hidden_mood_tag_id_fkey"
|
||||
FOREIGN KEY ("mood_tag_id") REFERENCES "mood_tags"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
EXCEPTION WHEN duplicate_object THEN NULL; END $$;
|
||||
|
||||
-- ─── 3. Seed the global `custom` category ────────────────────────────
|
||||
INSERT INTO "mood_tag_categories"
|
||||
("id", "key", "label_key", "icon", "sort_order", "is_active")
|
||||
VALUES ('mtc_custom', 'custom', 'mood.tagCategory.custom', 'Tag', 100, true)
|
||||
ON CONFLICT ("key") DO UPDATE SET
|
||||
"label_key" = EXCLUDED."label_key", "icon" = EXCLUDED."icon",
|
||||
"sort_order" = EXCLUDED."sort_order", "is_active" = EXCLUDED."is_active";
|
||||
@@ -378,6 +378,8 @@ model User {
|
||||
fitbitConnection FitbitConnection?
|
||||
fitbitOAuthStates FitbitOAuthState[]
|
||||
moodEntries MoodEntry[]
|
||||
moodTagsCustom MoodTag[] @relation("UserMoodTags")
|
||||
moodTagsHidden MoodTagHidden[]
|
||||
notificationChannels NotificationChannel[]
|
||||
pushSubscriptions PushSubscription[]
|
||||
dataBackups DataBackup[]
|
||||
@@ -2131,13 +2133,42 @@ model MoodTag {
|
||||
/// analytics layer flips the sign so "up" always reads as "better".
|
||||
inverse Boolean @default(false) @map("inverse")
|
||||
|
||||
/// v1.13.0 — owner of a per-user custom tag. NULL = the global catalogue
|
||||
/// (every row seeded by migration; resolves `labelKey` against the locale).
|
||||
/// Set = a user's own custom tag, carrying a `custom:<cuid>` key and a
|
||||
/// free-text label held in `labelEncrypted`.
|
||||
userId String? @map("user_id")
|
||||
/// v1.13.0 — AES-256-GCM ciphertext of a custom tag's free-text label
|
||||
/// (user prose, possibly health-adjacent — e.g. "Migräne", "Therapie").
|
||||
/// NULL for catalogue rows. Decrypted server-side for the effective read.
|
||||
labelEncrypted String? @map("label_encrypted")
|
||||
|
||||
category MoodTagCategory @relation(fields: [categoryId], references: [id], onDelete: Cascade)
|
||||
user User? @relation("UserMoodTags", fields: [userId], references: [id], onDelete: Cascade)
|
||||
links MoodEntryTagLink[]
|
||||
hiddenBy MoodTagHidden[]
|
||||
|
||||
@@index([categoryId, sortOrder])
|
||||
@@index([userId])
|
||||
@@map("mood_tags")
|
||||
}
|
||||
|
||||
/// v1.13.0 — per-user hide of a CATALOGUE tag. Present = hidden from that
|
||||
/// user's effective picker; absent = visible. A custom tag is hidden by
|
||||
/// flipping its own `MoodTag.isActive` instead, never via this table.
|
||||
model MoodTagHidden {
|
||||
userId String @map("user_id")
|
||||
moodTagId String @map("mood_tag_id")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
moodTag MoodTag @relation(fields: [moodTagId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@id([userId, moodTagId])
|
||||
@@index([moodTagId])
|
||||
@@map("mood_tag_hidden")
|
||||
}
|
||||
|
||||
// Join: which structured tags a mood entry carries. Composite PK keeps
|
||||
// the pairing unique; cascade on both sides so deleting an entry (or a
|
||||
// catalog tag) cleans up its links. Distinct from the flat `tags` JSON
|
||||
|
||||
Reference in new issue
Block a user