summaryrefslogtreecommitdiff
path: root/db/migrate/20190620105427_change_null_private_profile_to_false.rb
diff options
context:
space:
mode:
Diffstat (limited to 'db/migrate/20190620105427_change_null_private_profile_to_false.rb')
-rw-r--r--db/migrate/20190620105427_change_null_private_profile_to_false.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/db/migrate/20190620105427_change_null_private_profile_to_false.rb b/db/migrate/20190620105427_change_null_private_profile_to_false.rb
new file mode 100644
index 00000000000..d820dbbe9d3
--- /dev/null
+++ b/db/migrate/20190620105427_change_null_private_profile_to_false.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+class ChangeNullPrivateProfileToFalse < ActiveRecord::Migration[5.1]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ DELAY = 30.seconds.to_i
+ BATCH_SIZE = 1_000
+
+ disable_ddl_transaction!
+
+ class User < ActiveRecord::Base
+ self.table_name = 'users'
+
+ include ::EachBatch
+ end
+
+ def up
+ change_column_default :users, :private_profile, false
+
+ # Migration will take about 120 hours
+ User.where(private_profile: nil).each_batch(of: BATCH_SIZE) do |batch, index|
+ range = batch.pluck('MIN(id)', 'MAX(id)').first
+ delay = index * DELAY
+
+ BackgroundMigrationWorker.perform_in(delay.seconds, 'MigrateNullPrivateProfileToFalse', [*range])
+ end
+ end
+
+ def down
+ change_column_default :users, :private_profile, nil
+ end
+end