Remove active scope in add-on purchase lookup for SM
What does this MR do and why?
Part of https://gitlab.com/gitlab-org/gitlab/-/issues/426733+
Prior to this change, when there was an existing add-on purchase record (GitlabSubscriptions::AddOnPurchase) for the SM instance (namespace is nil) and that record is expired, the license data sync would fail. This was because the record can't be found because the lookup for the add-on purchase was looking for a not expired record by using the active scope. As a result a new add-on purchase record was attempted to be created which would then fail due to the uniqueness validation of the subscription_add_on_id scoped to namespace_id.
In this change, the active record is removed to allow finding the add-on purchase record and updating it regardless of being active or expired.
How to set up and validate locally
With this MR's branch checked out:
-
CustomersDot: Enable the
purchase_code_suggestionsfeature flag for your CustomersDot instance. - Zuora: Create a new Online Cloud subscription with a couple of Code Suggestions seats (example subscription).
- CustomersDot: Wait for the callout to process.
- CustomersDot: Copy the activation code from the email sent by the callout.
- GitLab: Active your GitLab instance with the activation code.
- GitLab: Open the rails console..
-
GitLab: Load the last
GitlabSubscriptions::AddOnPurchaserecord (it should belong to your subscription):add_on_purchase = GitlabSubscriptions::AddOnPurchase.last -
GitLab: Update the record manually to be expired:
add_on_purchase.update(expires_at: Date.yesterday) -
GitLab: Manually trigger the license data sync on
/admin/subscription. -
GitLab: Open
/admin/sidekiq/retriesand verify there's a retry for theSyncSeatLinkRequestWorker. -
GitLab: Verify the add-on purchase record wasn't updated:
add_on_purchase.reload - GitLab: Delete the retry entry on the Sidekiq retry page.
With this MR's branch checked out:
-
GitLab: Manually trigger the license data sync on
/admin/subscription. -
GitLab: Verify the add-on purchase record was updated this time:
add_on_purchase.reload
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.