feat: Scheduled Maintenance feature complete
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
-- user_notifications: In-app notification center for users
|
||||
CREATE TABLE user_notifications (
|
||||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||
user_id VARCHAR(255) NOT NULL,
|
||||
notification_type VARCHAR(50) NOT NULL,
|
||||
title VARCHAR(255) NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
reference_type VARCHAR(50),
|
||||
reference_id UUID,
|
||||
vehicle_id UUID,
|
||||
is_read BOOLEAN DEFAULT false,
|
||||
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||
read_at TIMESTAMP WITH TIME ZONE
|
||||
);
|
||||
|
||||
-- Indexes for performance
|
||||
CREATE INDEX idx_user_notifications_user_id ON user_notifications(user_id);
|
||||
CREATE INDEX idx_user_notifications_created_at ON user_notifications(created_at DESC);
|
||||
CREATE INDEX idx_user_notifications_unread ON user_notifications(user_id, created_at DESC) WHERE is_read = false;
|
||||
@@ -0,0 +1,21 @@
|
||||
-- sent_notification_tracker: Prevent duplicate notifications for schedules
|
||||
CREATE TABLE sent_notification_tracker (
|
||||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||
schedule_id UUID NOT NULL,
|
||||
notification_date DATE NOT NULL,
|
||||
reminder_level INTEGER NOT NULL CHECK (reminder_level IN (1, 2, 3)),
|
||||
delivery_method VARCHAR(20) NOT NULL CHECK (delivery_method IN ('email', 'in_app', 'both')),
|
||||
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT fk_sent_notification_schedule
|
||||
FOREIGN KEY (schedule_id)
|
||||
REFERENCES maintenance_schedules(id)
|
||||
ON DELETE CASCADE,
|
||||
|
||||
CONSTRAINT unique_notification_per_schedule_date_level
|
||||
UNIQUE (schedule_id, notification_date, reminder_level)
|
||||
);
|
||||
|
||||
-- Indexes for performance
|
||||
CREATE INDEX idx_sent_notification_tracker_schedule_id ON sent_notification_tracker(schedule_id);
|
||||
CREATE INDEX idx_sent_notification_tracker_notification_date ON sent_notification_tracker(notification_date);
|
||||
Reference in New Issue
Block a user