Skip to content

Instantly share code, notes, and snippets.

View bdelmas's full-sized avatar

Benjamin Delmas bdelmas

View GitHub Profile
require 'active_support/concern'
require 'active_support/core_ext/object/blank'
require 'action_view/buffers'
require 'action_view/helpers/output_safety_helper'
require 'action_view/helpers/capture_helper'
require 'action_view/helpers/tag_helper'
require 'benchmark/ips'
@carterbryden
carterbryden / AddPostgresTriggerAndFunctionForAllTables.exs
Last active February 4, 2025 19:16
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;