3

I have data in a Users table. One column called :provider_user_id of datatype float.

I want to change it to data type bigint.

How should I write this migration in rails 3

The original column was created with the following migration:

class AddFbuidToUsers < ActiveRecord::Migration
  def self.up
    add_column :users, :provider_user_id, :float
  end

  def self.down
    remove_column :users, :provider_user_id
  end
end
chell
  • 7,646
  • 16
  • 74
  • 140

2 Answers2

5
change_column :users, :provider_user_id, :bigint
sosiouxme
  • 1,226
  • 16
  • 26
0

Add a new column of type bigint, any name will do.

Write an update loop to update each new bigint column with the value in your current column

Drop the old column (hopefully no RI on it).

Rename the new column to that of the just-dropped old column.

MotownJoe
  • 78
  • 5