Files
growqr-backend/drizzle/0008_home_notifications.sql
2026-06-04 21:36:58 +05:30

37 lines
1.5 KiB
SQL

CREATE TABLE IF NOT EXISTS grow_home_notifications (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
module_id TEXT NOT NULL,
title TEXT NOT NULL,
subtitle TEXT NOT NULL,
tag TEXT NOT NULL,
urgency TEXT NOT NULL DEFAULT 'calm',
href TEXT NOT NULL,
source TEXT,
source_ref JSONB,
priority INTEGER NOT NULL DEFAULT 0,
generated_by TEXT NOT NULL DEFAULT 'deterministic',
reason TEXT,
status TEXT NOT NULL DEFAULT 'active',
expires_at TIMESTAMPTZ,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
CONSTRAINT grow_home_notifications_module_check
CHECK (module_id IN ('suggestions', 'missions', 'social', 'pathways', 'productivity', 'rewards')),
CONSTRAINT grow_home_notifications_urgency_check
CHECK (urgency IN ('now', 'today', 'soon', 'calm')),
CONSTRAINT grow_home_notifications_generated_by_check
CHECK (generated_by IN ('deterministic', 'agent', 'demo', 'manual')),
CONSTRAINT grow_home_notifications_status_check
CHECK (status IN ('active', 'dismissed', 'expired'))
);
CREATE INDEX IF NOT EXISTS grow_home_notifications_user_idx
ON grow_home_notifications(user_id, status, priority DESC);
CREATE INDEX IF NOT EXISTS grow_home_notifications_module_idx
ON grow_home_notifications(user_id, module_id, status);
CREATE INDEX IF NOT EXISTS grow_home_notifications_expiry_idx
ON grow_home_notifications(expires_at);