-
Notifications
You must be signed in to change notification settings - Fork 493
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:320.
- Loading branch information
1 parent
5354bf6
commit fe8e82a
Showing
5 changed files
with
67 additions
and
35 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,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 |
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