Skip to content

Commit

Permalink
Merge pull request #1340 from alphagov/add-posgres-notify-trigger
Browse files Browse the repository at this point in the history
Add Postgres notify trigger for route updates
  • Loading branch information
theseanything authored Nov 12, 2024
2 parents 1d70d11 + 5678999 commit d211bf8
Show file tree
Hide file tree
Showing 5 changed files with 574 additions and 118 deletions.
3 changes: 3 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class Application < Rails::Application
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")

# Make sure schema contains triggers
config.active_record.schema_format = :sql

# Don't generate system test files.
config.generators.system_tests = nil

Expand Down
38 changes: 38 additions & 0 deletions db/migrate/20241105135438_add_notify_trigger_for_route_changes.rb
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
118 changes: 0 additions & 118 deletions db/schema.rb

This file was deleted.

Loading

0 comments on commit d211bf8

Please sign in to comment.