Skip to content

Instantly share code, notes, and snippets.

@JKring
Created July 30, 2013 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JKring/6116618 to your computer and use it in GitHub Desktop.
Save JKring/6116618 to your computer and use it in GitHub Desktop.
migrating team ids
id_map = {
"soon-to-be-deleted-team-id" => "replacement-team-id",
"other-soon-to-be-deleted-team-id" => "other-replacement-team-id"
}
id_map.each_pair do |old_id, new_id|
old_id = BSON::ObjectId(old_id)
new_id = BSON::ObjectId(new_id)
classes = [BlogPost, Business, Job, FinishedJob, PitchSet, TempJob]
classes.each do |cl|
cl.where(team_id: old_id).each do |thing|
thing.set(team_id: new_id)
end
end
Writer.where(team_ids: old_id).each do |writer|
writer.pull(team_ids: old_id)
writer.add_to_set(team_ids: new_id)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment