diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 19:05:49 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 19:05:49 +0300 |
commit | 43a25d93ebdabea52f99b05e15b06250cd8f07d7 (patch) | |
tree | dceebdc68925362117480a5d672bcff122fb625b /db/post_migrate/20230405132104_remove_saml_provider_and_identities_non_root_group.rb | |
parent | 20c84b99005abd1c82101dfeff264ac50d2df211 (diff) |
Add latest changes from gitlab-org/gitlab@16-0-stable-eev16.0.0-rc42
Diffstat (limited to 'db/post_migrate/20230405132104_remove_saml_provider_and_identities_non_root_group.rb')
-rw-r--r-- | db/post_migrate/20230405132104_remove_saml_provider_and_identities_non_root_group.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/db/post_migrate/20230405132104_remove_saml_provider_and_identities_non_root_group.rb b/db/post_migrate/20230405132104_remove_saml_provider_and_identities_non_root_group.rb new file mode 100644 index 00000000000..55a017464c2 --- /dev/null +++ b/db/post_migrate/20230405132104_remove_saml_provider_and_identities_non_root_group.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +class RemoveSamlProviderAndIdentitiesNonRootGroup < Gitlab::Database::Migration[2.1] + BATCH_SIZE = 500 + + disable_ddl_transaction! + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + each_batch_range('saml_providers', scope: ->(table) { table.all }, of: BATCH_SIZE) do |min, max| + execute <<~SQL + DELETE FROM identities + WHERE identities.saml_provider_id + IN + ( + SELECT saml_providers.id FROM saml_providers + INNER JOIN namespaces ON namespaces.id=saml_providers.group_id + AND namespaces.type='Group' AND namespaces.parent_id IS NOT NULL + AND saml_providers.id BETWEEN #{min} AND #{max} + ); + + DELETE FROM saml_providers + USING namespaces + WHERE namespaces.id=saml_providers.group_id + AND namespaces.type='Group' AND namespaces.parent_id IS NOT NULL + AND saml_providers.id BETWEEN #{min} AND #{max}; + SQL + end + end + + def down + # noop + end +end |