Commit 3b18f3ca authored by James Fargher's avatar James Fargher

Merge branch '335808-fix-more-multiple-db-offenses' into 'master'

Fix more Database/MultipleDatabases offenses

See merge request gitlab-org/gitlab!67140
parents db3f0ce4 66b08296
...@@ -2499,7 +2499,6 @@ Database/MultipleDatabases: ...@@ -2499,7 +2499,6 @@ Database/MultipleDatabases:
- 'ee/spec/services/ee/merge_requests/update_service_spec.rb' - 'ee/spec/services/ee/merge_requests/update_service_spec.rb'
- 'lib/backup/database.rb' - 'lib/backup/database.rb'
- 'lib/after_commit_queue.rb' - 'lib/after_commit_queue.rb'
- 'lib/api/rubygem_packages.rb'
- 'lib/backup/manager.rb' - 'lib/backup/manager.rb'
- 'lib/gitlab/current_settings.rb' - 'lib/gitlab/current_settings.rb'
- 'lib/gitlab/database/load_balancing/load_balancer.rb' - 'lib/gitlab/database/load_balancing/load_balancer.rb'
...@@ -2535,29 +2534,20 @@ Database/MultipleDatabases: ...@@ -2535,29 +2534,20 @@ Database/MultipleDatabases:
- 'lib/gitlab/sherlock/query.rb' - 'lib/gitlab/sherlock/query.rb'
- 'lib/system_check/orphans/repository_check.rb' - 'lib/system_check/orphans/repository_check.rb'
- 'spec/db/schema_spec.rb' - 'spec/db/schema_spec.rb'
- 'spec/features/admin/dashboard_spec.rb'
- 'spec/initializers/database_config_spec.rb' - 'spec/initializers/database_config_spec.rb'
- 'spec/initializers/lograge_spec.rb'
- 'spec/lib/backup/manager_spec.rb' - 'spec/lib/backup/manager_spec.rb'
- 'spec/lib/gitlab/current_settings_spec.rb' - 'spec/lib/gitlab/current_settings_spec.rb'
- 'spec/lib/gitlab/database_spec.rb' - 'spec/lib/gitlab/database_spec.rb'
- 'spec/lib/gitlab/import_export/fast_hash_serializer_spec.rb'
- 'spec/lib/gitlab/import_export/project/tree_saver_spec.rb'
- 'spec/lib/gitlab/metrics/subscribers/active_record_spec.rb' - 'spec/lib/gitlab/metrics/subscribers/active_record_spec.rb'
- 'spec/lib/gitlab/pagination/keyset/order_spec.rb'
- 'spec/lib/gitlab/profiler_spec.rb' - 'spec/lib/gitlab/profiler_spec.rb'
- 'spec/lib/gitlab/query_limiting/active_support_subscriber_spec.rb'
- 'spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb'
- 'spec/lib/gitlab/usage_data_metrics_spec.rb' - 'spec/lib/gitlab/usage_data_metrics_spec.rb'
- 'spec/lib/gitlab/usage_data_queries_spec.rb' - 'spec/lib/gitlab/usage_data_queries_spec.rb'
- 'spec/lib/gitlab/usage/metrics/names_suggestions/relation_parsers/constraints_spec.rb' - 'spec/lib/gitlab/usage/metrics/names_suggestions/relation_parsers/constraints_spec.rb'
- 'spec/lib/gitlab/usage/metrics/names_suggestions/relation_parsers/joins_spec.rb' - 'spec/lib/gitlab/usage/metrics/names_suggestions/relation_parsers/joins_spec.rb'
- 'spec/lib/gitlab/usage/metrics/instrumentations/database_metric_spec.rb' - 'spec/lib/gitlab/usage/metrics/instrumentations/database_metric_spec.rb'
- 'spec/lib/gitlab/utils/usage_data_spec.rb' - 'spec/lib/gitlab/utils/usage_data_spec.rb'
- 'spec/models/application_setting_spec.rb'
- 'spec/models/project_feature_usage_spec.rb' - 'spec/models/project_feature_usage_spec.rb'
- 'spec/models/users_statistics_spec.rb' - 'spec/models/users_statistics_spec.rb'
- 'spec/requests/api/statistics_spec.rb'
- 'spec/services/users/activity_service_spec.rb' - 'spec/services/users/activity_service_spec.rb'
- 'spec/support/caching.rb' - 'spec/support/caching.rb'
- 'spec/support/gitlab/usage/metrics_instrumentation_shared_examples.rb' - 'spec/support/gitlab/usage/metrics_instrumentation_shared_examples.rb'
...@@ -2569,5 +2559,3 @@ Database/MultipleDatabases: ...@@ -2569,5 +2559,3 @@ Database/MultipleDatabases:
- 'spec/support/helpers/usage_data_helpers.rb' - 'spec/support/helpers/usage_data_helpers.rb'
- 'spec/tasks/gitlab/backup_rake_spec.rb' - 'spec/tasks/gitlab/backup_rake_spec.rb'
- 'spec/tasks/gitlab/db_rake_spec.rb' - 'spec/tasks/gitlab/db_rake_spec.rb'
- 'spec/workers/analytics/usage_trends/counter_job_worker_spec.rb'
- 'spec/workers/users/create_statistics_worker_spec.rb'
...@@ -101,7 +101,7 @@ module API ...@@ -101,7 +101,7 @@ module API
package_file = nil package_file = nil
ActiveRecord::Base.transaction do ApplicationRecord.transaction do
package = ::Packages::CreateTemporaryPackageService.new( package = ::Packages::CreateTemporaryPackageService.new(
user_project, current_user, declared_params.merge(build: current_authenticated_job) user_project, current_user, declared_params.merge(build: current_authenticated_job)
).execute(:rubygems, name: ::Packages::Rubygems::TEMPORARY_PACKAGE_NAME) ).execute(:rubygems, name: ::Packages::Rubygems::TEMPORARY_PACKAGE_NAME)
......
...@@ -19,8 +19,8 @@ RSpec.describe 'admin visits dashboard' do ...@@ -19,8 +19,8 @@ RSpec.describe 'admin visits dashboard' do
# Make sure the fork_networks & fork_networks reltuples have been updated # Make sure the fork_networks & fork_networks reltuples have been updated
# to get a correct count on postgresql # to get a correct count on postgresql
ActiveRecord::Base.connection.execute('ANALYZE fork_networks') ForkNetwork.connection.execute('ANALYZE fork_networks')
ActiveRecord::Base.connection.execute('ANALYZE fork_network_members') ForkNetwork.connection.execute('ANALYZE fork_network_members')
visit admin_root_path visit admin_root_path
......
...@@ -212,7 +212,7 @@ RSpec.describe 'lograge', type: :request do ...@@ -212,7 +212,7 @@ RSpec.describe 'lograge', type: :request do
end end
before do before do
ActiveRecord::Base.connection.execute('SELECT pg_sleep(0.1);') ApplicationRecord.connection.execute('SELECT pg_sleep(0.1);')
end end
context 'when RequestStore is enabled', :request_store do context 'when RequestStore is enabled', :request_store do
......
...@@ -190,7 +190,7 @@ RSpec.describe Gitlab::ImportExport::FastHashSerializer do ...@@ -190,7 +190,7 @@ RSpec.describe Gitlab::ImportExport::FastHashSerializer do
end end
it 'does not complain about non UTF-8 characters in MR diff files' do it 'does not complain about non UTF-8 characters in MR diff files' do
ActiveRecord::Base.connection.execute("UPDATE merge_request_diff_files SET diff = '---\n- :diff: !binary |-\n LS0tIC9kZXYvbnVsbAorKysgYi9pbWFnZXMvbnVjb3IucGRmCkBAIC0wLDAg\n KzEsMTY3OSBAQAorJVBERi0xLjUNJeLjz9MNCisxIDAgb2JqDTw8L01ldGFk\n YXR'") MergeRequest.connection.execute("UPDATE merge_request_diff_files SET diff = '---\n- :diff: !binary |-\n LS0tIC9kZXYvbnVsbAorKysgYi9pbWFnZXMvbnVjb3IucGRmCkBAIC0wLDAg\n KzEsMTY3OSBAQAorJVBERi0xLjUNJeLjz9MNCisxIDAgb2JqDTw8L01ldGFk\n YXR'")
expect(subject['merge_requests'].first['merge_request_diff']).not_to be_empty expect(subject['merge_requests'].first['merge_request_diff']).not_to be_empty
end end
......
...@@ -386,7 +386,7 @@ RSpec.describe Gitlab::ImportExport::Project::TreeSaver do ...@@ -386,7 +386,7 @@ RSpec.describe Gitlab::ImportExport::Project::TreeSaver do
end end
it 'does not complain about non UTF-8 characters in MR diff files' do it 'does not complain about non UTF-8 characters in MR diff files' do
ActiveRecord::Base.connection.execute("UPDATE merge_request_diff_files SET diff = '---\n- :diff: !binary |-\n LS0tIC9kZXYvbnVsbAorKysgYi9pbWFnZXMvbnVjb3IucGRmCkBAIC0wLDAg\n KzEsMTY3OSBAQAorJVBERi0xLjUNJeLjz9MNCisxIDAgb2JqDTw8L01ldGFk\n YXR'") MergeRequestDiffFile.connection.execute("UPDATE merge_request_diff_files SET diff = '---\n- :diff: !binary |-\n LS0tIC9kZXYvbnVsbAorKysgYi9pbWFnZXMvbnVjb3IucGRmCkBAIC0wLDAg\n KzEsMTY3OSBAQAorJVBERi0xLjUNJeLjz9MNCisxIDAgb2JqDTw8L01ldGFk\n YXR'")
expect(project_tree_saver.save).to be true expect(project_tree_saver.save).to be true
end end
......
...@@ -8,7 +8,7 @@ RSpec.describe Gitlab::Pagination::Keyset::Order do ...@@ -8,7 +8,7 @@ RSpec.describe Gitlab::Pagination::Keyset::Order do
let(:order) { nil } let(:order) { nil }
def run_query(query) def run_query(query)
ActiveRecord::Base.connection.execute(query).to_a ApplicationRecord.connection.execute(query).to_a
end end
def build_query(order:, where_conditions: nil, limit: nil) def build_query(order:, where_conditions: nil, limit: nil)
......
...@@ -27,7 +27,7 @@ RSpec.describe Gitlab::QueryLimiting::ActiveSupportSubscriber do ...@@ -27,7 +27,7 @@ RSpec.describe Gitlab::QueryLimiting::ActiveSupportSubscriber do
context 'when the query is actually a rails cache hit' do context 'when the query is actually a rails cache hit' do
it 'does not increment the number of executed SQL queries' do it 'does not increment the number of executed SQL queries' do
ActiveRecord::Base.connection.cache do User.connection.cache do
User.count User.count
User.count User.count
end end
......
...@@ -256,7 +256,7 @@ RSpec.describe Gitlab::SidekiqLogging::StructuredLogger do ...@@ -256,7 +256,7 @@ RSpec.describe Gitlab::SidekiqLogging::StructuredLogger do
expect(logger).to receive(:info).with(expected_end_payload_with_db).ordered expect(logger).to receive(:info).with(expected_end_payload_with_db).ordered
call_subject(job, 'test_queue') do call_subject(job, 'test_queue') do
ActiveRecord::Base.connection.execute('SELECT pg_sleep(0.1);') ApplicationRecord.connection.execute('SELECT pg_sleep(0.1);')
end end
end end
...@@ -267,7 +267,7 @@ RSpec.describe Gitlab::SidekiqLogging::StructuredLogger do ...@@ -267,7 +267,7 @@ RSpec.describe Gitlab::SidekiqLogging::StructuredLogger do
expect(logger).to receive(:info).with(expected_end_payload).ordered expect(logger).to receive(:info).with(expected_end_payload).ordered
call_subject(job.dup, 'test_queue') do call_subject(job.dup, 'test_queue') do
ActiveRecord::Base.connection.execute('SELECT pg_sleep(0.1);') ApplicationRecord.connection.execute('SELECT pg_sleep(0.1);')
end end
Gitlab::SafeRequestStore.clear! Gitlab::SafeRequestStore.clear!
...@@ -298,7 +298,7 @@ RSpec.describe Gitlab::SidekiqLogging::StructuredLogger do ...@@ -298,7 +298,7 @@ RSpec.describe Gitlab::SidekiqLogging::StructuredLogger do
allow(Gitlab::Database::LoadBalancing).to receive(:enable?).and_return(true) allow(Gitlab::Database::LoadBalancing).to receive(:enable?).and_return(true)
end end
let(:db_config_name) { ::Gitlab::Database.db_config_name(ActiveRecord::Base.connection) } let(:db_config_name) { ::Gitlab::Database.db_config_name(ApplicationRecord.connection) }
let(:expected_end_payload_with_db) do let(:expected_end_payload_with_db) do
expected_end_payload.merge( expected_end_payload.merge(
......
...@@ -927,7 +927,7 @@ RSpec.describe ApplicationSetting do ...@@ -927,7 +927,7 @@ RSpec.describe ApplicationSetting do
context 'when ApplicationSettings does not have a primary key' do context 'when ApplicationSettings does not have a primary key' do
before do before do
allow(ActiveRecord::Base.connection).to receive(:primary_key).with(described_class.table_name).and_return(nil) allow(described_class.connection).to receive(:primary_key).with(described_class.table_name).and_return(nil)
end end
it 'raises an exception' do it 'raises an exception' do
......
...@@ -63,7 +63,7 @@ RSpec.describe API::Statistics, 'Statistics' do ...@@ -63,7 +63,7 @@ RSpec.describe API::Statistics, 'Statistics' do
# Make sure the reltuples have been updated # Make sure the reltuples have been updated
# to get a correct count on postgresql # to get a correct count on postgresql
tables_to_analyze.each do |table| tables_to_analyze.each do |table|
ActiveRecord::Base.connection.execute("ANALYZE #{table}") ApplicationRecord.connection.execute("ANALYZE #{table}")
end end
get api(path, admin) get api(path, admin)
......
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