Skip to content

On user deletion associate releases author_id to ghost user

Currently when the user who created a release entry is deleted, the associated author_id column value is set to null on the releases table using the foreign key fk_8e4456f90f.

We should set the associated records to ghost user to make it consistent with Gitlab user deletion behaviour https://docs.gitlab.com/ee/user/profile/account/delete_account.html#associated-records

This would logically close out the edge case where the author_id value can be nil and also helps to debug and process the logs better as observed with this scenario where we are not able to clearly understand if the users were deleted #366797 (comment 1023386074) using logs and rails console.

Technical Proposal:

Include migrate_releases call to services/users/migrate_to_ghost_user_service

Migration of old records can be kept as is, since they are harmless. Let us discuss with team and then make this conclusion.

diff --git a/app/services/users/migrate_to_ghost_user_service.rb b/app/services/users/migrate_to_ghost_user_service.rb
index 3eb220c0e408..dae996429de5 100644
--- a/app/services/users/migrate_to_ghost_user_service.rb
+++ b/app/services/users/migrate_to_ghost_user_service.rb
@@ -62,6 +62,7 @@ def migrate_records
       migrate_award_emoji
       migrate_snippets
       migrate_reviews
+      migrate_releases
     end

     # rubocop: disable CodeReuse/ActiveRecord
@@ -99,6 +100,10 @@ def migrate_reviews
       batched_migrate(Review, :author_id)
     end

+    def migrate_releases
+      batched_migrate(Release, :author_id)
+    end
+
     # rubocop:disable CodeReuse/ActiveRecord
     def batched_migrate(base_scope, column, batch_size: 50)
       loop do
Edited by Bala Kumar