osem-fcy/db/migrate/20141118162030_change_lodging_association_to_conference.rb
Cody Borders 535b3f86d6 Fixes Style/Tab cops
Removes exclusions for Style/Tab cops in rubocop_todo
Places Style/Tab cop in appropriate alphabetical order
All cops now fixed.
2017-04-06 10:57:44 -06:00

31 lines
884 B
Ruby

class ChangeLodgingAssociationToConference < ActiveRecord::Migration
class TempConference < ActiveRecord::Base
self.table_name = 'conferences'
end
class TempVenue < ActiveRecord::Base
self.table_name = 'venues'
end
class TempLodging < ActiveRecord::Base
self.table_name = 'lodgings'
end
def change
add_column :lodgings, :conference_id, :integer
TempLodging.reset_column_information
# Change association from venue and conference
TempConference.all.each do |conference|
if TempVenue.exists?(conference_id: conference.id)
venue = TempVenue.find_by(conference_id: conference.id)
lodgings = TempLodging.where(venue_id: venue.id)
lodgings.each do |lodging|
lodging.update_attributes(conference_id: conference.id)
end
end
end
remove_column :lodgings, :venue_id, :integer
end
end