What is in the ip_number_from column?
In any case, I would probably:
- create a new bigint column,
- copy data from ip_number_from to new_column manually through the rails console or the rake command,
- remove source ip_number_from column
- rename new_column to ip_number_from
Or you could go down to SQL, as mjtko suggested, but I'm not sure if this will be easier.
Update
I looked what Yul offers. I think it would be a little dangerous to do all this in one migration, since you cannot check if the casting / copying of data was successful. If you want to do this in one go, in your case it will look something like this:
def up add_column :table, :new_column, :bigint Model.reset_column_information Model.all.each do |m| m.update_attribute :new_column, Model.bigint_from_ip_number_from(m) end drop_column :table, :ip_number_from rename_column :table, :new_column, :ip_number_from end
Then you must add the corresponding migration down.
You can always divide this into several migrations and check the progress / success as you progress.
source share