mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 04:50:59 +00:00
feat: scope Telegram reminder tracking to recipients
- keep delegated recipient slots independent\n- bind callback cleanup to the recipient account
This commit is contained in:
1 parent
5807879439
commit
fa46f27b01
6 files changed
+99
-51
No files matched your search
@@ -50,6 +50,34 @@ CREATE TABLE "notification_events" (
|
||||
CREATE INDEX "notification_events_record_user_id_event_type_dedup_key_created_at_desc_idx"
|
||||
ON "notification_events" ("record_user_id", "event_type", "dedup_key", "created_at" DESC);
|
||||
|
||||
-- Tracking belongs to the account that received the Telegram message. The
|
||||
-- prior subject-only key collapsed multiple delegated recipients into one row.
|
||||
ALTER TABLE "telegram_reminder_messages"
|
||||
ADD COLUMN "recipient_user_id" TEXT;
|
||||
|
||||
UPDATE "telegram_reminder_messages" AS "message"
|
||||
SET "recipient_user_id" = "medication"."user_id"
|
||||
FROM "medications" AS "medication"
|
||||
WHERE "medication"."id" = "message"."medication_id";
|
||||
|
||||
ALTER TABLE "telegram_reminder_messages"
|
||||
ALTER COLUMN "recipient_user_id" SET NOT NULL,
|
||||
ADD CONSTRAINT "telegram_reminder_messages_recipient_user_id_fkey"
|
||||
FOREIGN KEY ("recipient_user_id") REFERENCES "users"("id")
|
||||
ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
DROP INDEX "telegram_reminder_messages_med_sched_date_phase_tod_key";
|
||||
|
||||
CREATE UNIQUE INDEX "telegram_reminder_messages_recipient_slot_key"
|
||||
ON "telegram_reminder_messages" (
|
||||
"recipient_user_id",
|
||||
"medication_id",
|
||||
"schedule_id",
|
||||
"date",
|
||||
"phase",
|
||||
"time_of_day"
|
||||
);
|
||||
|
||||
CREATE FUNCTION enforce_push_attempt_attribution()
|
||||
RETURNS TRIGGER
|
||||
LANGUAGE plpgsql
|
||||
|
||||
+15
-12
@@ -863,6 +863,7 @@ model User {
|
||||
pushAttemptsForRecord PushAttempt[] @relation("PushAttemptRecordUser")
|
||||
pushAttemptsReceived PushAttempt[] @relation("PushAttemptRecipientUser")
|
||||
notificationEvents NotificationEvent[]
|
||||
telegramReminderMessages TelegramReminderMessage[]
|
||||
// v1.10.3 — per-(user, day) Strain personal-anchor cache (day-total
|
||||
// TRIMP + running EWMA reference) so the nightly Strain engine anchors
|
||||
// the 0–100 map to the user's own training load without re-integrating
|
||||
@@ -3364,24 +3365,26 @@ model ReminderPhaseConfig {
|
||||
}
|
||||
|
||||
model TelegramReminderMessage {
|
||||
id String @id @default(cuid())
|
||||
medicationId String @map("medication_id")
|
||||
scheduleId String @map("schedule_id")
|
||||
chatId String @map("chat_id")
|
||||
messageId Int @map("message_id")
|
||||
phase ReminderPhase
|
||||
sentAt DateTime @default(now()) @map("sent_at")
|
||||
date String // YYYY-MM-DD for day grouping
|
||||
id String @id @default(cuid())
|
||||
recipientUserId String @map("recipient_user_id")
|
||||
medicationId String @map("medication_id")
|
||||
scheduleId String @map("schedule_id")
|
||||
chatId String @map("chat_id")
|
||||
messageId Int @map("message_id")
|
||||
phase ReminderPhase
|
||||
sentAt DateTime @default(now()) @map("sent_at")
|
||||
date String // YYYY-MM-DD for day grouping
|
||||
/// v1.7.0 — time-of-day this reminder belongs to (HH:mm, user-local).
|
||||
/// Empty string = the single legacy window (pre-v1.7 rows + single-time
|
||||
/// schedules). Part of the dedup key so a multi-time schedule dispatches
|
||||
/// once per time-of-day per phase per day instead of once per day.
|
||||
timeOfDay String @default("") @map("time_of_day")
|
||||
timeOfDay String @default("") @map("time_of_day")
|
||||
|
||||
medication Medication @relation(fields: [medicationId], references: [id], onDelete: Cascade)
|
||||
schedule MedicationSchedule @relation(fields: [scheduleId], references: [id], onDelete: Cascade)
|
||||
recipientUser User @relation(fields: [recipientUserId], references: [id], onDelete: Cascade)
|
||||
medication Medication @relation(fields: [medicationId], references: [id], onDelete: Cascade)
|
||||
schedule MedicationSchedule @relation(fields: [scheduleId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([medicationId, scheduleId, date, phase, timeOfDay], map: "telegram_reminder_messages_med_sched_date_phase_tod_key")
|
||||
@@unique([recipientUserId, medicationId, scheduleId, date, phase, timeOfDay], map: "telegram_reminder_messages_recipient_slot_key")
|
||||
@@index([medicationId, date])
|
||||
@@map("telegram_reminder_messages")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user