Commit 5e292260 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'gitlab-database-remove-wrapper-methods' into 'master'

[RUN AS-IF-FOSS] Remove wrapper methods from Gitlab::Database

See merge request gitlab-org/gitlab!66288
parents b9051ffe 92c1283b
...@@ -71,7 +71,7 @@ class Admin::SessionsController < ApplicationController ...@@ -71,7 +71,7 @@ class Admin::SessionsController < ApplicationController
::Users::ValidateOtpService.new(user).execute(user_params[:otp_attempt]) ::Users::ValidateOtpService.new(user).execute(user_params[:otp_attempt])
valid_otp_attempt = otp_validation_result[:status] == :success valid_otp_attempt = otp_validation_result[:status] == :success
return valid_otp_attempt if Gitlab::Database.read_only? return valid_otp_attempt if Gitlab::Database.main.read_only?
valid_otp_attempt || user.invalidate_otp_backup_code!(user_params[:otp_attempt]) valid_otp_attempt || user.invalidate_otp_backup_code!(user_params[:otp_attempt])
end end
......
...@@ -27,7 +27,7 @@ module Boards ...@@ -27,7 +27,7 @@ module Boards
list_service = Boards::Issues::ListService.new(board_parent, current_user, filter_params) list_service = Boards::Issues::ListService.new(board_parent, current_user, filter_params)
issues = issues_from(list_service) issues = issues_from(list_service)
if Gitlab::Database.read_write? && !board.disabled_for?(current_user) if Gitlab::Database.main.read_write? && !board.disabled_for?(current_user)
Issue.move_nulls_to_end(issues) Issue.move_nulls_to_end(issues)
end end
......
...@@ -47,7 +47,7 @@ module AuthenticatesWithTwoFactorForAdminMode ...@@ -47,7 +47,7 @@ module AuthenticatesWithTwoFactorForAdminMode
# Remove any lingering user data from login # Remove any lingering user data from login
session.delete(:otp_user_id) session.delete(:otp_user_id)
user.save! unless Gitlab::Database.read_only? user.save! unless Gitlab::Database.main.read_only?
# The admin user has successfully passed 2fa, enable admin mode ignoring password # The admin user has successfully passed 2fa, enable admin mode ignoring password
enable_admin_mode enable_admin_mode
......
...@@ -148,7 +148,7 @@ module IssuableActions ...@@ -148,7 +148,7 @@ module IssuableActions
# on GET requests. # on GET requests.
# This is just a fail-safe in case notes_filter is sent via GET request in GitLab Geo. # This is just a fail-safe in case notes_filter is sent via GET request in GitLab Geo.
# In some cases, we also force the filter to not be persisted with the `persist_filter` param # In some cases, we also force the filter to not be persisted with the `persist_filter` param
if Gitlab::Database.read_only? || params[:persist_filter] == 'false' if Gitlab::Database.main.read_only? || params[:persist_filter] == 'false'
notes_filter_param || current_user&.notes_filter_for(issuable) notes_filter_param || current_user&.notes_filter_for(issuable)
else else
notes_filter = current_user&.set_notes_filter(notes_filter_param, issuable) || notes_filter_param notes_filter = current_user&.set_notes_filter(notes_filter_param, issuable) || notes_filter_param
......
...@@ -17,7 +17,7 @@ module RecordUserLastActivity ...@@ -17,7 +17,7 @@ module RecordUserLastActivity
def set_user_last_activity def set_user_last_activity
return unless request.get? return unless request.get?
return if Gitlab::Database.read_only? return if Gitlab::Database.main.read_only?
if current_user && current_user.last_activity_on != Date.today if current_user && current_user.last_activity_on != Date.today
Users::ActivityService.new(current_user).execute Users::ActivityService.new(current_user).execute
......
...@@ -41,7 +41,7 @@ module SortingPreference ...@@ -41,7 +41,7 @@ module SortingPreference
sort_param = params[:sort] sort_param = params[:sort]
sort_param ||= user_preference[field] sort_param ||= user_preference[field]
return sort_param if Gitlab::Database.read_only? return sort_param if Gitlab::Database.main.read_only?
if user_preference[field] != sort_param if user_preference[field] != sort_param
user_preference.update(field => sort_param) user_preference.update(field => sort_param)
......
...@@ -77,7 +77,7 @@ module Repositories ...@@ -77,7 +77,7 @@ module Repositories
def update_fetch_statistics def update_fetch_statistics
return unless project return unless project
return if Gitlab::Database.read_only? return if Gitlab::Database.main.read_only?
return unless repo_type.project? return unless repo_type.project?
OnboardingProgressService.async(project.namespace_id).execute(action: :git_pull) OnboardingProgressService.async(project.namespace_id).execute(action: :git_pull)
......
...@@ -126,7 +126,7 @@ module Repositories ...@@ -126,7 +126,7 @@ module Repositories
# Overridden in EE # Overridden in EE
def batch_operation_disallowed? def batch_operation_disallowed?
upload_request? && Gitlab::Database.read_only? upload_request? && Gitlab::Database.main.read_only?
end end
# Overridden in EE # Overridden in EE
......
...@@ -29,7 +29,7 @@ module Mutations ...@@ -29,7 +29,7 @@ module Mutations
end end
def ready?(**args) def ready?(**args)
raise_resource_not_available_error! ERROR_MESSAGE if Gitlab::Database.read_only? raise_resource_not_available_error! ERROR_MESSAGE if Gitlab::Database.main.read_only?
missing_args = self.class.arguments.values missing_args = self.class.arguments.values
.reject { |arg| arg.accepts?(args.fetch(arg.keyword, :not_given)) } .reject { |arg| arg.accepts?(args.fetch(arg.keyword, :not_given)) }
......
...@@ -344,7 +344,7 @@ module ApplicationHelper ...@@ -344,7 +344,7 @@ module ApplicationHelper
# Overridden in EE # Overridden in EE
def read_only_message def read_only_message
return unless Gitlab::Database.read_only? return unless Gitlab::Database.main.read_only?
_('You are on a read-only GitLab instance.') _('You are on a read-only GitLab instance.')
end end
......
...@@ -219,11 +219,11 @@ module ApplicationSettingImplementation ...@@ -219,11 +219,11 @@ module ApplicationSettingImplementation
end end
def home_page_url_column_exists? def home_page_url_column_exists?
::Gitlab::Database.cached_column_exists?(:application_settings, :home_page_url) ::Gitlab::Database.main.cached_column_exists?(:application_settings, :home_page_url)
end end
def help_page_support_url_column_exists? def help_page_support_url_column_exists?
::Gitlab::Database.cached_column_exists?(:application_settings, :help_page_support_url) ::Gitlab::Database.main.cached_column_exists?(:application_settings, :help_page_support_url)
end end
def disabled_oauth_sign_in_sources=(sources) def disabled_oauth_sign_in_sources=(sources)
......
...@@ -127,7 +127,7 @@ module CascadingNamespaceSettingAttribute ...@@ -127,7 +127,7 @@ module CascadingNamespaceSettingAttribute
end end
def alias_boolean(attribute) def alias_boolean(attribute)
return unless Gitlab::Database.exists? && type_for_attribute(attribute).type == :boolean return unless Gitlab::Database.main.exists? && type_for_attribute(attribute).type == :boolean
alias_method :"#{attribute}?", attribute alias_method :"#{attribute}?", attribute
end end
......
...@@ -34,7 +34,7 @@ module DeprecatedAssignee ...@@ -34,7 +34,7 @@ module DeprecatedAssignee
end end
def assignee_ids def assignee_ids
if Gitlab::Database.read_only? && pending_assignees_population? if Gitlab::Database.main.read_only? && pending_assignees_population?
return Array(deprecated_assignee_id) return Array(deprecated_assignee_id)
end end
...@@ -43,7 +43,7 @@ module DeprecatedAssignee ...@@ -43,7 +43,7 @@ module DeprecatedAssignee
end end
def assignees def assignees
if Gitlab::Database.read_only? && pending_assignees_population? if Gitlab::Database.main.read_only? && pending_assignees_population?
return User.where(id: deprecated_assignee_id) return User.where(id: deprecated_assignee_id)
end end
...@@ -56,7 +56,7 @@ module DeprecatedAssignee ...@@ -56,7 +56,7 @@ module DeprecatedAssignee
# This will make the background migration process quicker (#26496) as it'll have less # This will make the background migration process quicker (#26496) as it'll have less
# assignee_id rows to look through. # assignee_id rows to look through.
def nullify_deprecated_assignee def nullify_deprecated_assignee
return unless persisted? && Gitlab::Database.read_only? return unless persisted? && Gitlab::Database.main.read_only?
update_column(:assignee_id, nil) update_column(:assignee_id, nil)
end end
......
...@@ -39,7 +39,7 @@ module Sha256Attribute ...@@ -39,7 +39,7 @@ module Sha256Attribute
end end
def database_exists? def database_exists?
Gitlab::Database.exists? Gitlab::Database.main.exists?
end end
end end
end end
...@@ -32,7 +32,7 @@ module ShaAttribute ...@@ -32,7 +32,7 @@ module ShaAttribute
end end
def database_exists? def database_exists?
Gitlab::Database.exists? Gitlab::Database.main.exists?
end end
end end
end end
......
...@@ -41,7 +41,7 @@ module TokenAuthenticatableStrategies ...@@ -41,7 +41,7 @@ module TokenAuthenticatableStrategies
# Resets the token, but only saves when the database is in read & write mode # Resets the token, but only saves when the database is in read & write mode
def reset_token!(instance) def reset_token!(instance)
write_new_token(instance) write_new_token(instance)
instance.save! if Gitlab::Database.read_write? instance.save! if Gitlab::Database.main.read_write?
end end
def self.fabricate(model, field, options) def self.fabricate(model, field, options)
......
...@@ -39,7 +39,7 @@ module X509SerialNumberAttribute ...@@ -39,7 +39,7 @@ module X509SerialNumberAttribute
end end
def database_exists? def database_exists?
Gitlab::Database.exists? Gitlab::Database.main.exists?
end end
end end
end end
...@@ -289,7 +289,7 @@ class Deployment < ApplicationRecord ...@@ -289,7 +289,7 @@ class Deployment < ApplicationRecord
"#{id} as deployment_id", "#{id} as deployment_id",
"#{environment_id} as environment_id").to_sql "#{environment_id} as environment_id").to_sql
# We don't use `Gitlab::Database.bulk_insert` here so that we don't need to # We don't use `Gitlab::Database.main.bulk_insert` here so that we don't need to
# first pluck lots of IDs into memory. # first pluck lots of IDs into memory.
# #
# We also ignore any duplicates so this method can be called multiple times # We also ignore any duplicates so this method can be called multiple times
......
...@@ -88,7 +88,7 @@ module DesignManagement ...@@ -88,7 +88,7 @@ module DesignManagement
rows = design_actions.map { |action| action.row_attrs(version) } rows = design_actions.map { |action| action.row_attrs(version) }
Gitlab::Database.bulk_insert(::DesignManagement::Action.table_name, rows) # rubocop:disable Gitlab/BulkInsert Gitlab::Database.main.bulk_insert(::DesignManagement::Action.table_name, rows) # rubocop:disable Gitlab/BulkInsert
version.designs.reset version.designs.reset
version.validate! version.validate!
design_actions.each(&:performed) design_actions.each(&:performed)
......
...@@ -26,7 +26,7 @@ class MergeRequestContextCommit < ApplicationRecord ...@@ -26,7 +26,7 @@ class MergeRequestContextCommit < ApplicationRecord
# create MergeRequestContextCommit by given commit sha and it's diff file record # create MergeRequestContextCommit by given commit sha and it's diff file record
def self.bulk_insert(rows, **args) def self.bulk_insert(rows, **args)
Gitlab::Database.bulk_insert('merge_request_context_commits', rows, **args) # rubocop:disable Gitlab/BulkInsert Gitlab::Database.main.bulk_insert('merge_request_context_commits', rows, **args) # rubocop:disable Gitlab/BulkInsert
end end
def to_commit def to_commit
......
...@@ -14,7 +14,7 @@ class MergeRequestContextCommitDiffFile < ApplicationRecord ...@@ -14,7 +14,7 @@ class MergeRequestContextCommitDiffFile < ApplicationRecord
# create MergeRequestContextCommitDiffFile by given diff file record(s) # create MergeRequestContextCommitDiffFile by given diff file record(s)
def self.bulk_insert(*args) def self.bulk_insert(*args)
Gitlab::Database.bulk_insert('merge_request_context_commit_diff_files', *args) # rubocop:disable Gitlab/BulkInsert Gitlab::Database.main.bulk_insert('merge_request_context_commit_diff_files', *args) # rubocop:disable Gitlab/BulkInsert
end end
def path def path
......
...@@ -515,7 +515,7 @@ class MergeRequestDiff < ApplicationRecord ...@@ -515,7 +515,7 @@ class MergeRequestDiff < ApplicationRecord
transaction do transaction do
MergeRequestDiffFile.where(merge_request_diff_id: id).delete_all MergeRequestDiffFile.where(merge_request_diff_id: id).delete_all
Gitlab::Database.bulk_insert('merge_request_diff_files', rows) # rubocop:disable Gitlab/BulkInsert Gitlab::Database.main.bulk_insert('merge_request_diff_files', rows) # rubocop:disable Gitlab/BulkInsert
save! save!
end end
...@@ -535,7 +535,7 @@ class MergeRequestDiff < ApplicationRecord ...@@ -535,7 +535,7 @@ class MergeRequestDiff < ApplicationRecord
transaction do transaction do
MergeRequestDiffFile.where(merge_request_diff_id: id).delete_all MergeRequestDiffFile.where(merge_request_diff_id: id).delete_all
Gitlab::Database.bulk_insert('merge_request_diff_files', rows) # rubocop:disable Gitlab/BulkInsert Gitlab::Database.main.bulk_insert('merge_request_diff_files', rows) # rubocop:disable Gitlab/BulkInsert
update!(stored_externally: false) update!(stored_externally: false)
end end
...@@ -595,7 +595,7 @@ class MergeRequestDiff < ApplicationRecord ...@@ -595,7 +595,7 @@ class MergeRequestDiff < ApplicationRecord
rows = build_external_merge_request_diff_files(rows) if use_external_diff? rows = build_external_merge_request_diff_files(rows) if use_external_diff?
# Faster inserts # Faster inserts
Gitlab::Database.bulk_insert('merge_request_diff_files', rows) # rubocop:disable Gitlab/BulkInsert Gitlab::Database.main.bulk_insert('merge_request_diff_files', rows) # rubocop:disable Gitlab/BulkInsert
end end
def build_external_diff_tempfile(rows) def build_external_diff_tempfile(rows)
......
...@@ -63,7 +63,7 @@ class MergeRequestDiffCommit < ApplicationRecord ...@@ -63,7 +63,7 @@ class MergeRequestDiffCommit < ApplicationRecord
) )
end end
Gitlab::Database.bulk_insert(self.table_name, rows) # rubocop:disable Gitlab/BulkInsert Gitlab::Database.main.bulk_insert(self.table_name, rows) # rubocop:disable Gitlab/BulkInsert
end end
def self.prepare_commits_for_bulk_insert(commits) def self.prepare_commits_for_bulk_insert(commits)
......
...@@ -2818,11 +2818,11 @@ class Project < ApplicationRecord ...@@ -2818,11 +2818,11 @@ class Project < ApplicationRecord
end end
def cache_has_external_wiki def cache_has_external_wiki
update_column(:has_external_wiki, integrations.external_wikis.any?) if Gitlab::Database.read_write? update_column(:has_external_wiki, integrations.external_wikis.any?) if Gitlab::Database.main.read_write?
end end
def cache_has_external_issue_tracker def cache_has_external_issue_tracker
update_column(:has_external_issue_tracker, integrations.external_issue_trackers.any?) if Gitlab::Database.read_write? update_column(:has_external_issue_tracker, integrations.external_issue_trackers.any?) if Gitlab::Database.main.read_write?
end end
def active_runners_with_tags def active_runners_with_tags
......
...@@ -38,7 +38,7 @@ class ProjectStatistics < ApplicationRecord ...@@ -38,7 +38,7 @@ class ProjectStatistics < ApplicationRecord
end end
def refresh!(only: []) def refresh!(only: [])
return if Gitlab::Database.read_only? return if Gitlab::Database.main.read_only?
COLUMNS_TO_REFRESH.each do |column, generator| COLUMNS_TO_REFRESH.each do |column, generator|
if only.empty? || only.include?(column) if only.empty? || only.include?(column)
......
...@@ -34,7 +34,7 @@ class SnippetStatistics < ApplicationRecord ...@@ -34,7 +34,7 @@ class SnippetStatistics < ApplicationRecord
end end
def refresh! def refresh!
return if Gitlab::Database.read_only? return if Gitlab::Database.main.read_only?
update_commit_count update_commit_count
update_repository_size update_repository_size
......
...@@ -80,7 +80,7 @@ class User < ApplicationRecord ...@@ -80,7 +80,7 @@ class User < ApplicationRecord
# to limit database writes to at most once every hour # to limit database writes to at most once every hour
# rubocop: disable CodeReuse/ServiceClass # rubocop: disable CodeReuse/ServiceClass
def update_tracked_fields!(request) def update_tracked_fields!(request)
return if Gitlab::Database.read_only? return if Gitlab::Database.main.read_only?
update_tracked_fields(request) update_tracked_fields(request)
...@@ -363,7 +363,7 @@ class User < ApplicationRecord ...@@ -363,7 +363,7 @@ class User < ApplicationRecord
end end
before_transition do before_transition do
!Gitlab::Database.read_only? !Gitlab::Database.main.read_only?
end end
# rubocop: disable CodeReuse/ServiceClass # rubocop: disable CodeReuse/ServiceClass
...@@ -848,11 +848,11 @@ class User < ApplicationRecord ...@@ -848,11 +848,11 @@ class User < ApplicationRecord
end end
def remember_me! def remember_me!
super if ::Gitlab::Database.read_write? super if ::Gitlab::Database.main.read_write?
end end
def forget_me! def forget_me!
super if ::Gitlab::Database.read_write? super if ::Gitlab::Database.main.read_write?
end end
def disable_two_factor! def disable_two_factor!
...@@ -1750,7 +1750,7 @@ class User < ApplicationRecord ...@@ -1750,7 +1750,7 @@ class User < ApplicationRecord
# #
# rubocop: disable CodeReuse/ServiceClass # rubocop: disable CodeReuse/ServiceClass
def increment_failed_attempts! def increment_failed_attempts!
return if ::Gitlab::Database.read_only? return if ::Gitlab::Database.main.read_only?
increment_failed_attempts increment_failed_attempts
...@@ -1994,7 +1994,7 @@ class User < ApplicationRecord ...@@ -1994,7 +1994,7 @@ class User < ApplicationRecord
def consume_otp! def consume_otp!
if self.consumed_timestep != current_otp_timestep if self.consumed_timestep != current_otp_timestep
self.consumed_timestep = current_otp_timestep self.consumed_timestep = current_otp_timestep
return Gitlab::Database.read_only? ? true : save(validate: false) return Gitlab::Database.main.read_only? ? true : save(validate: false)
end end
false false
......
...@@ -111,7 +111,7 @@ class AuditEventService ...@@ -111,7 +111,7 @@ class AuditEventService
end end
def log_security_event_to_database def log_security_event_to_database
return if Gitlab::Database.read_only? return if Gitlab::Database.main.read_only?
event = AuditEvent.new(base_payload.merge(details: @details)) event = AuditEvent.new(base_payload.merge(details: @details))
save_or_track event save_or_track event
...@@ -120,7 +120,7 @@ class AuditEventService ...@@ -120,7 +120,7 @@ class AuditEventService
end end
def log_authentication_event_to_database def log_authentication_event_to_database
return unless Gitlab::Database.read_write? && authentication_event? return unless Gitlab::Database.main.read_write? && authentication_event?
event = AuthenticationEvent.new(authentication_event_payload) event = AuthenticationEvent.new(authentication_event_payload)
save_or_track event save_or_track event
......
...@@ -4,7 +4,7 @@ module Boards ...@@ -4,7 +4,7 @@ module Boards
module Visits module Visits
class CreateService < Boards::BaseService class CreateService < Boards::BaseService
def execute(board) def execute(board)
return unless current_user && Gitlab::Database.read_write? return unless current_user && Gitlab::Database.main.read_write?
return unless board return unless board
model.visited!(current_user, board) model.visited!(current_user, board)
......
...@@ -181,12 +181,12 @@ module DesignManagement ...@@ -181,12 +181,12 @@ module DesignManagement
) )
end end
# TODO Replace `Gitlab::Database.bulk_insert` with `BulkInsertSafe` # TODO Replace `Gitlab::Database.main.bulk_insert` with `BulkInsertSafe`
# once https://gitlab.com/gitlab-org/gitlab/-/issues/247718 is fixed. # once https://gitlab.com/gitlab-org/gitlab/-/issues/247718 is fixed.
# When this is fixed, we can remove the call to # When this is fixed, we can remove the call to
# `with_project_iid_supply` above, since the objects will be instantiated # `with_project_iid_supply` above, since the objects will be instantiated
# and callbacks (including `ensure_project_iid!`) will fire. # and callbacks (including `ensure_project_iid!`) will fire.
::Gitlab::Database.bulk_insert( # rubocop:disable Gitlab/BulkInsert ::Gitlab::Database.main.bulk_insert( # rubocop:disable Gitlab/BulkInsert
DesignManagement::Design.table_name, DesignManagement::Design.table_name,
new_rows, new_rows,
return_ids: true return_ids: true
...@@ -207,9 +207,9 @@ module DesignManagement ...@@ -207,9 +207,9 @@ module DesignManagement
) )
end end
# TODO Replace `Gitlab::Database.bulk_insert` with `BulkInsertSafe` # TODO Replace `Gitlab::Database.main.bulk_insert` with `BulkInsertSafe`
# once https://gitlab.com/gitlab-org/gitlab/-/issues/247718 is fixed. # once https://gitlab.com/gitlab-org/gitlab/-/issues/247718 is fixed.
::Gitlab::Database.bulk_insert( # rubocop:disable Gitlab/BulkInsert ::Gitlab::Database.main.bulk_insert( # rubocop:disable Gitlab/BulkInsert
DesignManagement::Version.table_name, DesignManagement::Version.table_name,
new_rows, new_rows,
return_ids: true return_ids: true
...@@ -239,7 +239,7 @@ module DesignManagement ...@@ -239,7 +239,7 @@ module DesignManagement
end end
# We cannot use `BulkInsertSafe` because of the uploader mounted in `Action`. # We cannot use `BulkInsertSafe` because of the uploader mounted in `Action`.
::Gitlab::Database.bulk_insert( # rubocop:disable Gitlab/BulkInsert ::Gitlab::Database.main.bulk_insert( # rubocop:disable Gitlab/BulkInsert
DesignManagement::Action.table_name, DesignManagement::Action.table_name,
new_rows new_rows
) )
...@@ -278,7 +278,7 @@ module DesignManagement ...@@ -278,7 +278,7 @@ module DesignManagement
# We cannot use `BulkInsertSafe` due to the LfsObjectsProject#update_project_statistics # We cannot use `BulkInsertSafe` due to the LfsObjectsProject#update_project_statistics
# callback that fires after_commit. # callback that fires after_commit.
::Gitlab::Database.bulk_insert( # rubocop:disable Gitlab/BulkInsert ::Gitlab::Database.main.bulk_insert( # rubocop:disable Gitlab/BulkInsert
LfsObjectsProject.table_name, LfsObjectsProject.table_name,
new_rows, new_rows,
on_conflict: :do_nothing # Upsert on_conflict: :do_nothing # Upsert
......
...@@ -99,7 +99,7 @@ module Issuable ...@@ -99,7 +99,7 @@ module Issuable
yield(event) yield(event)
end.compact end.compact
Gitlab::Database.bulk_insert(table_name, events) # rubocop:disable Gitlab/BulkInsert Gitlab::Database.main.bulk_insert(table_name, events) # rubocop:disable Gitlab/BulkInsert
end end
end end
......
...@@ -18,7 +18,7 @@ module Keys ...@@ -18,7 +18,7 @@ module Keys
end end
def update? def update?
return false if ::Gitlab::Database.read_only? return false if ::Gitlab::Database.main.read_only?
last_used = key.last_used_at last_used = key.last_used_at
......
...@@ -166,7 +166,7 @@ module MergeRequests ...@@ -166,7 +166,7 @@ module MergeRequests
strong_memoize(:service_error) do strong_memoize(:service_error) do
if !merge_request if !merge_request
ServiceResponse.error(message: 'Invalid argument') ServiceResponse.error(message: 'Invalid argument')
elsif Gitlab::Database.read_only? elsif Gitlab::Database.main.read_only?
ServiceResponse.error(message: 'Unsupported operation') ServiceResponse.error(message: 'Unsupported operation')
end end
end end
......
...@@ -76,7 +76,7 @@ module Packages ...@@ -76,7 +76,7 @@ module Packages
end end
def database def database
::Gitlab::Database ::Gitlab::Database.main
end end
end end
end end
...@@ -11,7 +11,7 @@ module Packages ...@@ -11,7 +11,7 @@ module Packages
::Gitlab::UsageDataCounters::PackageEventCounter.count(event_name) ::Gitlab::UsageDataCounters::PackageEventCounter.count(event_name)
end end
if Feature.enabled?(:collect_package_events) && Gitlab::Database.read_write? if Feature.enabled?(:collect_package_events) && Gitlab::Database.main.read_write?
::Packages::Event.create!( ::Packages::Event.create!(
event_type: event_name, event_type: event_name,
originator: current_user&.id, originator: current_user&.id,
......
...@@ -41,7 +41,7 @@ module Packages ...@@ -41,7 +41,7 @@ module Packages
} }
end end
::Gitlab::Database.bulk_insert(::Packages::Nuget::DependencyLinkMetadatum.table_name, rows.compact) # rubocop:disable Gitlab/BulkInsert ::Gitlab::Database.main.bulk_insert(::Packages::Nuget::DependencyLinkMetadatum.table_name, rows.compact) # rubocop:disable Gitlab/BulkInsert
end end
def raw_dependency_for(dependency) def raw_dependency_for(dependency)
......
...@@ -15,7 +15,7 @@ module Packages ...@@ -15,7 +15,7 @@ module Packages
tags_to_create = @tags - existing_tags tags_to_create = @tags - existing_tags
@package.tags.with_name(tags_to_destroy).delete_all if tags_to_destroy.any? @package.tags.with_name(tags_to_destroy).delete_all if tags_to_destroy.any?
::Gitlab::Database.bulk_insert(Packages::Tag.table_name, rows(tags_to_create)) if tags_to_create.any? # rubocop:disable Gitlab/BulkInsert ::Gitlab::Database.main.bulk_insert(Packages::Tag.table_name, rows(tags_to_create)) if tags_to_create.any? # rubocop:disable Gitlab/BulkInsert
end end
private private
......
...@@ -18,7 +18,7 @@ module PersonalAccessTokens ...@@ -18,7 +18,7 @@ module PersonalAccessTokens
private private
def update? def update?
return false if ::Gitlab::Database.read_only? return false if ::Gitlab::Database.main.read_only?
last_used = @personal_access_token.last_used_at last_used = @personal_access_token.last_used_at
......
...@@ -21,7 +21,7 @@ module Projects ...@@ -21,7 +21,7 @@ module Projects
.update_all(share: update[:share]) .update_all(share: update[:share])
end end
Gitlab::Database.bulk_insert( # rubocop:disable Gitlab/BulkInsert Gitlab::Database.main.bulk_insert( # rubocop:disable Gitlab/BulkInsert
RepositoryLanguage.table_name, RepositoryLanguage.table_name,
detection.insertions(matching_programming_languages) detection.insertions(matching_programming_languages)
) )
......
...@@ -38,7 +38,7 @@ module Projects ...@@ -38,7 +38,7 @@ module Projects
rows = existent_lfs_objects rows = existent_lfs_objects
.not_linked_to_project(project) .not_linked_to_project(project)
.map { |existing_lfs_object| { project_id: project.id, lfs_object_id: existing_lfs_object.id } } .map { |existing_lfs_object| { project_id: project.id, lfs_object_id: existing_lfs_object.id } }
Gitlab::Database.bulk_insert(:lfs_objects_projects, rows) # rubocop:disable Gitlab/BulkInsert Gitlab::Database.main.bulk_insert(:lfs_objects_projects, rows) # rubocop:disable Gitlab/BulkInsert
iterations += 1 iterations += 1
linked_existing_objects += existent_lfs_objects.map(&:oid) linked_existing_objects += existent_lfs_objects.map(&:oid)
......
...@@ -19,7 +19,7 @@ class Repositories::DestroyService < Repositories::BaseService ...@@ -19,7 +19,7 @@ class Repositories::DestroyService < Repositories::BaseService
# never be triggered on a read-only instance. # never be triggered on a read-only instance.
# #
# Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/223272 # Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/223272
if Gitlab::Database.read_only? if Gitlab::Database.main.read_only?
Repositories::ShellDestroyService.new(current_repository).execute Repositories::ShellDestroyService.new(current_repository).execute
else else
container.run_after_commit do container.run_after_commit do
......
...@@ -23,7 +23,7 @@ module ResourceEvents ...@@ -23,7 +23,7 @@ module ResourceEvents
label_hash.merge(label_id: label.id, action: ResourceLabelEvent.actions['remove']) label_hash.merge(label_id: label.id, action: ResourceLabelEvent.actions['remove'])
end end
Gitlab::Database.bulk_insert(ResourceLabelEvent.table_name, labels) # rubocop:disable Gitlab/BulkInsert Gitlab::Database.main.bulk_insert(ResourceLabelEvent.table_name, labels) # rubocop:disable Gitlab/BulkInsert
resource.expire_note_etag_cache resource.expire_note_etag_cache
Gitlab::UsageDataCounters::IssueActivityUniqueCounter.track_issue_label_changed_action(author: user) if resource.is_a?(Issue) Gitlab::UsageDataCounters::IssueActivityUniqueCounter.track_issue_label_changed_action(author: user) if resource.is_a?(Issue)
......
...@@ -25,7 +25,7 @@ module Suggestions ...@@ -25,7 +25,7 @@ module Suggestions
end end
rows.in_groups_of(100, false) do |rows| rows.in_groups_of(100, false) do |rows|
Gitlab::Database.bulk_insert('suggestions', rows) # rubocop:disable Gitlab/BulkInsert Gitlab::Database.main.bulk_insert('suggestions', rows) # rubocop:disable Gitlab/BulkInsert
end end
Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter.track_add_suggestion_action(user: @note.author) Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter.track_add_suggestion_action(user: @note.author)
......
...@@ -23,7 +23,7 @@ module Users ...@@ -23,7 +23,7 @@ module Users
private private
def record_activity def record_activity
return if Gitlab::Database.read_only? return if Gitlab::Database.main.read_only?
today = Date.today today = Date.today
......
...@@ -152,9 +152,9 @@ ...@@ -152,9 +152,9 @@
%span.float-right %span.float-right
#{Rails::VERSION::STRING} #{Rails::VERSION::STRING}
%p %p
= Gitlab::Database.human_adapter_name = Gitlab::Database.main.human_adapter_name
%span.float-right %span.float-right
= Gitlab::Database.version = Gitlab::Database.main.version
%p %p
= _('Redis') = _('Redis')
%span.float-right %span.float-right
......
...@@ -124,7 +124,7 @@ module GitGarbageCollectMethods ...@@ -124,7 +124,7 @@ module GitGarbageCollectMethods
def update_repository_statistics(resource) def update_repository_statistics(resource)
resource.repository.expire_statistics_caches resource.repository.expire_statistics_caches
return if Gitlab::Database.read_only? # GitGarbageCollectWorker may be run on a Geo secondary return if Gitlab::Database.main.read_only? # GitGarbageCollectWorker may be run on a Geo secondary
update_db_repository_statistics(resource) update_db_repository_statistics(resource)
end end
......
...@@ -54,7 +54,7 @@ module Gitlab ...@@ -54,7 +54,7 @@ module Gitlab
label_link_attrs << build_label_attrs(issue_id, import_label_id.to_i) label_link_attrs << build_label_attrs(issue_id, import_label_id.to_i)
Gitlab::Database.bulk_insert(LabelLink.table_name, label_link_attrs) # rubocop:disable Gitlab/BulkInsert Gitlab::Database.main.bulk_insert(LabelLink.table_name, label_link_attrs) # rubocop:disable Gitlab/BulkInsert
end end
def assign_issue(project_id, issue_id, assignee_ids) def assign_issue(project_id, issue_id, assignee_ids)
...@@ -62,7 +62,7 @@ module Gitlab ...@@ -62,7 +62,7 @@ module Gitlab
assignee_attrs = assignee_ids.map { |user_id| { issue_id: issue_id, user_id: user_id } } assignee_attrs = assignee_ids.map { |user_id| { issue_id: issue_id, user_id: user_id } }
Gitlab::Database.bulk_insert(IssueAssignee.table_name, assignee_attrs) # rubocop:disable Gitlab/BulkInsert Gitlab::Database.main.bulk_insert(IssueAssignee.table_name, assignee_attrs) # rubocop:disable Gitlab/BulkInsert
end end
def build_label_attrs(issue_id, label_id) def build_label_attrs(issue_id, label_id)
......
...@@ -11,7 +11,7 @@ class PagesDomainVerificationCronWorker # rubocop:disable Scalability/Idempotent ...@@ -11,7 +11,7 @@ class PagesDomainVerificationCronWorker # rubocop:disable Scalability/Idempotent
worker_resource_boundary :cpu worker_resource_boundary :cpu
def perform def perform
return if Gitlab::Database.read_only? return if Gitlab::Database.main.read_only?
PagesDomain.needs_verification.with_logging_info.find_each do |domain| PagesDomain.needs_verification.with_logging_info.find_each do |domain|
with_context(project: domain.project) do with_context(project: domain.project) do
......
...@@ -12,7 +12,7 @@ class PagesDomainVerificationWorker # rubocop:disable Scalability/IdempotentWork ...@@ -12,7 +12,7 @@ class PagesDomainVerificationWorker # rubocop:disable Scalability/IdempotentWork
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def perform(domain_id) def perform(domain_id)
return if Gitlab::Database.read_only? return if Gitlab::Database.main.read_only?
domain = PagesDomain.find_by(id: domain_id) domain = PagesDomain.find_by(id: domain_id)
......
...@@ -44,7 +44,7 @@ class ProjectCacheWorker ...@@ -44,7 +44,7 @@ class ProjectCacheWorker
# statistics to become accurate if they were already updated once in the # statistics to become accurate if they were already updated once in the
# last 15 minutes. # last 15 minutes.
def update_statistics(project, statistics = []) def update_statistics(project, statistics = [])
return if Gitlab::Database.read_only? return if Gitlab::Database.main.read_only?
return unless try_obtain_lease_for(project.id, statistics) return unless try_obtain_lease_for(project.id, statistics)
Projects::UpdateStatisticsService.new(project, nil, statistics: statistics).execute Projects::UpdateStatisticsService.new(project, nil, statistics: statistics).execute
......
...@@ -23,7 +23,7 @@ module Projects ...@@ -23,7 +23,7 @@ module Projects
end end
def cleanup_orphan_lfs_file_references(resource) def cleanup_orphan_lfs_file_references(resource)
return if Gitlab::Database.read_only? # GitGarbageCollectWorker may be run on a Geo secondary return if Gitlab::Database.main.read_only? # GitGarbageCollectWorker may be run on a Geo secondary
::Gitlab::Cleanup::OrphanLfsFileReferences.new(resource, dry_run: false, logger: logger).run! ::Gitlab::Cleanup::OrphanLfsFileReferences.new(resource, dry_run: false, logger: logger).run!
rescue StandardError => err rescue StandardError => err
......
...@@ -12,7 +12,7 @@ class ScheduleMergeRequestCleanupRefsWorker ...@@ -12,7 +12,7 @@ class ScheduleMergeRequestCleanupRefsWorker
idempotent! idempotent!
def perform def perform
return if Gitlab::Database.read_only? return if Gitlab::Database.main.read_only?
return unless Feature.enabled?(:merge_request_refs_cleanup, default_enabled: false) return unless Feature.enabled?(:merge_request_refs_cleanup, default_enabled: false)
MergeRequestCleanupRefsWorker.perform_with_capacity MergeRequestCleanupRefsWorker.perform_with_capacity
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
### Performance (1 change) ### Performance (1 change)
- Memoize Gitlab::Database.version. - Memoize Gitlab::Database.main.version.
## 10.8.2 (2018-05-28) ## 10.8.2 (2018-05-28)
......
...@@ -2006,7 +2006,7 @@ ...@@ -2006,7 +2006,7 @@
- Don't delete assigned MRs/issues when user is deleted. - Don't delete assigned MRs/issues when user is deleted.
- Remove new branch button for confidential issues. - Remove new branch button for confidential issues.
- Don't allow project guests to subscribe to merge requests through the API. (Robert Schilling) - Don't allow project guests to subscribe to merge requests through the API. (Robert Schilling)
- Don't connect in Gitlab::Database.adapter_name. - Don't connect in Gitlab::Database.main.adapter_name.
- Prevent users from creating notes on resources they can't access. - Prevent users from creating notes on resources they can't access.
- Ignore encrypted attributes in Import/Export. - Ignore encrypted attributes in Import/Export.
- Change rspec test to guarantee window is resized before visiting page. - Change rspec test to guarantee window is resized before visiting page.
......
# frozen_string_literal: true # frozen_string_literal: true
raise "PostgreSQL is the only supported database from GitLab 12.1" unless raise "PostgreSQL is the only supported database from GitLab 12.1" unless
Gitlab::Database.postgresql? Gitlab::Database.main.postgresql?
Gitlab::Database.check_postgres_version_and_print_warning Gitlab::Database.check_postgres_version_and_print_warning
...@@ -14,7 +14,7 @@ end ...@@ -14,7 +14,7 @@ end
if defined?(ActiveRecord::Base) if defined?(ActiveRecord::Base)
Gitlab::Cluster::LifecycleEvents.on_before_fork do Gitlab::Cluster::LifecycleEvents.on_before_fork do
raise 'ActiveRecord connection not established. Unable to start.' unless Gitlab::Database.exists? raise 'ActiveRecord connection not established. Unable to start.' unless Gitlab::Database.main.exists?
# the following is highly recommended for Rails + "preload_app true" # the following is highly recommended for Rails + "preload_app true"
# as there's no need for the master process to hold a connection # as there's no need for the master process to hold a connection
......
...@@ -10,8 +10,8 @@ if Gitlab::Runtime.console? ...@@ -10,8 +10,8 @@ if Gitlab::Runtime.console?
puts " GitLab:".ljust(justify) + "#{Gitlab::VERSION} (#{Gitlab.revision}) #{Gitlab.ee? ? 'EE' : 'FOSS'}" puts " GitLab:".ljust(justify) + "#{Gitlab::VERSION} (#{Gitlab.revision}) #{Gitlab.ee? ? 'EE' : 'FOSS'}"
puts " GitLab Shell:".ljust(justify) + "#{Gitlab::VersionInfo.parse(Gitlab::Shell.version)}" puts " GitLab Shell:".ljust(justify) + "#{Gitlab::VersionInfo.parse(Gitlab::Shell.version)}"
if Gitlab::Database.exists? if Gitlab::Database.main.exists?
puts " #{Gitlab::Database.human_adapter_name}:".ljust(justify) + Gitlab::Database.version puts " #{Gitlab::Database.main.human_adapter_name}:".ljust(justify) + Gitlab::Database.main.version
Gitlab.ee do Gitlab.ee do
if Gitlab::Geo.connected? && Gitlab::Geo.enabled? if Gitlab::Geo.connected? && Gitlab::Geo.enabled?
......
...@@ -20,16 +20,16 @@ Gitlab.ee do ...@@ -20,16 +20,16 @@ Gitlab.ee do
end end
end end
db_config = Gitlab::Database.config || db_config = Gitlab::Database.main.config ||
Rails.application.config.database_configuration[Rails.env] Rails.application.config.database_configuration[Rails.env]
ActiveRecord::Base.establish_connection( ActiveRecord::Base.establish_connection(
db_config.merge(pool: Gitlab::Database.default_pool_size) db_config.merge(pool: Gitlab::Database.main.default_pool_size)
) )
Gitlab.ee do Gitlab.ee do
if Gitlab::Runtime.sidekiq? && Gitlab::Geo.geo_database_configured? if Gitlab::Runtime.sidekiq? && Gitlab::Geo.geo_database_configured?
Rails.configuration.geo_database['pool'] = Gitlab::Database.default_pool_size Rails.configuration.geo_database['pool'] = Gitlab::Database.main.default_pool_size
Geo::TrackingBase.establish_connection(Rails.configuration.geo_database) Geo::TrackingBase.establish_connection(Rails.configuration.geo_database)
end end
end end
...@@ -4,6 +4,6 @@ ...@@ -4,6 +4,6 @@
# `Shard.connected?` could be cached and return true even though the table doesn't exist # `Shard.connected?` could be cached and return true even though the table doesn't exist
return unless Shard.connected? return unless Shard.connected?
return unless ActiveRecord::Migrator.current_version >= 20190402150158 return unless ActiveRecord::Migrator.current_version >= 20190402150158
return if Gitlab::Database.read_only? return if Gitlab::Database.main.read_only?
Shard.populate! Shard.populate!
...@@ -20,7 +20,7 @@ module Sidekiq ...@@ -20,7 +20,7 @@ module Sidekiq
module NoEnqueueingFromTransactions module NoEnqueueingFromTransactions
%i(perform_async perform_at perform_in).each do |name| %i(perform_async perform_at perform_in).each do |name|
define_method(name) do |*args| define_method(name) do |*args|
if !Sidekiq::Worker.skip_transaction_check && Gitlab::Database.inside_transaction? if !Sidekiq::Worker.skip_transaction_check && Gitlab::Database.main.inside_transaction?
begin begin
raise Sidekiq::Worker::EnqueueFromTransactionError, <<~MSG raise Sidekiq::Worker::EnqueueFromTransactionError, <<~MSG
`#{self}.#{name}` cannot be called inside a transaction as this can lead to `#{self}.#{name}` cannot be called inside a transaction as this can lead to
......
# frozen_string_literal: true # frozen_string_literal: true
if Gitlab::Database::LoadBalancing.enable? if Gitlab::Database::LoadBalancing.enable?
Gitlab::Database.disable_prepared_statements Gitlab::Database.main.disable_prepared_statements
Gitlab::Application.configure do |config| Gitlab::Application.configure do |config|
config.middleware.use(Gitlab::Database::LoadBalancing::RackMiddleware) config.middleware.use(Gitlab::Database::LoadBalancing::RackMiddleware)
......
...@@ -20,7 +20,7 @@ class MigrateSamlIdentitiesToScimIdentities < ActiveRecord::Migration[6.0] ...@@ -20,7 +20,7 @@ class MigrateSamlIdentitiesToScimIdentities < ActiveRecord::Migration[6.0]
record.attributes.extract!("extern_uid", "user_id", "group_id", "active", "created_at", "updated_at") record.attributes.extract!("extern_uid", "user_id", "group_id", "active", "created_at", "updated_at")
end end
Gitlab::Database.bulk_insert(:scim_identities, data_to_insert, on_conflict: :do_nothing) # rubocop:disable Gitlab/BulkInsert Gitlab::Database.main.bulk_insert(:scim_identities, data_to_insert, on_conflict: :do_nothing) # rubocop:disable Gitlab/BulkInsert
end end
end end
......
...@@ -445,7 +445,7 @@ module EE ...@@ -445,7 +445,7 @@ module EE
override :perform override :perform
def perform(table_name = EVENT_TABLES.first) def perform(table_name = EVENT_TABLES.first)
return if ::Gitlab::Database.read_only? return if ::Gitlab::Database.main.read_only?
deleted_rows = prune_orphaned_rows(table_name) deleted_rows = prune_orphaned_rows(table_name)
table_name = next_table(table_name) if deleted_rows.zero? table_name = next_table(table_name) if deleted_rows.zero?
......
...@@ -368,12 +368,12 @@ All Geo **secondary** nodes are read-only. ...@@ -368,12 +368,12 @@ All Geo **secondary** nodes are read-only.
The general principle of a [read-only database](verifying_database_capabilities.md#read-only-database) The general principle of a [read-only database](verifying_database_capabilities.md#read-only-database)
applies to all Geo **secondary** nodes. So the applies to all Geo **secondary** nodes. So the
`Gitlab::Database.read_only?` method will always return `true` on a `Gitlab::Database.main.read_only?` method will always return `true` on a
**secondary** node. **secondary** node.
When some write actions are not allowed because the node is a When some write actions are not allowed because the node is a
**secondary**, consider adding the `Gitlab::Database.read_only?` or **secondary**, consider adding the `Gitlab::Database.main.read_only?` or
`Gitlab::Database.read_write?` guard, instead of `Gitlab::Geo.secondary?`. `Gitlab::Database.main.read_write?` guard, instead of `Gitlab::Geo.secondary?`.
The database itself will already be read-only in a replicated setup, The database itself will already be read-only in a replicated setup,
so we don't need to take any extra step for that. so we don't need to take any extra step for that.
......
...@@ -11,7 +11,7 @@ info: To determine the technical writer assigned to the Stage/Group associated w ...@@ -11,7 +11,7 @@ info: To determine the technical writer assigned to the Stage/Group associated w
GitLab Maintenance Mode **only** blocks writes from HTTP and SSH requests at the application level in a few key places within the rails application. GitLab Maintenance Mode **only** blocks writes from HTTP and SSH requests at the application level in a few key places within the rails application.
[Search the codebase for `maintenance_mode?`.](https://gitlab.com/search?search=maintenance_mode%3F&group_id=9970&project_id=278964&scope=blobs&search_code=false&snippets=false&repository_ref=) [Search the codebase for `maintenance_mode?`.](https://gitlab.com/search?search=maintenance_mode%3F&group_id=9970&project_id=278964&scope=blobs&search_code=false&snippets=false&repository_ref=)
- [the read-only database method](https://gitlab.com/gitlab-org/gitlab/-/blob/2425e9de50c678413ceaad6ee3bf66f42b7e228c/ee/lib/ee/gitlab/database.rb#L13), which toggles special behavior when we are not allowed to write to the database. [Search the codebase for `Gitlab::Database.read_only?`.](https://gitlab.com/search?search=Gitlab%3A%3ADatabase.read_only%3F&group_id=9970&project_id=278964&scope=blobs&search_code=false&snippets=false&repository_ref=) - [the read-only database method](https://gitlab.com/gitlab-org/gitlab/-/blob/2425e9de50c678413ceaad6ee3bf66f42b7e228c/ee/lib/ee/gitlab/database.rb#L13), which toggles special behavior when we are not allowed to write to the database. [Search the codebase for `Gitlab::Database.main.read_only?`.](https://gitlab.com/search?search=Gitlab%3A%3ADatabase.read_only%3F&group_id=9970&project_id=278964&scope=blobs&search_code=false&snippets=false&repository_ref=)
- [the read-only middleware](https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/lib/ee/gitlab/middleware/read_only/controller.rb), where HTTP requests that cause database writes are blocked, unless explicitly allowed. - [the read-only middleware](https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/lib/ee/gitlab/middleware/read_only/controller.rb), where HTTP requests that cause database writes are blocked, unless explicitly allowed.
- [Git push access via SSH is denied](https://gitlab.com/gitlab-org/gitlab/-/blob/2425e9de50c678413ceaad6ee3bf66f42b7e228c/ee/lib/ee/gitlab/git_access.rb#L13) by returning 401 when `gitlab-shell` POSTs to [`/internal/allowed`](internal_api.md) to [check if access is allowed](internal_api.md#git-authentication). - [Git push access via SSH is denied](https://gitlab.com/gitlab-org/gitlab/-/blob/2425e9de50c678413ceaad6ee3bf66f42b7e228c/ee/lib/ee/gitlab/git_access.rb#L13) by returning 401 when `gitlab-shell` POSTs to [`/internal/allowed`](internal_api.md) to [check if access is allowed](internal_api.md#git-authentication).
- [Container registry authentication service](https://gitlab.com/gitlab-org/gitlab/-/blob/2425e9de50c678413ceaad6ee3bf66f42b7e228c/ee/app/services/ee/auth/container_registry_authentication_service.rb#L12), where updates to the container registry are blocked. - [Container registry authentication service](https://gitlab.com/gitlab-org/gitlab/-/blob/2425e9de50c678413ceaad6ee3bf66f42b7e228c/ee/app/services/ee/auth/container_registry_authentication_service.rb#L12), where updates to the container registry are blocked.
......
...@@ -12,13 +12,13 @@ necessary to add database (version) specific behavior. ...@@ -12,13 +12,13 @@ necessary to add database (version) specific behavior.
To facilitate this we have the following methods that you can use: To facilitate this we have the following methods that you can use:
- `Gitlab::Database.version`: returns the PostgreSQL version number as a string - `Gitlab::Database.main.version`: returns the PostgreSQL version number as a string
in the format `X.Y.Z`. in the format `X.Y.Z`.
This allows you to write code such as: This allows you to write code such as:
```ruby ```ruby
if Gitlab::Database.version.to_f >= 11.7 if Gitlab::Database.main.version.to_f >= 11.7
run_really_fast_query run_really_fast_query
else else
run_fast_query run_fast_query
...@@ -30,7 +30,7 @@ end ...@@ -30,7 +30,7 @@ end
The database can be used in read-only mode. In this case we have to The database can be used in read-only mode. In this case we have to
make sure all GET requests don't attempt any write operations to the make sure all GET requests don't attempt any write operations to the
database. If one of those requests wants to write to the database, it needs database. If one of those requests wants to write to the database, it needs
to be wrapped in a `Gitlab::Database.read_only?` or `Gitlab::Database.read_write?` to be wrapped in a `Gitlab::Database.main.read_only?` or `Gitlab::Database.main.read_write?`
guard, to make sure it doesn't for read-only databases. guard, to make sure it doesn't for read-only databases.
We have a Rails Middleware that filters any potentially writing We have a Rails Middleware that filters any potentially writing
......
...@@ -54,7 +54,7 @@ module Groups ...@@ -54,7 +54,7 @@ module Groups
if params[:state].present? if params[:state].present?
preference.roadmap_epics_state = Epic.state_ids[params[:state]] preference.roadmap_epics_state = Epic.state_ids[params[:state]]
preference.save if preference.changed? && Gitlab::Database.read_write? preference.save if preference.changed? && Gitlab::Database.main.read_write?
end end
Epic.state_ids.key(preference.roadmap_epics_state) Epic.state_ids.key(preference.roadmap_epics_state)
......
...@@ -131,7 +131,7 @@ module EE ...@@ -131,7 +131,7 @@ module EE
end end
def show_ultimate_trial_suitable_env? def show_ultimate_trial_suitable_env?
::Gitlab.com? && !::Gitlab::Database.read_only? ::Gitlab.com? && !::Gitlab::Database.main.read_only?
end end
def token_expiration_enforced? def token_expiration_enforced?
......
...@@ -413,19 +413,19 @@ module EE ...@@ -413,19 +413,19 @@ module EE
end end
def elasticsearch_indexing_column_exists? def elasticsearch_indexing_column_exists?
::Gitlab::Database.cached_column_exists?(:application_settings, :elasticsearch_indexing) ::Gitlab::Database.main.cached_column_exists?(:application_settings, :elasticsearch_indexing)
end end
def elasticsearch_pause_indexing_column_exists? def elasticsearch_pause_indexing_column_exists?
::Gitlab::Database.cached_column_exists?(:application_settings, :elasticsearch_pause_indexing) ::Gitlab::Database.main.cached_column_exists?(:application_settings, :elasticsearch_pause_indexing)
end end
def elasticsearch_search_column_exists? def elasticsearch_search_column_exists?
::Gitlab::Database.cached_column_exists?(:application_settings, :elasticsearch_search) ::Gitlab::Database.main.cached_column_exists?(:application_settings, :elasticsearch_search)
end end
def email_additional_text_column_exists? def email_additional_text_column_exists?
::Gitlab::Database.cached_column_exists?(:application_settings, :email_additional_text) ::Gitlab::Database.main.cached_column_exists?(:application_settings, :email_additional_text)
end end
def check_geo_node_allowed_ips def check_geo_node_allowed_ips
......
...@@ -454,7 +454,7 @@ module EE ...@@ -454,7 +454,7 @@ module EE
def generate_subscription def generate_subscription
return unless persisted? return unless persisted?
return if ::Gitlab::Database.read_only? return if ::Gitlab::Database.main.read_only?
create_gitlab_subscription( create_gitlab_subscription(
plan_code: Plan::FREE, plan_code: Plan::FREE,
......
...@@ -37,7 +37,7 @@ class ElasticsearchIndexedNamespace < ApplicationRecord ...@@ -37,7 +37,7 @@ class ElasticsearchIndexedNamespace < ApplicationRecord
{ created_at: now, updated_at: now, namespace_id: id } { created_at: now, updated_at: now, namespace_id: id }
end end
Gitlab::Database.bulk_insert(table_name, insert_rows) # rubocop:disable Gitlab/BulkInsert Gitlab::Database.main.bulk_insert(table_name, insert_rows) # rubocop:disable Gitlab/BulkInsert
invalidate_elasticsearch_indexes_cache! invalidate_elasticsearch_indexes_cache!
jobs = batch_ids.map { |id| [id, :index] } jobs = batch_ids.map { |id| [id, :index] }
......
...@@ -19,7 +19,7 @@ class NamespaceStatistics < ApplicationRecord ...@@ -19,7 +19,7 @@ class NamespaceStatistics < ApplicationRecord
COLUMNS_TO_REFRESH = [:wiki_size].freeze COLUMNS_TO_REFRESH = [:wiki_size].freeze
def refresh!(only: []) def refresh!(only: [])
return if Gitlab::Database.read_only? return if Gitlab::Database.main.read_only?
return unless group? return unless group?
COLUMNS_TO_REFRESH.each do |column| COLUMNS_TO_REFRESH.each do |column|
......
...@@ -18,7 +18,7 @@ module AuditEvents ...@@ -18,7 +18,7 @@ module AuditEvents
return if collection.empty? return if collection.empty?
collection.in_groups_of(BATCH_SIZE, false) do |services| collection.in_groups_of(BATCH_SIZE, false) do |services|
::Gitlab::Database.bulk_insert(::AuditEvent.table_name, services.map(&:attributes)) # rubocop:disable Gitlab/BulkInsert ::Gitlab::Database.main.bulk_insert(::AuditEvent.table_name, services.map(&:attributes)) # rubocop:disable Gitlab/BulkInsert
services.each(&:log_security_event_to_file) services.each(&:log_security_event_to_file)
end end
......
...@@ -133,7 +133,7 @@ module EE ...@@ -133,7 +133,7 @@ module EE
# @return [AuditEvent, nil] if record is persisted or nil if audit events # @return [AuditEvent, nil] if record is persisted or nil if audit events
# features are not enabled # features are not enabled
def unauth_security_event def unauth_security_event
return unless audit_events_enabled? && ::Gitlab::Database.read_write? return unless audit_events_enabled? && ::Gitlab::Database.main.read_write?
add_security_event_admin_details! add_security_event_admin_details!
......
...@@ -15,7 +15,7 @@ module Geo ...@@ -15,7 +15,7 @@ module Geo
end end
def execute def execute
return if Gitlab::Database.read_only? return if Gitlab::Database.main.read_only?
try_obtain_lease do try_obtain_lease do
log_info('Prune Geo Event Log entries up to id', geo_event_log_id: event_log_min_id) log_info('Prune Geo Event Log entries up to id', geo_event_log_id: event_log_min_id)
......
...@@ -15,7 +15,7 @@ module Iterations ...@@ -15,7 +15,7 @@ module Iterations
return ::ServiceResponse.error(message: _('Cadence is not automated'), http_status: 422) unless cadence.can_be_automated? return ::ServiceResponse.error(message: _('Cadence is not automated'), http_status: 422) unless cadence.can_be_automated?
update_existing_iterations! update_existing_iterations!
::Gitlab::Database.bulk_insert(Iteration.table_name, build_new_iterations) # rubocop:disable Gitlab/BulkInsert ::Gitlab::Database.main.bulk_insert(Iteration.table_name, build_new_iterations) # rubocop:disable Gitlab/BulkInsert
cadence.update!(last_run_date: compute_last_run_date) cadence.update!(last_run_date: compute_last_run_date)
......
...@@ -20,8 +20,8 @@ module Iterations ...@@ -20,8 +20,8 @@ module Iterations
ApplicationRecord.transaction do ApplicationRecord.transaction do
issues.update_all(sprint_id: to_iteration.id, updated_at: rolled_over_at) issues.update_all(sprint_id: to_iteration.id, updated_at: rolled_over_at)
Gitlab::Database.bulk_insert(ResourceIterationEvent.table_name, remove_iteration_events) # rubocop:disable Gitlab/BulkInsert Gitlab::Database.main.bulk_insert(ResourceIterationEvent.table_name, remove_iteration_events) # rubocop:disable Gitlab/BulkInsert
Gitlab::Database.bulk_insert(ResourceIterationEvent.table_name, add_iteration_events) # rubocop:disable Gitlab/BulkInsert Gitlab::Database.main.bulk_insert(ResourceIterationEvent.table_name, add_iteration_events) # rubocop:disable Gitlab/BulkInsert
end end
end end
......
...@@ -10,7 +10,7 @@ module ResourceEvents ...@@ -10,7 +10,7 @@ module ResourceEvents
end end
def execute def execute
::Gitlab::Database.bulk_insert(ResourceWeightEvent.table_name, resource_weight_changes) # rubocop:disable Gitlab/BulkInsert ::Gitlab::Database.main.bulk_insert(ResourceWeightEvent.table_name, resource_weight_changes) # rubocop:disable Gitlab/BulkInsert
resource.expire_note_etag_cache resource.expire_note_etag_cache
Gitlab::UsageDataCounters::IssueActivityUniqueCounter.track_issue_weight_changed_action(author: user) Gitlab::UsageDataCounters::IssueActivityUniqueCounter.track_issue_weight_changed_action(author: user)
......
...@@ -46,7 +46,7 @@ module EE ...@@ -46,7 +46,7 @@ module EE
end end
def audit_push?(project) def audit_push?(project)
project.push_audit_events_enabled? && !::Gitlab::Database.read_only? project.push_audit_events_enabled? && !::Gitlab::Database.main.read_only?
end end
end end
end end
...@@ -16,7 +16,7 @@ module Geo ...@@ -16,7 +16,7 @@ module Geo
tags :exclude_from_gitlab_com tags :exclude_from_gitlab_com
def perform def perform
return if Gitlab::Database.read_only? return if Gitlab::Database.main.read_only?
return unless Gitlab::Database.main.healthy? return unless Gitlab::Database.main.healthy?
unless ::GeoNode.secondary_nodes.any? unless ::GeoNode.secondary_nodes.any?
......
...@@ -18,7 +18,7 @@ class ProjectImportScheduleWorker ...@@ -18,7 +18,7 @@ class ProjectImportScheduleWorker
tags :needs_own_queue tags :needs_own_queue
def perform(project_id) def perform(project_id)
return if Gitlab::Database.read_only? return if Gitlab::Database.main.read_only?
project = Project.with_route.with_import_state.with_namespace.find_by_id(project_id) project = Project.with_route.with_import_state.with_namespace.find_by_id(project_id)
raise ImportStateNotFound unless project&.import_state raise ImportStateNotFound unless project&.import_state
......
...@@ -14,7 +14,7 @@ class UpdateAllMirrorsWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -14,7 +14,7 @@ class UpdateAllMirrorsWorker # rubocop:disable Scalability/IdempotentWorker
RESCHEDULE_WAIT = 1.second RESCHEDULE_WAIT = 1.second
def perform def perform
return if Gitlab::Database.read_only? return if Gitlab::Database.main.read_only?
scheduled = 0 scheduled = 0
with_lease do with_lease do
......
...@@ -12,7 +12,7 @@ class UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker # rubocop:disable Scalab ...@@ -12,7 +12,7 @@ class UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker # rubocop:disable Scalab
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def perform def perform
return if ::Gitlab::Database.read_only? return if ::Gitlab::Database.main.read_only?
return unless ::Gitlab::CurrentSettings.should_check_namespace_plan? return unless ::Gitlab::CurrentSettings.should_check_namespace_plan?
GitlabSubscription.with_a_paid_hosted_plan.preload_for_refresh_seat.find_in_batches(batch_size: 100) do |subscriptions| GitlabSubscription.with_a_paid_hosted_plan.preload_for_refresh_seat.find_in_batches(batch_size: 100) do |subscriptions|
......
...@@ -10,7 +10,7 @@ module EE ...@@ -10,7 +10,7 @@ module EE
override :update_user override :update_user
def update_user def update_user
return if ::Gitlab::Database.read_only? return if ::Gitlab::Database.main.read_only?
update_user_attributes update_user_attributes
update_memberships update_memberships
......
...@@ -49,7 +49,7 @@ module EE ...@@ -49,7 +49,7 @@ module EE
} }
end end
Gitlab::Database.bulk_insert(:gitlab_subscriptions, rows) # rubocop:disable Gitlab/BulkInsert Gitlab::Database.main.bulk_insert(:gitlab_subscriptions, rows) # rubocop:disable Gitlab/BulkInsert
end end
end end
end end
......
...@@ -61,7 +61,7 @@ module EE ...@@ -61,7 +61,7 @@ module EE
override :perform override :perform
def perform(table_name = EVENT_TABLES.first) def perform(table_name = EVENT_TABLES.first)
return if ::Gitlab::Database.read_only? return if ::Gitlab::Database.main.read_only?
deleted_rows = prune_orphaned_rows(table_name) deleted_rows = prune_orphaned_rows(table_name)
table_name = next_table(table_name) if deleted_rows == 0 table_name = next_table(table_name) if deleted_rows == 0
......
...@@ -25,7 +25,7 @@ module EE ...@@ -25,7 +25,7 @@ module EE
end end
def geo_custom_action? def geo_custom_action?
return unless ::Gitlab::Database.read_only? return unless ::Gitlab::Database.main.read_only?
return unless ::Gitlab::Geo.secondary_with_primary? return unless ::Gitlab::Geo.secondary_with_primary?
receive_pack? || upload_pack_and_not_replicated? receive_pack? || upload_pack_and_not_replicated?
...@@ -55,7 +55,7 @@ module EE ...@@ -55,7 +55,7 @@ module EE
end end
def current_replication_lag_message def current_replication_lag_message
return if ::Gitlab::Database.read_write? || current_replication_lag == 0 return if ::Gitlab::Database.main.read_write? || current_replication_lag == 0
"Current replication lag: #{current_replication_lag} seconds" "Current replication lag: #{current_replication_lag} seconds"
end end
......
...@@ -14,7 +14,7 @@ module EE ...@@ -14,7 +14,7 @@ module EE
# This method can be called/loaded before the database # This method can be called/loaded before the database
# has been created. With this guard clause we prevent querying # has been created. With this guard clause we prevent querying
# the License table until the table exists # the License table until the table exists
return [] unless ::Gitlab::Database.cached_table_exists?('licenses') && return [] unless ::Gitlab::Database.main.cached_table_exists?('licenses') &&
License.feature_available?(:custom_project_templates) License.feature_available?(:custom_project_templates)
[::Gitlab::ImportSources::ImportSource.new('gitlab_custom_project_template', [::Gitlab::ImportSources::ImportSource.new('gitlab_custom_project_template',
......
...@@ -66,7 +66,7 @@ module EE ...@@ -66,7 +66,7 @@ module EE
action = route_hash[:action] action = route_hash[:action]
if ALLOWLISTED_GEO_ROUTES[controller]&.include?(action) if ALLOWLISTED_GEO_ROUTES[controller]&.include?(action)
::Gitlab::Database.db_read_write? ::Gitlab::Database.main.db_read_write?
else else
ALLOWLISTED_GEO_ROUTES_TRACKING_DB[controller]&.include?(action) ALLOWLISTED_GEO_ROUTES_TRACKING_DB[controller]&.include?(action)
end end
......
...@@ -9,7 +9,7 @@ module Gitlab ...@@ -9,7 +9,7 @@ module Gitlab
return '' unless Gitlab::Geo.secondary? return '' unless Gitlab::Geo.secondary?
return 'Geo database configuration file is missing.' unless Gitlab::Geo.geo_database_configured? return 'Geo database configuration file is missing.' unless Gitlab::Geo.geo_database_configured?
return 'An existing tracking database cannot be reused.' if reusing_existing_tracking_database? return 'An existing tracking database cannot be reused.' if reusing_existing_tracking_database?
return 'Geo node has a database that is writable which is an indication it is not configured for replication with the primary node.' unless Gitlab::Database.db_read_only? return 'Geo node has a database that is writable which is an indication it is not configured for replication with the primary node.' unless Gitlab::Database.main.db_read_only?
return 'Geo node does not appear to be replicating the database from the primary node.' if replication_enabled? && !replication_working? return 'Geo node does not appear to be replicating the database from the primary node.' if replication_enabled? && !replication_working?
return "Geo database version (#{database_version}) does not match latest migration (#{migration_version}).\nYou may have to run `gitlab-rake geo:db:migrate` as root on the secondary." unless database_migration_version_match? return "Geo database version (#{database_version}) does not match latest migration (#{migration_version}).\nYou may have to run `gitlab-rake geo:db:migrate` as root on the secondary." unless database_migration_version_match?
......
...@@ -10,7 +10,7 @@ RSpec.describe ApplicationHelper do ...@@ -10,7 +10,7 @@ RSpec.describe ApplicationHelper do
context 'when not in a Geo secondary' do context 'when not in a Geo secondary' do
it 'returns a fallback message if database is readonly' do it 'returns a fallback message if database is readonly' do
expect(Gitlab::Database).to receive(:read_only?) { true } expect(Gitlab::Database.main).to receive(:read_only?) { true }
expect(helper.read_only_message).to match('You are on a read-only GitLab instance') expect(helper.read_only_message).to match('You are on a read-only GitLab instance')
end end
...@@ -38,7 +38,7 @@ RSpec.describe ApplicationHelper do ...@@ -38,7 +38,7 @@ RSpec.describe ApplicationHelper do
context 'when database is read-only' do context 'when database is read-only' do
it 'stacks read-only and maintenance mode messages' do it 'stacks read-only and maintenance mode messages' do
expect(Gitlab::Database).to receive(:read_only?).twice { true } expect(Gitlab::Database.main).to receive(:read_only?).twice { true }
expect(helper.read_only_message).to match('You are on a read-only GitLab instance') expect(helper.read_only_message).to match('You are on a read-only GitLab instance')
expect(helper.read_only_message).to match(/#{default_maintenance_mode_message}/) expect(helper.read_only_message).to match(/#{default_maintenance_mode_message}/)
......
...@@ -49,7 +49,7 @@ RSpec.describe Gitlab::BackgroundMigration::PruneOrphanedGeoEvents, geo: false, ...@@ -49,7 +49,7 @@ RSpec.describe Gitlab::BackgroundMigration::PruneOrphanedGeoEvents, geo: false,
end end
it 'does nothing if the database is read-only' do it 'does nothing if the database is read-only' do
allow(Gitlab::Database).to receive(:read_only?).and_return(true) allow(Gitlab::Database.main).to receive(:read_only?).and_return(true)
expect { background_migration.perform(event_table_name) }.not_to change { Geo::RepositoryUpdatedEvent.count } expect { background_migration.perform(event_table_name) }.not_to change { Geo::RepositoryUpdatedEvent.count }
end end
......
...@@ -51,7 +51,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do ...@@ -51,7 +51,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do
context 'on a read-only instance' do context 'on a read-only instance' do
before do before do
allow(Gitlab::Database).to receive(:read_only?).and_return(true) allow(Gitlab::Database.main).to receive(:read_only?).and_return(true)
end end
it 'does not block user in GitLab' do it 'does not block user in GitLab' do
...@@ -76,7 +76,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do ...@@ -76,7 +76,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do
context 'on a read-only instance' do context 'on a read-only instance' do
before do before do
allow(Gitlab::Database).to receive(:read_only?).and_return(true) allow(Gitlab::Database.main).to receive(:read_only?).and_return(true)
end end
it 'does not unblock user in GitLab' do it 'does not unblock user in GitLab' do
...@@ -102,7 +102,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do ...@@ -102,7 +102,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do
context 'on a read-only instance' do context 'on a read-only instance' do
before do before do
allow(Gitlab::Database).to receive(:read_only?).and_return(true) allow(Gitlab::Database.main).to receive(:read_only?).and_return(true)
end end
it 'does not block user in GitLab' do it 'does not block user in GitLab' do
...@@ -145,7 +145,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do ...@@ -145,7 +145,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do
end end
it 'does not update the email when in a read-only GitLab instance' do it 'does not update the email when in a read-only GitLab instance' do
allow(Gitlab::Database).to receive(:read_only?).and_return(true) allow(Gitlab::Database.main).to receive(:read_only?).and_return(true)
expect { access.update_user }.not_to change(user, :email) expect { access.update_user }.not_to change(user, :email)
end end
...@@ -181,7 +181,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do ...@@ -181,7 +181,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do
end end
it 'does not update the name when in a read-only GitLab instance' do it 'does not update the name when in a read-only GitLab instance' do
allow(Gitlab::Database).to receive(:read_only?).and_return(true) allow(Gitlab::Database.main).to receive(:read_only?).and_return(true)
expect { access.update_user }.not_to change(user, :name) expect { access.update_user }.not_to change(user, :name)
end end
...@@ -202,7 +202,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do ...@@ -202,7 +202,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do
end end
it 'does not update the name when in a read-only GitLab instance' do it 'does not update the name when in a read-only GitLab instance' do
allow(Gitlab::Database).to receive(:read_only?).and_return(true) allow(Gitlab::Database.main).to receive(:read_only?).and_return(true)
expect { access.update_user }.not_to change(user, :name) expect { access.update_user }.not_to change(user, :name)
end end
...@@ -240,7 +240,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do ...@@ -240,7 +240,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do
end end
it "doesn't trigger a sync when in a read-only GitLab instance" do it "doesn't trigger a sync when in a read-only GitLab instance" do
allow(Gitlab::Database).to receive(:read_only?).and_return(true) allow(Gitlab::Database.main).to receive(:read_only?).and_return(true)
create(:ldap_group_link, cn: 'Group1', provider: provider) create(:ldap_group_link, cn: 'Group1', provider: provider)
create(:ldap_group_link, cn: 'Group2', provider: provider) create(:ldap_group_link, cn: 'Group2', provider: provider)
...@@ -313,7 +313,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do ...@@ -313,7 +313,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do
end end
it 'does not add a SSH key when in a read-only GitLab instance' do it 'does not add a SSH key when in a read-only GitLab instance' do
allow(Gitlab::Database).to receive(:read_only?).and_return(true) allow(Gitlab::Database.main).to receive(:read_only?).and_return(true)
stub_ldap_person_find_by_dn(entry, provider) stub_ldap_person_find_by_dn(entry, provider)
expect { access.update_user }.not_to change(user.keys, :count) expect { access.update_user }.not_to change(user.keys, :count)
...@@ -377,7 +377,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do ...@@ -377,7 +377,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do
end end
it 'does not add a Kerberos identity when in a read-only GitLab instance' do it 'does not add a Kerberos identity when in a read-only GitLab instance' do
allow(Gitlab::Database).to receive(:read_only?).and_return(true) allow(Gitlab::Database.main).to receive(:read_only?).and_return(true)
allow_any_instance_of(EE::Gitlab::Auth::Ldap::Person).to receive_messages(kerberos_principal: 'mylogin@FOO.COM') allow_any_instance_of(EE::Gitlab::Auth::Ldap::Person).to receive_messages(kerberos_principal: 'mylogin@FOO.COM')
expect { access.update_user }.not_to change(user.identities.where(provider: :kerberos), :count) expect { access.update_user }.not_to change(user.identities.where(provider: :kerberos), :count)
...@@ -398,7 +398,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do ...@@ -398,7 +398,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do
end end
it 'does not update the external UID when in a read-only GitLab instance' do it 'does not update the external UID when in a read-only GitLab instance' do
allow(Gitlab::Database).to receive(:read_only?).and_return(true) allow(Gitlab::Database.main).to receive(:read_only?).and_return(true)
access.update_user access.update_user
......
...@@ -37,7 +37,7 @@ RSpec.describe Gitlab::Geo::HealthCheck, :geo do ...@@ -37,7 +37,7 @@ RSpec.describe Gitlab::Geo::HealthCheck, :geo do
before do before do
allow(Gitlab::Geo).to receive(:secondary?) { true } allow(Gitlab::Geo).to receive(:secondary?) { true }
allow(Gitlab::Geo).to receive(:geo_database_configured?) { geo_database_configured } allow(Gitlab::Geo).to receive(:geo_database_configured?) { geo_database_configured }
allow(Gitlab::Database).to receive(:db_read_only?) { db_read_only } allow(Gitlab::Database.main).to receive(:db_read_only?) { db_read_only }
end end
context 'when the Geo tracking DB is not configured' do context 'when the Geo tracking DB is not configured' do
...@@ -124,8 +124,8 @@ RSpec.describe Gitlab::Geo::HealthCheck, :geo do ...@@ -124,8 +124,8 @@ RSpec.describe Gitlab::Geo::HealthCheck, :geo do
describe '#db_replication_lag_seconds' do describe '#db_replication_lag_seconds' do
before do before do
query = 'SELECT CASE WHEN pg_last_wal_receive_lsn() = pg_last_wal_replay_lsn() THEN 0 ELSE EXTRACT (EPOCH FROM now() - pg_last_xact_replay_timestamp())::INTEGER END AS replication_lag' query = 'SELECT CASE WHEN pg_last_wal_receive_lsn() = pg_last_wal_replay_lsn() THEN 0 ELSE EXTRACT (EPOCH FROM now() - pg_last_xact_replay_timestamp())::INTEGER END AS replication_lag'
allow(Gitlab::Database).to receive(:pg_last_wal_receive_lsn).and_return('pg_last_wal_receive_lsn') allow(Gitlab::Database.main).to receive(:pg_last_wal_receive_lsn).and_return('pg_last_wal_receive_lsn')
allow(Gitlab::Database).to receive(:pg_last_wal_replay_lsn).and_return('pg_last_wal_replay_lsn') allow(Gitlab::Database.main).to receive(:pg_last_wal_replay_lsn).and_return('pg_last_wal_replay_lsn')
allow(ActiveRecord::Base).to receive_message_chain('connection.execute').with(query).and_return([{ 'replication_lag' => lag_in_seconds }]) allow(ActiveRecord::Base).to receive_message_chain('connection.execute').with(query).and_return([{ 'replication_lag' => lag_in_seconds }])
end end
......
...@@ -32,7 +32,7 @@ RSpec.describe Gitlab::GitAccess do ...@@ -32,7 +32,7 @@ RSpec.describe Gitlab::GitAccess do
context "when in a read-only GitLab instance" do context "when in a read-only GitLab instance" do
before do before do
create(:protected_branch, name: 'feature', project: project) create(:protected_branch, name: 'feature', project: project)
allow(Gitlab::Database).to receive(:read_only?) { true } allow(Gitlab::Database.main).to receive(:read_only?) { true }
end end
let(:primary_repo_url) { geo_primary_http_url_to_repo(project) } let(:primary_repo_url) { geo_primary_http_url_to_repo(project) }
......
...@@ -40,7 +40,7 @@ RSpec.describe Gitlab::GitAccessWiki do ...@@ -40,7 +40,7 @@ RSpec.describe Gitlab::GitAccessWiki do
context 'when in a read-only GitLab instance' do context 'when in a read-only GitLab instance' do
before do before do
allow(Gitlab::Database).to receive(:read_only?) { true } allow(Gitlab::Database.main).to receive(:read_only?) { true }
end end
it 'does not give access to upload wiki code' do it 'does not give access to upload wiki code' do
...@@ -153,7 +153,7 @@ RSpec.describe Gitlab::GitAccessWiki do ...@@ -153,7 +153,7 @@ RSpec.describe Gitlab::GitAccessWiki do
before do before do
create(:protected_branch, name: 'feature', project: project) create(:protected_branch, name: 'feature', project: project)
allow(Gitlab::Database).to receive(:read_only?) { true } allow(Gitlab::Database.main).to receive(:read_only?) { true }
end end
let(:primary_repo_url) { geo_primary_http_url_to_repo(project.wiki) } let(:primary_repo_url) { geo_primary_http_url_to_repo(project.wiki) }
......
...@@ -121,7 +121,7 @@ RSpec.describe Namespace do ...@@ -121,7 +121,7 @@ RSpec.describe Namespace do
context 'when DB is read-only' do context 'when DB is read-only' do
before do before do
expect(Gitlab::Database).to receive(:read_only?) { true } expect(Gitlab::Database.main).to receive(:read_only?) { true }
end end
it 'returns free plan' do it 'returns free plan' do
......
...@@ -26,7 +26,7 @@ RSpec.describe NamespaceStatistics do ...@@ -26,7 +26,7 @@ RSpec.describe NamespaceStatistics do
context 'when database is read_only' do context 'when database is read_only' do
it 'does not save the object' do it 'does not save the object' do
allow(Gitlab::Database).to receive(:read_only?).and_return(true) allow(Gitlab::Database.main).to receive(:read_only?).and_return(true)
expect(statistics).not_to receive(:save!) expect(statistics).not_to receive(:save!)
......
...@@ -92,7 +92,7 @@ RSpec.describe AuditEventService, :request_store do ...@@ -92,7 +92,7 @@ RSpec.describe AuditEventService, :request_store do
context 'on a read-only instance' do context 'on a read-only instance' do
before do before do
allow(Gitlab::Database).to receive(:read_only?).and_return(true) allow(Gitlab::Database.main).to receive(:read_only?).and_return(true)
end end
it 'does not create an event' do it 'does not create an event' do
......
...@@ -7,7 +7,7 @@ RSpec.describe Keys::LastUsedService do ...@@ -7,7 +7,7 @@ RSpec.describe Keys::LastUsedService do
key = create(:key, last_used_at: 1.year.ago) key = create(:key, last_used_at: 1.year.ago)
original_time = key.last_used_at original_time = key.last_used_at
allow(::Gitlab::Database).to receive(:read_only?).and_return(true) allow(::Gitlab::Database.main).to receive(:read_only?).and_return(true)
described_class.new(key).execute described_class.new(key).execute
expect(key.reload.last_used_at).to be_like_time(original_time) expect(key.reload.last_used_at).to be_like_time(original_time)
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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