-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/monitor names in alert configs (#95)
* feat: Add migration to add `monitor_name` to `monitor_alert_config`, mirroring `monitor.name` * feat: Make `AlertConfig` domain model include Monitor name as well as monitor ID * feat: Infra changes to support `AlertConfig` domain model including names of monitors * chore: Add comment to explain how trigger keeps `monitor_alert_config.monitor_name` up to date with `monitor.name`
- Loading branch information
Showing
8 changed files
with
170 additions
and
52 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
5 changes: 5 additions & 0 deletions
5
...src/infrastructure/migrations/2024-12-13-222551_add-name-to-monitor-alert-config/down.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,5 @@ | ||
-- Drop trigger and function | ||
DROP TRIGGER IF EXISTS monitor_name_update ON monitor; | ||
DROP FUNCTION IF EXISTS update_monitor_alert_config_monitor_name; | ||
|
||
ALTER TABLE monitor_alert_config DROP monitor_name; |
30 changes: 30 additions & 0 deletions
30
api/src/infrastructure/migrations/2024-12-13-222551_add-name-to-monitor-alert-config/up.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,30 @@ | ||
-- Add name to monitor_alert_config, nullable for now. | ||
ALTER TABLE monitor_alert_config | ||
ADD monitor_name VARCHAR NULL; | ||
|
||
-- Set the names to what they are currently, then make the column non-nullable. | ||
UPDATE monitor_alert_config | ||
SET monitor_name = monitor.name | ||
FROM monitor | ||
WHERE monitor_alert_config.monitor_id = monitor.monitor_id; | ||
|
||
ALTER TABLE monitor_alert_config | ||
ALTER COLUMN monitor_name SET NOT NULL; | ||
|
||
-- Create a trigger function for updating the monitor name in monitor_alert_config. | ||
CREATE OR REPLACE FUNCTION update_monitor_alert_config_monitor_name() | ||
RETURNS TRIGGER AS $$ | ||
BEGIN | ||
UPDATE monitor_alert_config | ||
SET monitor_name = NEW.name | ||
WHERE monitor_id = NEW.monitor_id; | ||
RETURN NEW; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
|
||
-- Apply the trigger to the monitor table so that when name changes, the changes are | ||
-- reflected in the monitor_alert_config table. | ||
CREATE TRIGGER monitor_name_update | ||
AFTER UPDATE OF name ON monitor | ||
FOR EACH ROW | ||
EXECUTE FUNCTION update_monitor_alert_config_monitor_name(); |
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.