Fix add-on purchase lookup in GitLab Duo setup script

What does this MR do and why?

Fixes support/setup/gitlab_duo_setup.rb, which now fails on GitLab master with:

PG::UndefinedColumn: ERROR:  column subscription_add_on_purchases.add_on does not exist

gitlab!258275 (merged) changed GitlabSubscriptions::AddOnPurchase#add_on to a belongs_to_fixed_items association. ActiveRecord no longer sees it as an association, so AddOnPurchase.find_by(add_on: ...) becomes a lookup on a column that doesn't exist. This MR looks the purchase up through the for_duo_enterprise and for_gitlab_duo_pro scopes instead. Both scopes exist in older GitLab versions too, so update-from-previous scenarios keep working.

This breaks every scenario that seeds Duo seats, for example the duo-agent-platform job added to gitlab-org/gitlab in gitlab!264661 (merged):

After this is merged, we need a gitlab-qa release and a version bump in gitlab-org/gitlab's qa/Gemfile.

Screenshots or screen recordings

N/A

How to set up and validate locally

  1. Against a GitLab instance with a Duo Enterprise or Duo Pro add-on purchase, run:
    ASSIGN_SEATS=true HAS_ADD_ON=true QA_EE_ACTIVATION_CODE=<code> gitlab-rails runner support/setup/gitlab_duo_setup.rb
  2. Confirm it prints Seat assignment for admin successful.

MR acceptance checklist

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

Edited by Igor Drozdov

Merge request reports

Loading
Loading