Refactoring Conference/Event media to new media object

close #420
This commit is contained in:
Chrisbr 2014-08-05 18:23:42 +02:00
parent 850beb72e1
commit 2a731e8350
31 changed files with 491 additions and 57 deletions

View file

@ -0,0 +1,28 @@
class MoveEventMediaToCommercial < ActiveRecord::Migration
class TempEvent < ActiveRecord::Base
self.table_name = 'events'
end
class TempCommercial < ActiveRecord::Base
self.table_name = 'commercials'
attr_accessible :commercial_id, :commercial_type, :commercialable_id, :commercialable_type
end
def change
# Move all the settings to the new object
TempEvent.all.each do |event|
unless TempCommercial.exists?(commercialable_id: event.id, commercialable_id: 'Conference')
unless event.media_id.blank? || event.media_type.blank?
TempCommercial.create(commercial_id: event.media_id,
commercial_type: event.media_type,
commercialable_id: event.id,
commercialable_type: 'Event')
end
end
end
# Then remove all the columns
remove_column :events, :media_id
remove_column :events, :media_type
end
end