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

20230405132855_remove_scim_token_and_scim_identity_non_root_group.rb « post_migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: aa149acc5be8194fc668fc3d8284550bec7e7fc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

class RemoveScimTokenAndScimIdentityNonRootGroup < Gitlab::Database::Migration[2.1]
  BATCH_SIZE = 500

  disable_ddl_transaction!
  restrict_gitlab_migration gitlab_schema: :gitlab_main

  def up
    each_batch_range('scim_oauth_access_tokens', scope: ->(table) { table.all }, of: BATCH_SIZE) do |min, max|
      execute <<~SQL
        DELETE FROM scim_identities
        WHERE scim_identities.group_id
        IN
        (
          SELECT namespaces.id FROM scim_oauth_access_tokens
          INNER JOIN namespaces ON namespaces.id=scim_oauth_access_tokens.group_id
          WHERE namespaces.type='Group' AND namespaces.parent_id IS NOT NULL
          AND scim_oauth_access_tokens.id BETWEEN #{min} AND #{max}
        );

        DELETE FROM scim_oauth_access_tokens
        USING namespaces
        WHERE namespaces.id=scim_oauth_access_tokens.group_id
        AND namespaces.type='Group' AND namespaces.parent_id IS NOT NULL
        AND scim_oauth_access_tokens.id BETWEEN #{min} AND #{max};
      SQL
    end
  end

  def down
    # noop
  end
end