Prepare user contribution reassignment process for Rails 7.1
It was pointed out on the user contribution reassignment process that the way we query composite key models will break in Rails 7.1.
Currently, rails does not truly support composite primary keys on a model's database table. ModelClass.primary_key
returns nil
for models whose corresponding database tables have composite primary keys. In the current reassignment process, we check if a model's primary_key
is nil
, and if it is, we build a query string to select for an array of tuples: https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/models/import/source_user_placeholder_reference.rb#L96-101
In the next version of Rails, composite keys are finally supported so that ModelClass.primary_key
returns an array of primary key columns, and we should be able to query by tuples: composite key release notes, tuple query release notes
However, the current approach does not expect composite key models to have a primary_key
value, so we never pass the placeholder references' composite_key
s to the query.
Proposal
Update Import::SourceUserPlaceholderReference.model_relations_for_source_user_reference
to query for models with pimary key matching composite_key
if primary_key
is more than one value. We need to ensure specs pass with the current gemfile, and with the next rails version gemfile:
BUNDLE_GEMFILE=Gemfile.next bundle exec rspec ./spec/services/import/reassign_placeholder_user_records_service_spec.rb