Skip to content

Commit

Permalink
Rake task to merge organizations
Browse files Browse the repository at this point in the history
  • Loading branch information
moveson committed Dec 12, 2023
1 parent 5f3166c commit 315ad6b
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/tasks/merge_organizations.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# require "active_record"

desc "merges one organization into another"
task :merge_organizations, [:disappearing_organization_id, :surviving_organization_id] => :environment do |_, args|
disappearing_organization = Organization.find_by(id: args.disappearing_organization_id)
surviving_organization = Organization.find_by(id: args.surviving_organization_id)

abort if disappearing_organization.nil? || surviving_organization.nil?

puts "This will merge #{disappearing_organization.name} into #{surviving_organization.name}"
puts "Are you sure you want to do this? (y/n)"
answer = STDIN.gets.chomp
abort unless answer.downcase == "y"

relevant_models = [
Course,
CourseGroup,
EventGroup,
EventSeries,
Lottery,
ResultsCategory,
ResultsTemplate,
Stewardship,
]

relevant_models.each do |model|
puts "Merging #{model.table_name.titleize.pluralize}"
model.where(organization: disappearing_organization).update_all(organization_id: surviving_organization.id)
end
end

0 comments on commit 315ad6b

Please sign in to comment.