jackc / tern

The SQL Fan's Migrator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wrapping migration files in transactions

lzap opened this issue · comments

Hello,

since tern use transactions for each migration, is it safe to wrap each migration file between BEGIN/COMMIT statements? We are migrating from golang-migrate to tern and we have these, so I wonder if I need to remove them. It appears to work just fine, but would love to hear an official word :)

Thanks!

The begin would be ignored as you are already in a transaction. But the commit would actually commit the transaction.

The only problem is a failure that occurred in the tiny window between finishing your migration and tern updating the version table would mean your migration would have been applied but that fact didn't get recorded. Hence a subsequent migration run would attempt to rerun the same migration.

Ok so the recommendation is not to have these BEGIN/COMMIT statements in migration files. Removed, thanks!