postgres-shift icon indicating copy to clipboard operation
postgres-shift copied to clipboard

Wrap each migration into its own transaction

Open kruszczynski opened this issue 7 months ago • 0 comments

Hi!

I appreciate postgres-shift a lot! It's a wonderful, small, single purpose library. Thanks for creating it!

I come here with a suggestion to wrap each migration into its own transaction.

I grew up in Ruby on Rails universe and their transactions do this. As do the transactions in Ecto, Elixir's ORM.

I learned why it might be a good idea this week. I was extending a postgres Enum and then creating backfill records that used the newly created value. Instinctively I did that in separate migrations.

I didn't notice any issues in development because I ran each migration as I was writing it. Only once I shipped both migration in one PR I learned on our staging environment that one cannot create records referencing enum values added in the same transaction.

So please let me know if you'd consider adding this and releasing an updated version.

All the best, Bartek

kruszczynski avatar Jul 11 '24 13:07 kruszczynski