26 lines
1 KiB
SQL
26 lines
1 KiB
SQL
-- Notifications (in-app)
|
|
CREATE TABLE IF NOT EXISTS notifications (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
title VARCHAR(255) NOT NULL,
|
|
body TEXT,
|
|
type VARCHAR(50), -- APPROVAL, LEAD, JOB, PAYMENT
|
|
reference_id UUID,
|
|
is_read BOOLEAN NOT NULL DEFAULT false,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
);
|
|
|
|
-- Email logs (audit trail)
|
|
CREATE TABLE IF NOT EXISTS email_logs (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
user_id UUID REFERENCES users(id),
|
|
trigger VARCHAR(100) NOT NULL, -- PROFILE_APPROVED, JOB_APPROVED, etc.
|
|
to_email VARCHAR(255) NOT NULL,
|
|
subject VARCHAR(500),
|
|
status VARCHAR(20) NOT NULL DEFAULT 'PENDING', -- PENDING, SENT, FAILED
|
|
sent_at TIMESTAMPTZ
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_notifications_user_id ON notifications(user_id);
|
|
CREATE INDEX IF NOT EXISTS idx_notifications_is_read ON notifications(is_read);
|
|
CREATE INDEX IF NOT EXISTS idx_email_logs_user_id ON email_logs(user_id);
|