mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
26 lines
756 B
Ruby
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
|