Switch from delete_all to destroy_all for user add-on assignments

What does this MR do and why?

When we delete user add-on assignments, we always want to trigger callbacks to create audits for the deletion via paper trail and the user add-on assignment version model.

Database Review

Both code locations switch from delete_all to destroy_all. With that, we use callbacks, and so Papertrail creates audits. Per destroy, we create one audit. In each location, we already use the helper each_batch , which saves us from memory overload. The queries are the same in both places, so we need only one query plan per type.

GitlabSubscriptions::AddOnPurchase

  • Raw SQL (Including creation of audit)

    INSERT INTO "subscription_user_add_on_assignment_versions" ("organization_id", "item_id", "purchase_id", "user_id", "created_at", "item_type", "event", "namespace_path", "add_on_name", "object") VALUES (1051, 27, 164, 22, '2025-01-09 10:34:16.472441', 'GitlabSubscriptions::UserAddOnAssignment', 'destroy', '151/', 'code_suggestions', '{"id":27,"add_on_purchase_id":164,"user_id":22,"created_at":"2025-01-09T10:33:23.668Z","updated_at":"2025-01-09T10:33:23.668Z","organization_id":1051}') RETURNING "id"
    
    SELECT "subscription_user_add_on_assignments".* FROM "subscription_user_add_on_assignments" WHERE "subscription_user_add_on_assignments"."id" = 27 LIMIT 1
    
    DELETE FROM "subscription_user_add_on_assignments" WHERE "subscription_user_add_on_assignments"."id" = 27

GitlabSubscriptions::AddOnPurchase::ReconcileSeatOverageService

  • Raw SQL (Including creation of audit)

    INSERT INTO "subscription_user_add_on_assignment_versions" ("organization_id", "item_id", "purchase_id", "user_id", "created_at", "item_type", "event", "namespace_path", "add_on_name", "object") VALUES (1052, 29, 165, 24, '2025-01-09 11:20:44.957801', 'GitlabSubscriptions::UserAddOnAssignment', 'destroy', '152/', 'code_suggestions', '{"id":29,"add_on_purchase_id":165,"user_id":24,"created_at":"2025-01-09T11:20:33.074Z","updated_at":"2025-01-09T11:20:33.074Z","organization_id":1052}') RETURNING "id"
    
    SELECT "subscription_user_add_on_assignments".* FROM "subscription_user_add_on_assignments" WHERE "subscription_user_add_on_assignments"."id" = 29 LIMIT 1 
    
    DELETE FROM "subscription_user_add_on_assignments" WHERE "subscription_user_add_on_assignments"."id" = 29

Query Plans

References

Please include cross links to any resources that are relevant to this MR. This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.

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.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Green test suite is sufficient

Edited by Lukas Wanko

Merge request reports

Loading