2012-12-18 19:02:00 +01:00
|
|
|
class MoveNoteableCommitToOwnField < ActiveRecord::Migration
|
|
|
|
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')
|
2012-12-18 20:06:29 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2012-12-18 19:02:00 +01:00
|
|
|
remove_column :notes, :noteable_id
|
|
|
|
rename_column :notes, :new_noteable_id, :noteable_id
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
2012-12-19 11:08:27 +01:00
|
|
|
raise ActiveRecord::IrreversibleMigration
|
2012-12-18 19:02:00 +01:00
|
|
|
end
|
|
|
|
end
|