diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-04-27 15:33:25 +0000 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-04-28 17:36:24 +0800 |
commit | 07b4c1b28ffcaa97dd4050ea1235ebc518f4879d (patch) | |
tree | 8342b8ffa2109e7f8f21cbfa183e36f9c1acc5aa | |
parent | d3123f67f1ee891a284e1a37a02c8efcffbee0f0 (diff) | |
download | gitlab-ce-07b4c1b28ffcaa97dd4050ea1235ebc518f4879d.tar.gz |
Merge branch '2246-uuid-is-nil-for-new-installation' into 'master'
Lazily set UUID in ApplicationSetting for new installations
Closes gitlab-ee#2246
See merge request !10893
-rw-r--r-- | app/models/application_setting.rb | 9 | ||||
-rw-r--r-- | changelogs/unreleased/2246-uuid-is-nil-for-new-installation.yml | 4 | ||||
-rw-r--r-- | db/migrate/20170426175636_fill_missing_uuid_on_application_settings.rb | 10 | ||||
-rw-r--r-- | db/schema.rb | 2 | ||||
-rw-r--r-- | spec/models/application_setting_spec.rb | 1 |
5 files changed, 25 insertions, 1 deletions
diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index dd1a6922968..cf042717c95 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -28,6 +28,8 @@ class ApplicationSetting < ActiveRecord::Base attr_accessor :domain_whitelist_raw, :domain_blacklist_raw + validates :uuid, presence: true + validates :session_expire_delay, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 } @@ -159,6 +161,7 @@ class ApplicationSetting < ActiveRecord::Base end end + before_validation :ensure_uuid! before_save :ensure_runners_registration_token before_save :ensure_health_check_access_token @@ -344,6 +347,12 @@ class ApplicationSetting < ActiveRecord::Base private + def ensure_uuid! + return if uuid? + + self.uuid = SecureRandom.uuid + end + def check_repository_storages invalid = repository_storages - Gitlab.config.repositories.storages.keys errors.add(:repository_storages, "can't include: #{invalid.join(", ")}") unless diff --git a/changelogs/unreleased/2246-uuid-is-nil-for-new-installation.yml b/changelogs/unreleased/2246-uuid-is-nil-for-new-installation.yml new file mode 100644 index 00000000000..70d35f06af4 --- /dev/null +++ b/changelogs/unreleased/2246-uuid-is-nil-for-new-installation.yml @@ -0,0 +1,4 @@ +--- +title: Lazily sets UUID in ApplicationSetting for new installations +merge_request: +author: diff --git a/db/migrate/20170426175636_fill_missing_uuid_on_application_settings.rb b/db/migrate/20170426175636_fill_missing_uuid_on_application_settings.rb new file mode 100644 index 00000000000..58ad2c64075 --- /dev/null +++ b/db/migrate/20170426175636_fill_missing_uuid_on_application_settings.rb @@ -0,0 +1,10 @@ +class FillMissingUuidOnApplicationSettings < ActiveRecord::Migration + DOWNTIME = false + + def up + execute("UPDATE application_settings SET uuid = #{quote(SecureRandom.uuid)} WHERE uuid is NULL") + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index 8c2c360e9ab..3e656c77047 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170423064036) do +ActiveRecord::Schema.define(version: 20170426175636) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index 01ca1584ed2..c2c19c62048 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -4,6 +4,7 @@ describe ApplicationSetting, models: true do let(:setting) { ApplicationSetting.create_from_defaults } it { expect(setting).to be_valid } + it { expect(setting.uuid).to be_present } describe 'validations' do let(:http) { 'http://example.com' } |