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
path: root/db
diff options
context:
space:
mode:
authorGitLab Release Tools Bot <delivery-team+release-tools@gitlab.com>2021-08-31 20:25:23 +0300
committerGitLab Release Tools Bot <delivery-team+release-tools@gitlab.com>2021-08-31 20:25:23 +0300
commit3333112d46dd179a55295ebed754544a97b49b7f (patch)
tree218cc0d9d971809b17ec62c5196177025cbd075a /db
parent2da7c8579601c14a93d4291b8cf5fa39c6eeabd8 (diff)
parent8d08c6cbe51a88fbdc5065aba6e459768e98e63b (diff)
Merge remote-tracking branch 'dev/14-2-stable' into 14-2-stable
Diffstat (limited to 'db')
-rw-r--r--db/post_migrate/20210811122206_update_external_project_bots.rb33
-rw-r--r--db/schema_migrations/202108111222061
2 files changed, 34 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
diff --git a/db/schema_migrations/20210811122206 b/db/schema_migrations/20210811122206
new file mode 100644
index 00000000000..3bb2799461a
--- /dev/null
+++ b/db/schema_migrations/20210811122206
@@ -0,0 +1 @@
+f6f5e081672fb42adde980fa12f696f5d8fd11921ee52c1472b3d745bb11a5ff \ No newline at end of file