-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deconflate organization/conference IDs in role versions
Resolves failing test spec/features/versions_spec.rb:321 Partially reverts 81853d1
- Loading branch information
1 parent
150bbef
commit 3f6a9e9
Showing
6 changed files
with
69 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
class AddOrganizationToVersions < ActiveRecord::Migration[5.2] | ||
def up | ||
add_reference :versions, :organization | ||
deconflate | ||
PaperTrail::Version.reset_column_information | ||
end | ||
|
||
def down | ||
conflate | ||
remove_reference :versions, :organization | ||
PaperTrail::Version.reset_column_information | ||
end | ||
|
||
private | ||
|
||
def conflate | ||
say 'conflate' | ||
|
||
PaperTrail::Version.where.not(organization_id: nil).each do |version| | ||
version.update 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 conference_id: nil, organization_id: id | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters