Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'db/post_migrate/20210825150212_cleanup_remaining_orphan_invites.rb')
-rw-r--r--db/post_migrate/20210825150212_cleanup_remaining_orphan_invites.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/db/post_migrate/20210825150212_cleanup_remaining_orphan_invites.rb b/db/post_migrate/20210825150212_cleanup_remaining_orphan_invites.rb
new file mode 100644
index 00000000000..d892e6897af
--- /dev/null
+++ b/db/post_migrate/20210825150212_cleanup_remaining_orphan_invites.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+class CleanupRemainingOrphanInvites < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ TMP_INDEX_NAME = 'tmp_idx_members_with_orphaned_invites'
+
+ QUERY_CONDITION = "invite_token IS NOT NULL AND user_id IS NOT NULL"
+
+ def up
+ membership = define_batchable_model('members')
+
+ add_concurrent_index :members, :id, where: QUERY_CONDITION, name: TMP_INDEX_NAME
+
+ membership.where(QUERY_CONDITION).pluck(:id).each_slice(10) do |group|
+ membership.where(id: group).where(QUERY_CONDITION).update_all(invite_token: nil)
+ end
+
+ remove_concurrent_index_by_name :members, TMP_INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :members, TMP_INDEX_NAME if index_exists_by_name?(:members, TMP_INDEX_NAME)
+ end
+end