Yimaru-BackEnd/db/migrations/000002_notification.up.sql

48 lines
1.6 KiB
SQL

CREATE TABLE IF NOT EXISTS notifications (
id VARCHAR(255) NOT NULL PRIMARY KEY,
recipient_id BIGSERIAL NOT NULL,
type TEXT NOT NULL CHECK (
type IN (
'cash_out_success',
'deposit_success',
'bet_placed',
'daily_report',
'high_loss_on_bet',
'bet_overload',
'signup_welcome',
'otp_sent'
)
),
level TEXT NOT NULL CHECK (level IN ('info', 'error', 'warning', 'success')),
error_severity TEXT CHECK (
error_severity IN ('low', 'medium', 'high', 'critical', 'fatal')
),
reciever TEXT NOT NULL CHECK (reciever IN ('admin', 'customer')),
is_read BOOLEAN NOT NULL DEFAULT FALSE,
delivery_status TEXT NOT NULL CHECK (delivery_status IN ('pending', 'sent', 'failed')),
delivery_channel TEXT CHECK (
delivery_channel IN ('email', 'sms', 'push', 'in-app')
),
payload JSONB NOT NULL,
priority INTEGER,
version INTEGER NOT NULL DEFAULT 0,
timestamp TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
metadata JSONB
);
CREATE TABLE IF NOT EXISTS wallet_threshold_notifications (
company_id BIGINT NOT NULL,
threshold FLOAT NOT NULL,
notified_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (company_id, threshold)
);
CREATE INDEX idx_wallet_threshold_notifications_company ON wallet_threshold_notifications(company_id);
CREATE INDEX idx_notifications_recipient_id ON notifications (recipient_id);
CREATE INDEX idx_notifications_timestamp ON notifications (timestamp);
CREATE INDEX idx_notifications_type ON notifications (type);