Skip to main content

Phoenix

Migrations

Use the Ecto.Migration.execute/1 function.

First, create a migration:

mix ecto.gen.migration electrify_items

Then e.g.:

defmodule MyApp.Repo.Migrations.ElectrifyItems do
use Ecto.Migration

def change do
execute "ALTER TABLE items ENABLE ELECTRIC"
end
end

Event sourcing

There are quite a few options in Elixir for event sourcing. Two to flag up include:

  • cainophile/cainophile for consuming a logical replication stream
  • cpursley/walex for listening to Postgres change events and doing stuff directly in Elixir
  • Oban for running jobs in response to database writes

You can also see the Electric source code for consuming Postgres logical replication.