osem-fcy/db/migrate/20170531094819_move_conferences_to_organizations.rb
2025-08-12 16:44:20 +02:00

26 lines
756 B
Ruby

# frozen_string_literal: true
class MoveConferencesToOrganizations < ActiveRecord::Migration
class TempConference < ActiveRecord::Base
self.table_name = 'conferences'
end
class TempOrganization < ActiveRecord::Base
self.table_name = 'organizations'
end
def change
add_reference :conferences, :organization, index: true
TempConference.reset_column_information
if TempConference.any?
organization = TempOrganization.create(name: 'organization', description: 'Default organization')
TempConference.all.each do |conference|
conference.organization_id = organization.id
conference.save!
end
end
add_foreign_key :conferences, :organizations, null: false, on_delete: :cascade
end
end