We have a problem regarding a migration when we try to update some data contained in a table.
Our base model looks like this:
User
- username
- password
- …
We created a first migration to add a column in the model and then update the existing rows:
add_column :users, :deleted, :boolean
User.all.each do |user|
user.deleted = false
user.save
end
The second migration is supposed to create a last_name column and rename the username column to first_name:
rename_column :users, :username, :first_name
add_column :users, :last_name, :string
It worked without any problem in development because the second migration was created several days after the first one (so everyone had enough time to apply the first well before the second one).
The problem we have is when we try to deploy those migrations it in staging/production to the following model:
class User < ActiveRecord::Base
attr_accessible :first_name,
:last_name,
:password,
:password_confirmation,
...
...
end
The first migration fails on the save because first_name and last_name don't exist yet although they're present in attr_accessible.
The problem persists even if we try to bypass validation.
Did you ever have this kind of issue and could you help us bypass it because we'd like to stick to full ruby code without writing any SQL?