-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1340 from alphagov/add-posgres-notify-trigger
Add Postgres notify trigger for route updates
- Loading branch information
Showing
5 changed files
with
574 additions
and
118 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
38 changes: 38 additions & 0 deletions
38
db/migrate/20241105135438_add_notify_trigger_for_route_changes.rb
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,38 @@ | ||
class AddNotifyTriggerForRouteChanges < ActiveRecord::Migration[7.2] | ||
def up | ||
execute <<-SQL | ||
CREATE OR REPLACE FUNCTION notify_route_change() RETURNS trigger AS $$ | ||
BEGIN | ||
PERFORM pg_notify('route_changes', ''); | ||
RETURN OLD; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
SQL | ||
|
||
execute <<-SQL | ||
CREATE TRIGGER content_item_change_trigger | ||
AFTER INSERT OR UPDATE OR DELETE ON content_items | ||
FOR EACH ROW EXECUTE PROCEDURE notify_route_change(); | ||
SQL | ||
|
||
execute <<-SQL | ||
CREATE TRIGGER publish_intent_change_trigger | ||
AFTER INSERT OR UPDATE OR DELETE ON publish_intents | ||
FOR EACH ROW EXECUTE PROCEDURE notify_route_change(); | ||
SQL | ||
end | ||
|
||
def down | ||
execute <<-SQL | ||
DROP TRIGGER IF EXISTS content_item_change_trigger ON content_items; | ||
SQL | ||
|
||
execute <<-SQL | ||
DROP TRIGGER IF EXISTS publish_intent_change_trigger ON publish_intents; | ||
SQL | ||
|
||
execute <<-SQL | ||
DROP FUNCTION IF EXISTS notify_route_change(); | ||
SQL | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.