-- Notifications table (master notification record) CREATE TABLE notifications ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), title VARCHAR(255) NOT NULL, body TEXT, type VARCHAR(100), category VARCHAR(100), priority VARCHAR(50) NOT NULL DEFAULT 'normal' CHECK (priority IN ('low', 'normal', 'high')), image_url VARCHAR(512), action_url VARCHAR(512), notifiable_type VARCHAR(100), notifiable_id UUID, data JSONB, scheduled_at TIMESTAMP WITH TIME ZONE, sent_at TIMESTAMP WITH TIME ZONE, expired_at TIMESTAMP WITH TIME ZONE, created_by UUID REFERENCES users(id) ON DELETE SET NULL, created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(), updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() ); -- Indexes CREATE INDEX idx_notifications_created_by ON notifications(created_by); CREATE INDEX idx_notifications_type ON notifications(type); CREATE INDEX idx_notifications_category ON notifications(category); CREATE INDEX idx_notifications_notifiable ON notifications(notifiable_type, notifiable_id); CREATE INDEX idx_notifications_scheduled_at ON notifications(scheduled_at); CREATE INDEX idx_notifications_sent_at ON notifications(sent_at);