-- 019_notify_targets_signal_shares.sql — notifications phase 2 (Gitea #10). -- -- Additive and idempotent; schema.sql carries the identical final shape, so -- this is a structural no-op on a fresh database (db-converge proves both -- paths land the same). Constraint names are restated explicitly so the -- migrated catalog matches schema.sql's inline CHECKs exactly. -- -- 1. share_received trigger: notify a user when a bookmark, tag or -- collection is shared with them (scanner pattern unchanged: producers -- stay uninstrumented, exactly-once via UNIQUE("ruleId","dedupeKey")). -- 2. signal channel kind (signal-cli REST bridge delivery). -- 3. Per-recipient delivery: Notification.recipientId NULL means the rule -- owner (phase-1 behaviour); a non-NULL recipient is a targeted user and -- is delivered through THAT user's own enabled channel of the rule's -- kind (targets are validated same-tenant at rule write time). -- 4. Branding footer ("Managed by David's Superbrain.") is applied at -- delivery time from the recipient tenant's plan (entitlements -- ManagedFooter: free only) — data, not a code fork. ALTER TABLE "NotificationRule" DROP CONSTRAINT IF EXISTS "NotificationRule_trigger_check"; ALTER TABLE "NotificationRule" ADD CONSTRAINT "NotificationRule_trigger_check" CHECK (trigger IN ('signal_created','bookmark_due','share_received')); ALTER TABLE "NotificationChannel" DROP CONSTRAINT IF EXISTS "NotificationChannel_kind_check"; ALTER TABLE "NotificationChannel" ADD CONSTRAINT "NotificationChannel_kind_check" CHECK (kind IN ('email','slack','matrix','telegram','signal')); ALTER TABLE "Notification" ADD COLUMN IF NOT EXISTS "recipientId" text REFERENCES "User"(id) ON DELETE CASCADE; CREATE INDEX IF NOT EXISTS "Notification_recipientId_idx" ON "Notification"("recipientId");