From 23db8409aafc6cdbae165056ec037e31096a8a66 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Thu, 1 Jun 2017 10:17:56 +0100 Subject: [PATCH] Skip loading application settings from the database when migrations are pending Various Rails initializers (metrics, sentry, etc) are run before migrations, which can lead to a mismatch between app/models/application_settings.rb and schema. --- lib/gitlab/current_settings.rb | 5 +++-- spec/controllers/projects/merge_requests_controller_spec.rb | 2 +- spec/serializers/pipeline_serializer_spec.rb | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/gitlab/current_settings.rb b/lib/gitlab/current_settings.rb index 82576d197fe..9e14b35b0f8 100644 --- a/lib/gitlab/current_settings.rb +++ b/lib/gitlab/current_settings.rb @@ -19,7 +19,7 @@ module Gitlab settings = ::ApplicationSetting.last end - settings ||= ::ApplicationSetting.create_from_defaults unless ActiveRecord::Migrator.needs_migration? + settings ||= ::ApplicationSetting.create_from_defaults end settings || in_memory_application_settings @@ -46,7 +46,8 @@ module Gitlab active_db_connection = ActiveRecord::Base.connection.active? rescue false active_db_connection && - ActiveRecord::Base.connection.table_exists?('application_settings') + ActiveRecord::Base.connection.table_exists?('application_settings') && + !ActiveRecord::Migrator.needs_migration? rescue ActiveRecord::NoDatabaseError false end diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb index 08024a2148b..a25db7a65fb 100644 --- a/spec/controllers/projects/merge_requests_controller_spec.rb +++ b/spec/controllers/projects/merge_requests_controller_spec.rb @@ -126,7 +126,7 @@ describe Projects::MergeRequestsController do recorded = ActiveRecord::QueryRecorder.new { go(format: :json) } - expect(recorded.count).to be_within(5).of(50) + expect(recorded.count).to be_within(5).of(59) expect(recorded.cached_count).to eq(0) end end diff --git a/spec/serializers/pipeline_serializer_spec.rb b/spec/serializers/pipeline_serializer_spec.rb index f2426db6d81..088f24eb180 100644 --- a/spec/serializers/pipeline_serializer_spec.rb +++ b/spec/serializers/pipeline_serializer_spec.rb @@ -113,7 +113,7 @@ describe PipelineSerializer do it "verifies number of queries" do recorded = ActiveRecord::QueryRecorder.new { subject } - expect(recorded.count).to be_within(1).of(58) + expect(recorded.count).to be_within(1).of(60) expect(recorded.cached_count).to eq(0) end