Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset column information in-between each migration #251

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

caius
Copy link

@caius caius commented Apr 19, 2023

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).

Writing to a table in one migration, amending the columns in another migration then trying to write to the same table blows up when all the migrations are in the same run. Resetting the column information on all models between migrations doesn't add much time at all, but avoids that being an issue.
@caius
Copy link
Author

caius commented Dec 5, 2023

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

@ngan ngan self-assigned this Dec 9, 2023
@ilyakatz
Copy link
Owner

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

@ngan
Copy link
Collaborator

ngan commented Jan 11, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants