Deconflate organization/conference IDs in role versions

Resolves failing test spec/features/versions_spec.rb:320.
This commit is contained in:
Andrew Kvalheim 2020-04-03 09:51:35 -07:00
parent 79cd1c9fcd
commit fe2e5febe3
5 changed files with 67 additions and 35 deletions

View file

@ -0,0 +1,35 @@
class AddOrganizationToVersions < ActiveRecord::Migration[5.2]
def up
add_reference :versions, :organization
deconflate
end
def down
conflate
remove_reference :versions, :organization
end
private
def conflate
say 'conflate'
PaperTrail::Version.where.not(organization_id: nil).each do |version|
version.update_attributes conference_id: version.organization_id
end
end
def deconflate
say 'deconflate'
PaperTrail::Version.where.not(conference_id: nil).where(item_type: %[Role UsersRole]).each do |version|
id = version.conference_id
if Organization.exists?(id)
raise "version #{version.id} conflates organization #{id} with conference #{id}" if Conference.exists?(id)
version.update_attributes conference_id: nil, organization_id: id
end
end
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20181113195810) do
ActiveRecord::Schema.define(version: 2020_03_31_214534) do
create_table "answers", force: :cascade do |t|
t.string "title"
@ -639,7 +639,9 @@ ActiveRecord::Schema.define(version: 20181113195810) do
t.text "object_changes"
t.datetime "created_at"
t.integer "conference_id"
t.integer "organization_id"
t.index ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id"
t.index ["organization_id"], name: "index_versions_on_organization_id"
end
create_table "votes", force: :cascade do |t|