2018-05-07 16:47:29 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2014-11-20 14:57:03 +01:00
|
|
|
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|
|
2017-04-04 11:48:52 -06:00
|
|
|
lodging.update_attributes(conference_id: conference.id)
|
2014-11-20 14:57:03 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
remove_column :lodgings, :venue_id, :integer
|
|
|
|
|
end
|
|
|
|
|
end
|