diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-30 15:40:01 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-30 15:40:01 +0300 |
commit | f19a0fa10a0024fab5ef3c556612944f2a62c298 (patch) | |
tree | ef5c359820d2409cf07c0610122299d314ec4743 /db/post_migrate | |
parent | eba52140851d2fb08665119c0a3997d0612ccb88 (diff) |
Add latest changes from gitlab-org/security/gitlab@14-2-stable-ee
Diffstat (limited to 'db/post_migrate')
-rw-r--r-- | db/post_migrate/20210811122206_update_external_project_bots.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/db/post_migrate/20210811122206_update_external_project_bots.rb b/db/post_migrate/20210811122206_update_external_project_bots.rb new file mode 100644 index 00000000000..dc2e3d316b0 --- /dev/null +++ b/db/post_migrate/20210811122206_update_external_project_bots.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +class UpdateExternalProjectBots < ActiveRecord::Migration[6.1] + include Gitlab::Database::MigrationHelpers + + class User < ActiveRecord::Base + self.table_name = 'users' + end + + disable_ddl_transaction! + + TMP_INDEX_NAME = 'tmp_idx_update_external_project_bots' + + def up + add_concurrent_index('users', 'id', name: TMP_INDEX_NAME, where: 'external = true') + + ids = ActiveRecord::Base.connection + .execute("SELECT u.id FROM users u JOIN users u2 on u2.id = u.created_by_id WHERE u.user_type = 6 AND u2.external = true") + .map { |result| result['id'] } + + ids.each_slice(10) do |group| + UpdateExternalProjectBots::User.where(id: group).update_all(external: true) + end + + remove_concurrent_index_by_name('users', TMP_INDEX_NAME) + end + + def down + remove_concurrent_index_by_name('users', TMP_INDEX_NAME) if index_exists_by_name?('users', TMP_INDEX_NAME) + + # This migration is irreversible + end +end |