osem-fcy/db/migrate/20170531094819_move_conferences_to_organizations.rb

27 lines
762 B
Ruby
Raw Normal View History

# frozen_string_literal: true
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-07 12:37:30 +05:30
add_reference :conferences, :organization, index: 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
2017-06-07 12:37:30 +05:30
add_foreign_key :conferences, :organizations, null: false, on_delete: :cascade
2017-06-05 11:59:27 +05:30
end
end