summaryrefslogtreecommitdiff
path: root/db/post_migrate
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-11-19 12:06:00 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-11-19 12:06:00 +0000
commitb570d73ecd31e2ca9cf8c2f1adb056edf2869477 (patch)
tree0b8aa67eab6da552d8499f1fdcf9a7495dcf1379 /db/post_migrate
parent34b3567c97ecc0f317adae04e10e4d7d8c8830db (diff)
downloadgitlab-ce-b570d73ecd31e2ca9cf8c2f1adb056edf2869477.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db/post_migrate')
-rw-r--r--db/post_migrate/20191104142124_nullify_users_role.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/db/post_migrate/20191104142124_nullify_users_role.rb b/db/post_migrate/20191104142124_nullify_users_role.rb
new file mode 100644
index 00000000000..540d58e95ba
--- /dev/null
+++ b/db/post_migrate/20191104142124_nullify_users_role.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class NullifyUsersRole < ActiveRecord::Migration[5.2]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+ INDEX_NAME = 'partial_index_users_updated_at_for_cleaning_mistaken_values'.freeze
+
+ DOWNTIME = false
+
+ def up
+ # expected updated users count is around 10K
+ # rubocop: disable Migration/UpdateLargeTable
+ add_concurrent_index(:users, :updated_at, where: 'role = 0', name: INDEX_NAME)
+
+ update_column_in_batches(:users, :role, nil) do |table, query|
+ query.where(table[:updated_at].lt('2019-11-05 12:08:00')).where(table[:role].eq(0))
+ end
+
+ remove_concurrent_index_by_name(:users, INDEX_NAME)
+ end
+
+ def down
+ # noop
+ end
+end