Skip to content

Commit

Permalink
if for migration
Browse files Browse the repository at this point in the history
  • Loading branch information
dzaporozhets committed Dec 18, 2012
1 parent 552c6d4 commit 96af55b
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ def up
add_column :notes, :commit_id, :string, null: true
add_column :notes, :new_noteable_id, :integer, null: true
Note.where(noteable_type: 'Commit').update_all('commit_id = noteable_id')
Note.where("noteable_type != 'Commit'").update_all('new_noteable_id = CAST (noteable_id AS INTEGER)')

if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
Note.where("noteable_type != 'Commit'").update_all('new_noteable_id = CAST (noteable_id AS INTEGER)')
else
Note.where("noteable_type != 'Commit'").update_all('new_noteable_id = noteable_id')
end

remove_column :notes, :noteable_id
rename_column :notes, :new_noteable_id, :noteable_id
end
Expand Down

0 comments on commit 96af55b

Please sign in to comment.