Skip to content

Instantly share code, notes, and snippets.

View carterbryden's full-sized avatar

Carter carterbryden

View GitHub Profile
@carterbryden
carterbryden / AddPostgresTriggerAndFunctionForAllTables.exs
Last active December 18, 2023 08:10
Elixir Phoenix Postgresql migration to add triggers for pubsub to run on every CRUD operation on every table. If a new table is added, it'll automatically add a trigger to that table too.
defmodule MyApp.Repo.Migrations.AddPostgresTriggerAndFunctionForAllTables do
use Ecto.Migration
def up do
# Create a function that broadcasts row changes
execute "
CREATE OR REPLACE FUNCTION broadcast_changes()
RETURNS trigger AS $$
DECLARE
current_row RECORD;