summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Hegyi <ahegyi@gitlab.com>2019-07-25 08:07:11 +0200
committerAdam Hegyi <ahegyi@gitlab.com>2019-08-28 09:14:42 +0200
commit607c6ec35a80a3a1d207b873a8633d5bd8a209b0 (patch)
tree01343a1e1e93117904961a64af7be98aabd568bd
parent6ac7ba3673db10a2eb003aa3fae9297edfdfe140 (diff)
downloadgitlab-ce-57538-not-null-constraint-on-users-private-profile.tar.gz
Adding NOT NULL constraint to private_profile57538-not-null-constraint-on-users-private-profile
This change sets NOT NULL constraint to users.private profile. closes https://gitlab.com/gitlab-org/gitlab-ce/issues/57538
-rw-r--r--changelogs/unreleased/57538-not-null-constraint-on-users-private-profile.yml5
-rw-r--r--db/post_migrate/20190725080128_set_not_null_on_users_private_profile.rb26
-rw-r--r--db/schema.rb2
-rw-r--r--spec/models/user_spec.rb2
4 files changed, 33 insertions, 2 deletions
diff --git a/changelogs/unreleased/57538-not-null-constraint-on-users-private-profile.yml b/changelogs/unreleased/57538-not-null-constraint-on-users-private-profile.yml
new file mode 100644
index 00000000000..bcbd8e3f11e
--- /dev/null
+++ b/changelogs/unreleased/57538-not-null-constraint-on-users-private-profile.yml
@@ -0,0 +1,5 @@
+---
+title: Setting NOT NULL constraint to users.private_profile column
+merge_request: 14838
+author:
+type: other
diff --git a/db/post_migrate/20190725080128_set_not_null_on_users_private_profile.rb b/db/post_migrate/20190725080128_set_not_null_on_users_private_profile.rb
new file mode 100644
index 00000000000..db42e949d3f
--- /dev/null
+++ b/db/post_migrate/20190725080128_set_not_null_on_users_private_profile.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class SetNotNullOnUsersPrivateProfile < ActiveRecord::Migration[5.1]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ Gitlab::BackgroundMigration.steal('MigrateNullPrivateProfileToFalse')
+
+ # rubocop:disable Migration/UpdateLargeTable
+ # rubocop:disable Migration/UpdateColumnInBatches
+ # Data has been migrated previously, count should be close to 0
+ update_column_in_batches(:users, :private_profile, false) do |table, query|
+ query.where(table[:private_profile].eq(nil))
+ end
+
+ change_column_null :users, :private_profile, false
+ end
+
+ def down
+ change_column_null :users, :private_profile, true
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index f30dad3d030..6c6c2796b9a 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -3499,7 +3499,7 @@ ActiveRecord::Schema.define(version: 2019_08_20_163320) do
t.integer "theme_id", limit: 2
t.integer "accepted_term_id"
t.string "feed_token"
- t.boolean "private_profile", default: false
+ t.boolean "private_profile", default: false, null: false
t.boolean "include_private_contributions"
t.string "commit_email"
t.boolean "auditor", default: false, null: false
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 8338d2b5b39..f1408194250 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -1176,7 +1176,7 @@ describe User do
expect(user.can_create_group).to eq(Gitlab.config.gitlab.default_can_create_group)
expect(user.theme_id).to eq(Gitlab.config.gitlab.default_theme)
expect(user.external).to be_falsey
- expect(user.private_profile).to eq false
+ expect(user.private_profile).to eq(false)
end
end