Allow multiple reminder dates for a single chat group
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
ALTER TABLE chat ADD remind_days_ahead BIGINT NOT NULL DEFAULT 0;
|
||||
|
||||
UPDATE chat SET remind_days_ahead = (SELECT days_ahead FROM reminder WHERE chat_id = chat.id ORDER BY days_ahead ASC LIMIT 1);
|
||||
|
||||
DROP TABLE reminder;
|
||||
13
migrations/2024-01-17-093811_multi_ahead_reminders/up.sql
Normal file
13
migrations/2024-01-17-093811_multi_ahead_reminders/up.sql
Normal file
@@ -0,0 +1,13 @@
|
||||
-- This migration extracts "remind days ahead" into a separate table so that a chat can configure mutiple reminders
|
||||
|
||||
CREATE TABLE reminder (
|
||||
id INTEGER PRIMARY KEY NOT NULL,
|
||||
chat_id INTEGER NOT NULL REFERENCES chat (id) ON DELETE CASCADE,
|
||||
days_ahead BIGINT NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX reminders_chat_id ON reminder (chat_id, days_ahead); -- Having days_ahead as index saves us from taking extra effort for sorted data
|
||||
|
||||
INSERT INTO reminder (chat_id, days_ahead) SELECT id, remind_days_ahead FROM chat;
|
||||
|
||||
ALTER TABLE chat DROP remind_days_ahead;
|
||||
Reference in New Issue
Block a user