data-migrate icon indicating copy to clipboard operation
data-migrate copied to clipboard

Reset column information in-between each migration

Open caius opened this issue 2 years ago • 3 comments

We ran into an issue where having the following run in the same rake db:migrate:with_data process caused an issue:

  1. Data migration that writes to a table
  2. Schema migration that adds a new column to the table
  3. Data migration that writes to the same table

We ended up needing to call ActiveRecord::Base#reset_column_information) as documented in the rails guides between amending the table and trying to write to it in the same ruby process. (If you split any of the above migration files into different runs, this issue goes away.)

Rather than have to remember to call reset_column_information every time we either amend a table or try to write to a table in either schema or data migrations respectively, lets just call it for all models before we run either migration. It's a very low cost call from testing and migrations aren't usually run all that often (certainly compared to web requests).

caius avatar Apr 19 '23 09:04 caius

@ilyakatz is there any appetite for accepting this patch upstream please?

caius avatar Dec 05 '23 17:12 caius

Hi @caius i'm not actively involved in this anymore. I see that @ngan assigned himself to this request though, thanks, Ngan!

ilyakatz avatar Dec 12 '23 01:12 ilyakatz

Hey @caius -- we're in the middle of refactoring how migrations are run and will look to incorporate this after the dust settles.

ngan avatar Jan 11 '24 23:01 ngan