Last active
August 29, 2015 13:56
-
-
Save rusllonrails/9020112 to your computer and use it in GitHub Desktop.
POSTGRES CHANGE COLUMN TYPE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ChangeMessages < ActiveRecord::Migration | |
def change | |
rename_column :messages, :recipient_ids, :old_recipient_ids | |
add_column :messages, :recipient_ids, :integer, array: true | |
Message.all.each do |message| | |
message.recipient_ids = message.old_recipient_ids | |
message.save!(validate: false) | |
end | |
remove_column :messages, :old_recipient_ids | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment