osem-fcy/db/migrate/20140801170430_move_event_media_to_commercial.rb
2018-04-04 10:28:10 -07:00

27 lines
873 B
Ruby

# frozen_string_literal: true
class MoveEventMediaToCommercial < ActiveRecord::Migration
class TempEvent < ApplicationRecord
self.table_name = 'events'
end
class TempCommercial < ApplicationRecord
self.table_name = 'commercials'
end
def change
# Move all the settings to the new object
TempEvent.all.each do |event|
next if TempCommercial.exists?(commercialable_id: event.id, commercialable_id: 'Conference')
next if 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
# Then remove all the columns
remove_column :events, :media_id
remove_column :events, :media_type
end
end