Add complete snitch feature with contact management, consent system, and notification delivery

This commit is contained in:
2026-02-16 20:14:03 -06:00
parent 69163a37d1
commit a6ae4e13fd
6 changed files with 810 additions and 0 deletions

View File

@@ -250,3 +250,46 @@ CREATE TABLE IF NOT EXISTS medication_schedules (
CREATE INDEX IF NOT EXISTS idx_med_schedules_user_date ON medication_schedules(user_uuid, adjustment_date);
CREATE INDEX IF NOT EXISTS idx_med_schedules_status ON medication_schedules(status);
-- ── Snitch System ─────────────────────────────────────────────
CREATE TABLE IF NOT EXISTS snitch_settings (
id UUID PRIMARY KEY,
user_uuid UUID REFERENCES users(id) ON DELETE CASCADE UNIQUE,
snitch_enabled BOOLEAN DEFAULT FALSE,
trigger_after_nags INTEGER DEFAULT 4,
trigger_after_missed_doses INTEGER DEFAULT 1,
max_snitches_per_day INTEGER DEFAULT 2,
require_consent BOOLEAN DEFAULT TRUE,
consent_given BOOLEAN DEFAULT FALSE,
snitch_cooldown_hours INTEGER DEFAULT 4,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS snitch_contacts (
id UUID PRIMARY KEY,
user_uuid UUID REFERENCES users(id) ON DELETE CASCADE,
contact_name VARCHAR(255) NOT NULL,
contact_type VARCHAR(50) NOT NULL,
contact_value VARCHAR(255) NOT NULL,
priority INTEGER DEFAULT 1,
notify_all BOOLEAN DEFAULT FALSE,
is_active BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS snitch_log (
id UUID PRIMARY KEY,
user_uuid UUID REFERENCES users(id) ON DELETE CASCADE,
contact_id UUID REFERENCES snitch_contacts(id) ON DELETE SET NULL,
medication_id UUID REFERENCES medications(id) ON DELETE SET NULL,
trigger_reason VARCHAR(100) NOT NULL,
snitch_count_today INTEGER DEFAULT 1,
message_content TEXT,
sent_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
delivered BOOLEAN DEFAULT FALSE
);
CREATE INDEX IF NOT EXISTS idx_snitch_log_user_date ON snitch_log(user_uuid, DATE(sent_at));
CREATE INDEX IF NOT EXISTS idx_snitch_contacts_user ON snitch_contacts(user_uuid, is_active);