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:
authorAdam Hegyi <ahegyi@gitlab.com>2019-07-16 00:07:54 +0300
committerMayra Cabrera <mcabrera@gitlab.com>2019-07-16 00:07:54 +0300
commit4959d8fd4967e5769c8c81bf37e18ea13f607e2b (patch)
treec8983a05de4aca907d104106206e6987d3f61706 /db
parentd8f7017ab01333b51b823035b177446ec36259d8 (diff)
Migrate null values for users.private_profile
- Background migration for changing null values to false - Set false as default value for private_profile DB column
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20190620105427_change_null_private_profile_to_false.rb33
-rw-r--r--db/schema.rb2
2 files changed, 34 insertions, 1 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
diff --git a/db/schema.rb b/db/schema.rb
index e6a52e691c1..644ca1fe970 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -3391,7 +3391,7 @@ ActiveRecord::Schema.define(version: 2019_07_03_130053) do
t.integer "theme_id", limit: 2
t.integer "accepted_term_id"
t.string "feed_token"
- t.boolean "private_profile"
+ t.boolean "private_profile", default: false
t.boolean "include_private_contributions"
t.string "commit_email"
t.boolean "auditor", default: false, null: false