-
Notifications
You must be signed in to change notification settings - Fork 18
Merging User Accounts
Occasionally we must merge User
accounts. Examples include if a user has a name change and their CSS ID changes, the next time they log in to Caseflow it will create a new User
record with no association to their old User
record. (Ideally they would tell us ahead of time and we could just change the CSS ID on the existing User
record before they log in with the new CSS ID, but ideals have a way of falling short sometimes.)
Ask the user to avoid logging into Caseflow while you're performing these steps
In this example we are going to merge all the new_user
associated records to the old_user
, delete the new_user
, and rename the old_user
CSS ID.
> ur = UserReporter.new(new_user)
> ur.report
=> ["13508 has 81 Annotation.user_id", "13508 has 7 ClaimsFolderSearch.user_id", "13508 has 1 OrganizationsUser.user_id", "13508 has 20 AppealView.user", "13508 has 1913 DocumentView.user"]
You can refer to the models listed in the UserReporter
output. Example clean up looks like:
Annotation.where(user: new_user).update_all(user_id: old_user.id)
Some models have unique indexes and trying to insert new records will collide because the old user already has existing records with the corresponding values. Examples are DocumentView
and AppealView
. To work around this, since we want to skip the duplicates, we can just rescue the error and interate:
begin
AppealView.where(user: new_user).each do |dv|
dv.update(user_id: old_user.id)
rescue ActiveRecord::RecordNotUnique
dv.delete # because we already have the view recorded under old_user
end
end
> new_user.destroy
Use the new CSS ID
> old_user.update!(css_id: new_user.css_id)
- Home
- Acronyms and Glossary
- Caseflow products
- Caseflow Intake
- Caseflow Queue
- Appeals Consumer
- Caseflow Reader
- Caseflow eFolder
- Caseflow Hearings
- Caseflow Certification
- Caseflow APIs
- Appeal Status API
- Caseflow Dispatch
-
CSUM Roles
- System Admin
- VHA Team Management
- Active Record Queries Resource
- External Integrations
- Caseflow Demo
- Caseflow ProdTest
- Background
- Stuck Jobs
- VA Notify
- Caseflow-Team
- Frontend Best Practices
- Accessibility
- How-To
- Debugging Tips
- Adding a Feature Flag with FeatureToggle
- Editing AMA issues
- Editing a decision review
- Fixing task trees
- Investigating and diagnosing issues
- Data and Metric Request Workflow
- Exporting and Importing Appeals
- Explain page for Appeals
- Record associations and Foreign Keys
- Upgrading Ruby
- Stuck Appeals
- Testing Action Mailer Messages Locally
- Re-running Seed Files
- Rake Generator for Legacy Appeals
- Manually running Scheduled Jobs
- System Admin UI
- Caseflow Makefile
- Upgrading Postgresql from v11.7 to v14.8 Locally
- VACOLS VM Trigger Fix M1
- Using SlackService to Send a Job Alert
- Technical Talks