Skip to content

Add before_transaction/1 and after_transaction/1 migration callbacks - #758

Merged
josevalim merged 2 commits into
elixir-ecto:masterfrom
a-nassim:around-transaction-migration-callbacks
Oct 8, 2026
Merged

josevalim merged 2 commits into
elixir-ecto:masterfrom
a-nassim:around-transaction-migration-callbacks

Conversation

@a-nassim

@a-nassim a-nassim commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Closes https://groups.google.com/g/elixir-ecto/c/yLHOK68mAgo/m/ymbM0xFRAQAJ

Adds optional before_transaction/1 and after_transaction/1 migration callbacks that run around the migration transaction, on the same checked-out connection, for commands that only work outside one, like SQLite PRAGMA foreign_keys.

  • after_transaction/1 always runs, also on rollback, so state can be restored (that's why it was not named after_commit). Like after_begin/0 and before_commit/0, both are skipped when there is no transaction.
  • They receive the repo as an argument: they run in the migrator, where there is no runner, so repo/0, execute/1, flush/0 and direction/0 are unavailable.
  • Alternative: moving the transaction into Ecto.Migration.Runner which would be more consistent with existing callbacks, but the change is a bit more involved, would you prefer that approach?

@a-nassim
a-nassim marked this pull request as ready for review October 8, 2026 01:56
@josevalim
josevalim merged commit bf126d6 into elixir-ecto:master Oct 8, 2026
9 of 10 checks passed
@josevalim

Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants