Commit 448a3747 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'ee-2246-uuid-is-nil-for-new-installation' into 'master'

Port of 2246-uuid-is-nil-for-new-installation to EE

See merge request !1733
parents ee8e9c9f 084a87ae
...@@ -29,6 +29,8 @@ class ApplicationSetting < ActiveRecord::Base ...@@ -29,6 +29,8 @@ class ApplicationSetting < ActiveRecord::Base
attr_accessor :domain_whitelist_raw, :domain_blacklist_raw attr_accessor :domain_whitelist_raw, :domain_blacklist_raw
validates :uuid, presence: true
validates :session_expire_delay, validates :session_expire_delay,
presence: true, presence: true,
numericality: { only_integer: true, greater_than_or_equal_to: 0 } numericality: { only_integer: true, greater_than_or_equal_to: 0 }
...@@ -176,6 +178,7 @@ class ApplicationSetting < ActiveRecord::Base ...@@ -176,6 +178,7 @@ class ApplicationSetting < ActiveRecord::Base
end end
end end
before_validation :ensure_uuid!
before_save :ensure_runners_registration_token before_save :ensure_runners_registration_token
before_save :ensure_health_check_access_token before_save :ensure_health_check_access_token
...@@ -402,6 +405,12 @@ class ApplicationSetting < ActiveRecord::Base ...@@ -402,6 +405,12 @@ class ApplicationSetting < ActiveRecord::Base
private private
def ensure_uuid!
return if uuid?
self.uuid = SecureRandom.uuid
end
def check_repository_storages def check_repository_storages
invalid = repository_storages - Gitlab.config.repositories.storages.keys invalid = repository_storages - Gitlab.config.repositories.storages.keys
errors.add(:repository_storages, "can't include: #{invalid.join(", ")}") unless errors.add(:repository_storages, "can't include: #{invalid.join(", ")}") unless
......
---
title: Lazily sets UUID in ApplicationSetting for new installations
merge_request:
author:
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
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170424142900) do ActiveRecord::Schema.define(version: 20170426175636) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
...@@ -1624,4 +1624,4 @@ ActiveRecord::Schema.define(version: 20170424142900) do ...@@ -1624,4 +1624,4 @@ ActiveRecord::Schema.define(version: 20170424142900) do
add_foreign_key "timelogs", "merge_requests", name: "fk_timelogs_merge_requests_merge_request_id", on_delete: :cascade add_foreign_key "timelogs", "merge_requests", name: "fk_timelogs_merge_requests_merge_request_id", on_delete: :cascade
add_foreign_key "trending_projects", "projects", on_delete: :cascade add_foreign_key "trending_projects", "projects", on_delete: :cascade
add_foreign_key "u2f_registrations", "users" add_foreign_key "u2f_registrations", "users"
end end
\ No newline at end of file
...@@ -4,6 +4,7 @@ describe ApplicationSetting, models: true do ...@@ -4,6 +4,7 @@ describe ApplicationSetting, models: true do
let(:setting) { ApplicationSetting.create_from_defaults } let(:setting) { ApplicationSetting.create_from_defaults }
it { expect(setting).to be_valid } it { expect(setting).to be_valid }
it { expect(setting.uuid).to be_present }
describe 'validations' do describe 'validations' do
let(:http) { 'http://example.com' } let(:http) { 'http://example.com' }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment