Release deleted objects claim

What

Based on #365 (comment 2710296049) and issue Support claiming of unique model attributes acr... (#365 - closed), we have to find a way how to release claim from deleted objects.

Figure out how to make sure Rails will call before_commit for all the records that we're deleting. Some are not called like gpg_key_subkeys, and possibly also emails. Not sure why, but I suspect that it's possibly deleted by PostgreSQL with DELETE CASCADE therefore it's bypassing Rails. That does make sense, but we need to make sure we're releasing the claims on Topology service.

We can consider trying to look into those associations from the parent records, because if we know we're deleting the parent records and we know the children will get deleted in cascade, there's no need to really call before_commit for those records and we can just queue all data we want to delete anyway. Or we can still try to trigger those, depending on which is easier to do.

Proposal

  1. Thong Kuah: Use the queue pattern — for example, ci_deleted_objects. Something inserts into ci_deleted_objects when a Ci Build record is deleted. A worker then comes along to process ci_deleted_objects. https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/services/ci/delete_objects_service.rb?ref_type=heads
  2. David Leach You could also use a database trigger that happens on delete to populate a table for the models you care about to simulate the around_destroy pattern the delete_object_service performs. Claude generated example
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information