Skip to content

Modify DB migration scope to avoid table join

What does this MR do and why?

!80253 (merged) was merged but it turned out that the batched migration logic couldn't handle table joins due to an ambiguous id column. This MR modifies the migration to use a subquery instead.

How to set up and validate locally

  1. in console, create a group member that references a nonexistent namespace as its source_id:
# console, assumes namespace_id 999 does not exist
> user = User.find(1)
> invalid_member = Member.new(user_id: user.id, source_id: 999, access_level: Gitlab::Access::MAINTAINER, type: "GroupMember", source_type: "Namespace", notification_level: 3) }
> invalid_member.save(validate: false)
  1. Run the migration
> bundle exec rake db:migrate:up VERSION=20220809002011
  1. With this fix it should not error out.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #371309 (closed)

Edited by charlie ablett

Merge request reports