-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
We're about to add several more reminder notifications for planting sites, and it will start to get a little unwieldy to have a separate column in the planting sites table to keep track of each one. Create a new table `planting_site_notifications` that tracks how many of each type of notification we've sent for a planting site. This models the reminder notifications a bit differently than before: they are considered to have the same notification type but a different "notification number" where the first notification about something is number 1, the first reminder is number 2, etc.
- Loading branch information
Showing
12 changed files
with
231 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 45 additions & 30 deletions
75
src/main/kotlin/com/terraformation/backend/tracking/model/NotificationCriteria.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/resources/db/migration/0200/V225__PlantingSiteNotifications.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
CREATE TABLE tracking.planting_site_notifications ( | ||
id BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, | ||
planting_site_id BIGINT NOT NULL REFERENCES tracking.planting_sites ON DELETE CASCADE, | ||
notification_type_id INTEGER NOT NULL REFERENCES notification_types, | ||
notification_number INTEGER NOT NULL, | ||
sent_time TIMESTAMP WITH TIME ZONE NOT NULL, | ||
|
||
UNIQUE (planting_site_id, notification_type_id, notification_number) | ||
); | ||
|
||
-- These are also in R__TypeCodes.sql | ||
INSERT INTO notification_criticalities (id, name) | ||
VALUES (1, 'Info') | ||
ON CONFLICT DO NOTHING; | ||
INSERT INTO notification_types (id, name, notification_criticality_id) | ||
VALUES (21, 'Observation Not Scheduled (Support)', 1); | ||
|
||
INSERT INTO tracking.planting_site_notifications | ||
(planting_site_id, notification_type_id, notification_number, sent_time) | ||
SELECT ps.id, nt.id, 1, ps.schedule_observation_notification_sent_time | ||
FROM tracking.planting_sites ps, notification_types nt | ||
WHERE ps.schedule_observation_notification_sent_time IS NOT NULL | ||
AND nt.name = 'Schedule Observation'; | ||
|
||
INSERT INTO tracking.planting_site_notifications | ||
(planting_site_id, notification_type_id, notification_number, sent_time) | ||
SELECT ps.id, nt.id, 2, ps.schedule_observation_reminder_notification_sent_time | ||
FROM tracking.planting_sites ps, notification_types nt | ||
WHERE ps.schedule_observation_reminder_notification_sent_time IS NOT NULL | ||
AND nt.name = 'Schedule Observation'; | ||
|
||
INSERT INTO tracking.planting_site_notifications | ||
(planting_site_id, notification_type_id, notification_number, sent_time) | ||
SELECT ps.id, nt.id, 1, ps.observation_not_scheduled_first_notification_sent_time | ||
FROM tracking.planting_sites ps, notification_types nt | ||
WHERE ps.observation_not_scheduled_first_notification_sent_time IS NOT NULL | ||
AND nt.name = 'Observation Not Scheduled (Support)'; | ||
|
||
INSERT INTO tracking.planting_site_notifications | ||
(planting_site_id, notification_type_id, notification_number, sent_time) | ||
SELECT ps.id, nt.id, 2, ps.observation_not_scheduled_second_notification_sent_time | ||
FROM tracking.planting_sites ps, notification_types nt | ||
WHERE ps.observation_not_scheduled_second_notification_sent_time IS NOT NULL | ||
AND nt.name = 'Observation Not Scheduled (Support)'; | ||
|
||
-- Usually we would drop columns in a separate migration to avoid breaking the old code while the | ||
-- new release is being rolled out, but in this case we do it all in one migration. | ||
-- | ||
-- If notifications are being generated on another instance while this migration is running, the | ||
-- notification job will fail because we're dropping these columns. The next run will generate | ||
-- any missing notifications. | ||
ALTER TABLE tracking.planting_sites DROP COLUMN observation_not_scheduled_first_notification_sent_time; | ||
ALTER TABLE tracking.planting_sites DROP COLUMN observation_not_scheduled_second_notification_sent_time; | ||
ALTER TABLE tracking.planting_sites DROP COLUMN schedule_observation_notification_sent_time; | ||
ALTER TABLE tracking.planting_sites DROP COLUMN schedule_observation_reminder_notification_sent_time; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.