jackc / tern

The SQL Fan's Migrator
MIT License
850 stars 66 forks source link

Wrapping migration files in transactions #60

Closed lzap closed 2 years ago

lzap commented 2 years ago

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!

jackc commented 2 years ago

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.

lzap commented 2 years ago

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