Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bulk move people from an old to a new team for specific teams #805

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Polsonby
Copy link
Contributor

@Polsonby Polsonby commented Aug 23, 2022

Description

Support some cleaning up work that's been done to tidy up members under some specific prison establishments

The user has set up old and new teams as described in the ticket.

Verify the team names are as they should be, then run rake peoplefinder:data:etc:bulk_move_lewes_huntercombe_coldingley to move all team members from the old team into the new team, preserving existing members of the new team, and delete the old team.

The script uses << to copy the members from the old team and preserve existing memberships in the new team.

The old teams have no sub teams.

Self-review checklist

  • (1) Quick stakeholder demo done OR
  • (2) ...bug with before and after screenshots
  • (3) Tests passing
  • (4) Branch ready to be merged (not work in progress)
  • (5) No superfluous changes in diff
  • (6) No TODO's without new ticket numbers
  • (7) PR Prefixed with ticket number e.g. CT-7654 ...

Screenshots

Related JIRA tickets

Deployment

Manual testing instructions

To replicate the scenario, find three teams that have members in them. Create three new empty teams and add a couple of canary users to one of them matching the scenarios below. Log into the namespace and run the rake task. You get one go and there's no rollback, so recommend testing thoroughly on non-prod environments first.

Scenarios to test

  1. new team has members
  2. new team has members that are duplicates of members moving in

@Polsonby Polsonby requested a review from a team as a code owner August 23, 2022 08:58
if old_team && new_team
puts "Copying #{old_team.people.count} members"
new_team.people << old_team.people
old_team.people.delete_all
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume you've tested this, but just wanted to make sure that doing new_team.people << old_team.people means you end up with 2 sets of people, so it is then safe to delete them from old_team.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, missed this! Yep, exactly so, I've just been testing it again locally as a sanity check.

The many-to-many table memberships is what's getting modified here so for example

  Membership Destroy (43.9ms)  DELETE FROM "memberships" WHERE "memberships"."id" IN (SELECT "memberships"."id" FROM "memberships" LEFT OUTER JOIN "people" ON "people"."id" = "memberships"."person_id" WHERE "memberships"."group_id" = $1 AND "memberships"."person_id" IN ($2, $3, $4, $5, $6, $7, $8, $9, $10) ORDER BY people.surname)  [["group_id", 18], ["person_id", 74], ["person_id", 73], ["person_id", 61], ["person_id", 50], ["person_id", 62], ["person_id", 72], ["person_id", 60], ["person_id", 48], ["person_id", 49]]
=> 9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants