Yimaru-BackEnd/db/migrations/000002_notification.up.sql
Samuel Tariku 0ffba57ec5 feat: Refactor report generation and management
- Removed detailed event routes from the API.
- Added new report request routes for creating and fetching report requests.
- Introduced new domain models for report requests, including metadata and status handling.
- Implemented report request processing logic, including CSV generation for event interval reports.
- Enhanced company statistics handling with new domain models and service methods.
- Updated repository interfaces and implementations to support new report functionalities.
- Added error handling and logging for report file operations and notifications.
2025-10-28 00:51:52 +03:00

54 lines
2.0 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',
'withdraw_success',
'bet_placed',
'daily_report',
'report_request',
'high_loss_on_bet',
'bet_overload',
'signup_welcome',
'otp_sent',
'wallet_threshold',
'wallet_updated',
'transfer_failed',
'transfer_success',
'admin_alert',
'bet_result',
'transfer_rejected',
'approval_required',
'bonus_awarded'
)
),
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,
img TEXT,
expires TIMESTAMPTZ NOT NULL,
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);