Proposal: before_begin/after_commit callbacks for migrations

22 views
Skip to first unread message

Nassim ABDELGHANI

unread,
Oct 7, 2026, 11:28:00 AM (2 days ago) Oct 7
to elixir-ecto

Some sqlite schema changes need a command to run before the migration transaction opens. The procedure in the sqlite docs first disables the foreign key check with PRAGMA foreign_keys https://sqlite.org/lang_altertable.html#making_other_kinds_of_table_schema_changes
It is a no-op inside a transaction, that's why it has to happen outside.

One solution currently is to set @disable_ddl_transaction true, running the PRAGMA, then opening a transaction by hand in the migration. However that way, the migration transaction commits inside up/0, and the schema_migrations row is only written afterwards, outside the transaction.

If something fails in between, the schema has changed but the migration isn't recorded. Running it again either fails with a confusing error ("there is already another table with this name") or applies the migration a second time.

Is there a way to run a migration inside a transaction together with the schema_migrations update, while running the required PRAGMA outside?

If there is not, the proposal would be optional before_begin/0 and after_commit/0 callbacks, run outside the transaction but on the same checked-out connection, so a PRAGMA set in before_begin applies to the transaction that follows.

What do you think?

José Valim

unread,
Oct 7, 2026, 12:40:13 PM (2 days ago) Oct 7
to elixi...@googlegroups.com
Yes, please do send a PR!


--
You received this message because you are subscribed to the Google Groups "elixir-ecto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-ecto...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/elixir-ecto/c261364d-fd9d-4a25-9dd8-050b1ae708f5n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages