finalized reminder notification system migrations

This commit is contained in:
2026-03-21 12:58:38 +08:00
parent b2c3202317
commit 7d9096963a
5 changed files with 530 additions and 27 deletions
@@ -45,7 +45,7 @@ BEGIN
SELECT id AS schedule_id, user_id AS user_id, start_time AS start_at
FROM public.duty_schedules
WHERE start_time BETWEEN now() + interval '15 minutes' - interval '30 seconds' AND now() + interval '15 minutes' + interval '30 seconds'
AND status = 'active'
AND status IN ('arrival', 'late')
LOOP
-- Skip if user already checked in for this duty (attendance_logs references duty_schedule_id)
IF EXISTS (SELECT 1 FROM public.attendance_logs al WHERE al.duty_schedule_id = rec.schedule_id AND al.check_in_at IS NOT NULL) THEN
@@ -62,7 +62,7 @@ BEGIN
SELECT id AS schedule_id, user_id AS user_id, end_time AS end_at
FROM public.duty_schedules
WHERE end_time BETWEEN now() - interval '30 seconds' AND now() + interval '30 seconds'
AND status = 'active'
AND status IN ('arrival', 'late')
LOOP
INSERT INTO public.scheduled_notifications (schedule_id, user_id, notify_type, scheduled_for)
VALUES (rec.schedule_id, rec.user_id, 'end', rec.end_at)