-- Enhanced AI Notification with Predictive Timing -- Add new fields for scheduled notifications and AI prediction metadata -- Add new status 'scheduled' and 'cancelled' to existing enum -- Note: This depends on your Prisma schema, adjust as needed -- Add new columns for predictive timing ALTER TABLE `AINotification` ADD COLUMN `ScheduledAt_AIN` DATETIME(3) NULL COMMENT 'AI-predicted optimal delivery time', ADD COLUMN `PredictedConfidence_AIN` INT NULL COMMENT 'AI confidence score (0-100)', ADD COLUMN `PredictionReasoning_AIN` VARCHAR(255) NULL COMMENT 'AI reasoning for timing prediction', ADD COLUMN `UserEngagementPattern_AIN` VARCHAR(50) NULL COMMENT 'Detected user pattern: morning_active, evening_active, etc', ADD COLUMN `DelayMinutes_AIN` INT NULL COMMENT 'Delay in minutes from creation to scheduled delivery'; -- Update SentStatus_AIN to support new statuses -- If using ENUM, you'll need to modify it: -- ALTER TABLE `AINotification` -- MODIFY COLUMN `SentStatus_AIN` ENUM('pending', 'scheduled', 'sent', 'delivered', 'failed', 'cancelled') NOT NULL DEFAULT 'pending'; -- Add index for scheduled notifications query performance CREATE INDEX `idx_scheduled_notifications` ON `AINotification`(`SentStatus_AIN`, `ScheduledAt_AIN`); -- Add index for user engagement pattern analysis CREATE INDEX `idx_user_pattern` ON `AINotification`(`UserID_AIN`, `UserEngagementPattern_AIN`); -- Optional: Add constraint to ensure scheduled notifications have ScheduledAt_AIN -- ALTER TABLE `AINotification` -- ADD CONSTRAINT `chk_scheduled_has_time` -- CHECK (`SentStatus_AIN` != 'scheduled' OR `ScheduledAt_AIN` IS NOT NULL);