Add smart notification reminder system with frequency-aware scheduling
Replaces one-size-fits-all "2 days before" reminders with intelligent
scheduling based on task frequency. Infrequent tasks (annual) get 30-day
advance notice while frequent tasks (weekly) only get day-of reminders.
Key features:
- Frequency-aware pre-reminders: annual (30d, 14d, 7d), quarterly (7d, 3d),
monthly (3d), bi-weekly (1d), daily/weekly/once (day-of only)
- Overdue tapering: daily for 3 days, then every 3 days, stops after 14 days
- Reminder log table prevents duplicate notifications per due date/stage
- Admin endpoint displays notification schedules for all frequencies
- Comprehensive test suite (100 random tasks, 61 days each, 10 test functions)
New files:
- internal/notifications/reminder_config.go - Editable schedule configuration
- internal/notifications/reminder_schedule.go - Schedule lookup logic
- internal/notifications/reminder_schedule_test.go - Dynamic test suite
- internal/models/reminder_log.go - TaskReminderLog model
- internal/repositories/reminder_repo.go - Reminder log repository
- migrations/010_add_task_reminder_log.{up,down}.sql
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
5
migrations/010_add_task_reminder_log.down.sql
Normal file
5
migrations/010_add_task_reminder_log.down.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
-- Rollback: Smart Notification Reminder System
|
||||
|
||||
DROP INDEX IF EXISTS idx_reminderlog_sent_at;
|
||||
DROP INDEX IF EXISTS idx_reminderlog_task_user_date;
|
||||
DROP TABLE IF EXISTS task_reminderlog;
|
||||
24
migrations/010_add_task_reminder_log.up.sql
Normal file
24
migrations/010_add_task_reminder_log.up.sql
Normal file
@@ -0,0 +1,24 @@
|
||||
-- Smart Notification Reminder System
|
||||
-- Tracks which reminders have been sent to prevent duplicates
|
||||
|
||||
CREATE TABLE task_reminderlog (
|
||||
id SERIAL PRIMARY KEY,
|
||||
task_id INTEGER NOT NULL REFERENCES task_task(id) ON DELETE CASCADE,
|
||||
user_id INTEGER NOT NULL REFERENCES auth_user(id) ON DELETE CASCADE,
|
||||
due_date DATE NOT NULL, -- Which occurrence this is for
|
||||
reminder_stage VARCHAR(20) NOT NULL, -- e.g., "reminder_30d", "reminder_7d", "day_of", "overdue_1", "overdue_4"
|
||||
sent_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
||||
notification_id INTEGER REFERENCES notifications_notification(id) ON DELETE SET NULL,
|
||||
|
||||
-- Prevent duplicate reminders for same task/user/date/stage
|
||||
UNIQUE(task_id, user_id, due_date, reminder_stage)
|
||||
);
|
||||
|
||||
-- Index for quick lookup when checking if reminder was already sent
|
||||
CREATE INDEX idx_reminderlog_task_user_date ON task_reminderlog(task_id, user_id, due_date);
|
||||
|
||||
-- Index for cleanup job (delete old logs)
|
||||
CREATE INDEX idx_reminderlog_sent_at ON task_reminderlog(sent_at);
|
||||
|
||||
COMMENT ON TABLE task_reminderlog IS 'Tracks sent task reminders to prevent duplicate notifications';
|
||||
COMMENT ON COLUMN task_reminderlog.reminder_stage IS 'Stage of reminder: reminder_30d, reminder_14d, reminder_7d, reminder_3d, reminder_1d, day_of, overdue_N';
|
||||
Reference in New Issue
Block a user