Skip to content

Instantly share code, notes, and snippets.

@rusllonrails
Last active August 29, 2015 13:56
Show Gist options
  • Save rusllonrails/9020112 to your computer and use it in GitHub Desktop.
Save rusllonrails/9020112 to your computer and use it in GitHub Desktop.
POSTGRES CHANGE COLUMN TYPE
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