diff --git a/db/migrate/20170531094817_add_organizaton_id_to_conference.rb b/db/migrate/20170531094817_add_organizaton_id_to_conference.rb deleted file mode 100644 index 4397ed7a..00000000 --- a/db/migrate/20170531094817_add_organizaton_id_to_conference.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddOrganizatonIdToConference < ActiveRecord::Migration - def change - add_column :conferences, :organization_id, :integer - end -end diff --git a/db/migrate/20170531094819_move_conferences_to_organizations.rb b/db/migrate/20170531094819_move_conferences_to_organizations.rb new file mode 100644 index 00000000..80c2ebd6 --- /dev/null +++ b/db/migrate/20170531094819_move_conferences_to_organizations.rb @@ -0,0 +1,21 @@ +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 + add_foreign_key :conferences, :organizations, dependent: :delete + + TempConference.reset_column_information + organization = TempOrganization.create(name: 'organization', description: 'Default organization to migrate old conferences to the new version of OSEM') + TempConference.all.each do |conference| + conference.organization_id = organization.id + conference.save! + end + end +end diff --git a/db/schema.rb b/db/schema.rb index c50e6b45..7db5faa0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170531094817) do +ActiveRecord::Schema.define(version: 20170531094819) do create_table "ahoy_events", force: :cascade do |t| t.uuid "visit_id", limit: 16 @@ -103,6 +103,8 @@ ActiveRecord::Schema.define(version: 20170531094817) do t.integer "organization_id" end + add_index "conferences", ["organization_id"], name: "index_conferences_on_organization_id" + create_table "conferences_questions", id: false, force: :cascade do |t| t.integer "conference_id" t.integer "question_id"