Prepare user contribution reassignment process for Rails 7.1
What does this MR do and why?
This MR updates the reassignment process slightly to be compatible with Rails 7.1 so that we don't face sudden issues when we upgrade our Rails version. In the new rails version, models with composite primary keys are finally recognized by ActiveRecord, and we can query for tuples, so this MR leverages that for a smooth upgrade in advance.
Currently, ModelClass.primary_key
returns nil
if the model's primary key is a composite key. However, in the next version, ModelClass.primary_key
returns an array of the primary key's columns. Before querying a model from a batch of placeholder references, this MR adds a check if the model's primary key is an array. If so, it queries the model for a tuple of its composite keys. This condition is not met in the current rails version because ApplicationRecord
models don't return an array for primary key:
ApplicationRecord.subclasses.filter_map{ |sc| sc.to_s if sc.primary_key.is_a?(Array) }
=> []
Ci::ApplicationRecord.subclasses.filter_map{ |sc| sc.to_s if sc.primary_key.is_a?(Array) }
=> []
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
How to set up and validate locally
Verify current rails version specs and verify the reassignment process works locally by:
- Fetch the branch in Assign contributions to placeholder users (!162484 - merged) if it hasn't been merged yet and follow its instructions to import a group to your local instance.
- Switch back to this branch.
- Assign a real user to a placeholder user.
- Impersonate the real user, find the reassignment email, and accept reassignment.
- Verify the user's contributions have been reassigned, especially those models with composite keys (e.g. IssueAssignee).
Specs are the easiest way to verify this for the next version:
BUNDLE_GEMFILE=Gemfile.next bundle exec rspec spec/services/import/reassign_placeholder_user_records_service_spec.rb
BUNDLE_GEMFILE=Gemfile.next bundle exec rspec spec/models/import/source_user_placeholder_reference_spec.rb
Related to #479387 (closed)