2017-06-05 11:59:27 +05:30
|
|
|
class MoveConferencesToOrganizations < ActiveRecord::Migration
|
|
|
|
|
class TempConference < ActiveRecord::Base
|
|
|
|
|
self.table_name = 'conferences'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
class TempOrganization < ActiveRecord::Base
|
|
|
|
|
self.table_name = 'organizations'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def change
|
2017-06-06 20:04:39 +05:30
|
|
|
add_reference :conferences, :organization, index: true, foreign_key: true
|
2017-06-05 11:59:27 +05:30
|
|
|
|
|
|
|
|
TempConference.reset_column_information
|
2017-06-06 20:04:39 +05:30
|
|
|
if TempConference.count != 0
|
|
|
|
|
organization = TempOrganization.create(name: 'organization', description: 'Default organization')
|
|
|
|
|
TempConference.all.each do |conference|
|
|
|
|
|
conference.organization_id = organization.id
|
|
|
|
|
conference.save!
|
|
|
|
|
end
|
2017-06-05 11:59:27 +05:30
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|