diff options
author | Adam Hegyi <ahegyi@gitlab.com> | 2019-08-12 07:35:38 +0200 |
---|---|---|
committer | Mayra Cabrera <mcabrera@gitlab.com> | 2019-08-14 13:43:11 -0500 |
commit | 8a14f22c773c679f807bcf4ab99b77d92fb5c1ab (patch) | |
tree | 2617220f637e923d2c123abed49892e6e41ddece | |
parent | 7f9c653ef4c90a039ede690da1bc9d0524ffcc95 (diff) | |
download | gitlab-ce-8a14f22c773c679f807bcf4ab99b77d92fb5c1ab.tar.gz |
Migrate remaining users with null private_profilepost-migrate-private-profile
-rw-r--r-- | changelogs/unreleased/post-migrate-private-profile.yml | 5 | ||||
-rw-r--r-- | db/post_migrate/20190812070645_migrate_private_profile_nulls.rb | 31 | ||||
-rw-r--r-- | db/schema.rb | 2 |
3 files changed, 37 insertions, 1 deletions
diff --git a/changelogs/unreleased/post-migrate-private-profile.yml b/changelogs/unreleased/post-migrate-private-profile.yml new file mode 100644 index 00000000000..53a55661aa0 --- /dev/null +++ b/changelogs/unreleased/post-migrate-private-profile.yml @@ -0,0 +1,5 @@ +--- +title: Migrate remaining users with null private_profile +merge_request: 31708 +author: +type: other diff --git a/db/post_migrate/20190812070645_migrate_private_profile_nulls.rb b/db/post_migrate/20190812070645_migrate_private_profile_nulls.rb new file mode 100644 index 00000000000..063c1e16c27 --- /dev/null +++ b/db/post_migrate/20190812070645_migrate_private_profile_nulls.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +class MigratePrivateProfileNulls < ActiveRecord::Migration[5.2] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + DELAY = 5.minutes.to_i + BATCH_SIZE = 1_000 + + disable_ddl_transaction! + + class User < ActiveRecord::Base + self.table_name = 'users' + + include ::EachBatch + end + + def up + # Migration will take about 7 hours + User.where(private_profile: nil).each_batch(of: BATCH_SIZE) do |batch, index| + range = batch.pluck(Arel.sql("MIN(id)"), Arel.sql("MAX(id)")).first + delay = index * DELAY + + BackgroundMigrationWorker.perform_in(delay.seconds, 'MigrateNullPrivateProfileToFalse', [*range]) + end + end + + def down + # noop + end +end diff --git a/db/schema.rb b/db/schema.rb index 003f12b5171..7c4a91da750 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_08_06_071559) do +ActiveRecord::Schema.define(version: 2019_08_12_070645) do # These are extensions that must be enabled in order to support this database enable_extension "pg_trgm" |