Commit 1891fd3a authored by Tetiana Chupryna's avatar Tetiana Chupryna

Merge branch 'legacy_connection_handling_false' into 'master'

Migrate to Rails 6.1 connection handling

See merge request gitlab-org/gitlab!63816
parents 0d06e94e 9610d076
...@@ -165,6 +165,10 @@ module Gitlab ...@@ -165,6 +165,10 @@ module Gitlab
# like if you have constraints or database-specific column types # like if you have constraints or database-specific column types
config.active_record.schema_format = :sql config.active_record.schema_format = :sql
# Use new connection handling so that we can use Rails 6.1+ multiple
# database support.
config.active_record.legacy_connection_handling = false
config.action_mailer.delivery_job = "ActionMailer::MailDeliveryJob" config.action_mailer.delivery_job = "ActionMailer::MailDeliveryJob"
# Enable the asset pipeline # Enable the asset pipeline
......
...@@ -54,6 +54,9 @@ Rails.application.configure do ...@@ -54,6 +54,9 @@ Rails.application.configure do
# Enable serving of images, stylesheets, and JavaScripts from an asset server # Enable serving of images, stylesheets, and JavaScripts from an asset server
config.action_controller.asset_host = ENV['GITLAB_CDN_HOST'] if ENV['GITLAB_CDN_HOST'].present? config.action_controller.asset_host = ENV['GITLAB_CDN_HOST'] if ENV['GITLAB_CDN_HOST'].present?
# We use a env var to keep at old default until we enable this for GitLab.com
config.active_record.legacy_connection_handling = !Gitlab::Utils.to_boolean(ENV.fetch('ENABLE_RAILS_61_CONNECTION_HANDLING', false))
# Do not dump schema after migrations. # Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false config.active_record.dump_schema_after_migration = false
......
...@@ -7,8 +7,15 @@ RSpec.describe 'Database config initializer' do ...@@ -7,8 +7,15 @@ RSpec.describe 'Database config initializer' do
load Rails.root.join('config/initializers/database_config.rb') load Rails.root.join('config/initializers/database_config.rb')
end end
around do |example|
original_config = ActiveRecord::Base.connection_db_config
example.run
ActiveRecord::Base.establish_connection(original_config)
end
before do before do
allow(ActiveRecord::Base).to receive(:establish_connection)
allow(Gitlab::Runtime).to receive(:max_threads).and_return(max_threads) allow(Gitlab::Runtime).to receive(:max_threads).and_return(max_threads)
end end
...@@ -21,6 +28,8 @@ RSpec.describe 'Database config initializer' do ...@@ -21,6 +28,8 @@ RSpec.describe 'Database config initializer' do
it "sets it based on the max number of worker threads" do it "sets it based on the max number of worker threads" do
expect { subject }.to change { Gitlab::Database.config['pool'] }.from(nil).to(18) expect { subject }.to change { Gitlab::Database.config['pool'] }.from(nil).to(18)
expect(ActiveRecord::Base.connection_db_config.pool).to eq(18)
end end
end end
...@@ -31,6 +40,8 @@ RSpec.describe 'Database config initializer' do ...@@ -31,6 +40,8 @@ RSpec.describe 'Database config initializer' do
it "sets it based on the max number of worker threads" do it "sets it based on the max number of worker threads" do
expect { subject }.to change { Gitlab::Database.config['pool'] }.from(1).to(18) expect { subject }.to change { Gitlab::Database.config['pool'] }.from(1).to(18)
expect(ActiveRecord::Base.connection_db_config.pool).to eq(18)
end end
end end
...@@ -41,6 +52,8 @@ RSpec.describe 'Database config initializer' do ...@@ -41,6 +52,8 @@ RSpec.describe 'Database config initializer' do
it "sets it based on the max number of worker threads" do it "sets it based on the max number of worker threads" do
expect { subject }.to change { Gitlab::Database.config['pool'] }.from(100).to(18) expect { subject }.to change { Gitlab::Database.config['pool'] }.from(100).to(18)
expect(ActiveRecord::Base.connection_db_config.pool).to eq(18)
end end
end end
...@@ -56,15 +69,16 @@ RSpec.describe 'Database config initializer' do ...@@ -56,15 +69,16 @@ RSpec.describe 'Database config initializer' do
expect { subject }.to change { Gitlab::Database.config['pool'] } expect { subject }.to change { Gitlab::Database.config['pool'] }
.from(1) .from(1)
.to(max_threads + headroom) .to(max_threads + headroom)
expect(ActiveRecord::Base.connection_db_config.pool).to eq(max_threads + headroom)
end end
end end
def stub_database_config(pool_size:) def stub_database_config(pool_size:)
config = { original_config = Gitlab::Database.config
'adapter' => 'postgresql',
'host' => 'db.host.com', config = original_config.dup
'pool' => pool_size config['pool'] = pool_size
}.compact
allow(Gitlab::Database).to receive(:config).and_return(config) allow(Gitlab::Database).to receive(:config).and_return(config)
end end
......
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