Commit 5fbebc21 authored by Yorick Peterse's avatar Yorick Peterse

Remove wrapper methods from Gitlab::Database

This module contained various methods that were forwarded to
Gitlab::Database::Connection. This commit removes these wrappers in
favour of using Gitlab::Database.main instead. This is done to make it
explicit what database connection should be used.

See https://gitlab.com/gitlab-org/gitlab/-/issues/331776 and
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/65262 for more
information.
parent a8da8da2
......@@ -71,7 +71,7 @@ class Admin::SessionsController < ApplicationController
::Users::ValidateOtpService.new(user).execute(user_params[:otp_attempt])
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])
end
......
......@@ -27,7 +27,7 @@ module Boards
list_service = Boards::Issues::ListService.new(board_parent, current_user, filter_params)
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)
end
......
......@@ -47,7 +47,7 @@ module AuthenticatesWithTwoFactorForAdminMode
# Remove any lingering user data from login
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
enable_admin_mode
......
......@@ -148,7 +148,7 @@ module IssuableActions
# on GET requests.
# 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
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)
else
notes_filter = current_user&.set_notes_filter(notes_filter_param, issuable) || notes_filter_param
......
......@@ -17,7 +17,7 @@ module RecordUserLastActivity
def set_user_last_activity
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
Users::ActivityService.new(current_user).execute
......
......@@ -41,7 +41,7 @@ module SortingPreference
sort_param = params[:sort]
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
user_preference.update(field => sort_param)
......
......@@ -77,7 +77,7 @@ module Repositories
def update_fetch_statistics
return unless project
return if Gitlab::Database.read_only?
return if Gitlab::Database.main.read_only?
return unless repo_type.project?
OnboardingProgressService.async(project.namespace_id).execute(action: :git_pull)
......
......@@ -126,7 +126,7 @@ module Repositories
# Overridden in EE
def batch_operation_disallowed?
upload_request? && Gitlab::Database.read_only?
upload_request? && Gitlab::Database.main.read_only?
end
# Overridden in EE
......
......@@ -29,7 +29,7 @@ module Mutations
end
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?
true
end
......
......@@ -344,7 +344,7 @@ module ApplicationHelper
# Overridden in EE
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.')
end
......
......@@ -219,11 +219,11 @@ module ApplicationSettingImplementation
end
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
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
def disabled_oauth_sign_in_sources=(sources)
......
......@@ -127,7 +127,7 @@ module CascadingNamespaceSettingAttribute
end
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
end
......
......@@ -34,7 +34,7 @@ module DeprecatedAssignee
end
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)
end
......@@ -43,7 +43,7 @@ module DeprecatedAssignee
end
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)
end
......@@ -56,7 +56,7 @@ module DeprecatedAssignee
# This will make the background migration process quicker (#26496) as it'll have less
# assignee_id rows to look through.
def nullify_deprecated_assignee
return unless persisted? && Gitlab::Database.read_only?
return unless persisted? && Gitlab::Database.main.read_only?
update_column(:assignee_id, nil)
end
......
......@@ -39,7 +39,7 @@ module Sha256Attribute
end
def database_exists?
Gitlab::Database.exists?
Gitlab::Database.main.exists?
end
end
end
......@@ -32,7 +32,7 @@ module ShaAttribute
end
def database_exists?
Gitlab::Database.exists?
Gitlab::Database.main.exists?
end
end
end
......
......@@ -41,7 +41,7 @@ module TokenAuthenticatableStrategies
# Resets the token, but only saves when the database is in read & write mode
def reset_token!(instance)
write_new_token(instance)
instance.save! if Gitlab::Database.read_write?
instance.save! if Gitlab::Database.main.read_write?
end
def self.fabricate(model, field, options)
......
......@@ -39,7 +39,7 @@ module X509SerialNumberAttribute
end
def database_exists?
Gitlab::Database.exists?
Gitlab::Database.main.exists?
end
end
end
......@@ -289,7 +289,7 @@ class Deployment < ApplicationRecord
"#{id} as deployment_id",
"#{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.
#
# We also ignore any duplicates so this method can be called multiple times
......
......@@ -88,7 +88,7 @@ module DesignManagement
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.validate!
design_actions.each(&:performed)
......
......@@ -26,7 +26,7 @@ class MergeRequestContextCommit < ApplicationRecord
# create MergeRequestContextCommit by given commit sha and it's diff file record
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
def to_commit
......
......@@ -14,7 +14,7 @@ class MergeRequestContextCommitDiffFile < ApplicationRecord
# create MergeRequestContextCommitDiffFile by given diff file record(s)
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
def path
......
......@@ -515,7 +515,7 @@ class MergeRequestDiff < ApplicationRecord
transaction do
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!
end
......@@ -535,7 +535,7 @@ class MergeRequestDiff < ApplicationRecord
transaction do
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)
end
......@@ -595,7 +595,7 @@ class MergeRequestDiff < ApplicationRecord
rows = build_external_merge_request_diff_files(rows) if use_external_diff?
# 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
def build_external_diff_tempfile(rows)
......
......@@ -63,7 +63,7 @@ class MergeRequestDiffCommit < ApplicationRecord
)
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
def self.prepare_commits_for_bulk_insert(commits)
......
......@@ -2817,11 +2817,11 @@ class Project < ApplicationRecord
end
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
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
def active_runners_with_tags
......
......@@ -38,7 +38,7 @@ class ProjectStatistics < ApplicationRecord
end
def refresh!(only: [])
return if Gitlab::Database.read_only?
return if Gitlab::Database.main.read_only?
COLUMNS_TO_REFRESH.each do |column, generator|
if only.empty? || only.include?(column)
......
......@@ -34,7 +34,7 @@ class SnippetStatistics < ApplicationRecord
end
def refresh!
return if Gitlab::Database.read_only?
return if Gitlab::Database.main.read_only?
update_commit_count
update_repository_size
......
......@@ -80,7 +80,7 @@ class User < ApplicationRecord
# to limit database writes to at most once every hour
# rubocop: disable CodeReuse/ServiceClass
def update_tracked_fields!(request)
return if Gitlab::Database.read_only?
return if Gitlab::Database.main.read_only?
update_tracked_fields(request)
......@@ -363,7 +363,7 @@ class User < ApplicationRecord
end
before_transition do
!Gitlab::Database.read_only?
!Gitlab::Database.main.read_only?
end
# rubocop: disable CodeReuse/ServiceClass
......@@ -848,11 +848,11 @@ class User < ApplicationRecord
end
def remember_me!
super if ::Gitlab::Database.read_write?
super if ::Gitlab::Database.main.read_write?
end
def forget_me!
super if ::Gitlab::Database.read_write?
super if ::Gitlab::Database.main.read_write?
end
def disable_two_factor!
......@@ -1750,7 +1750,7 @@ class User < ApplicationRecord
#
# rubocop: disable CodeReuse/ServiceClass
def increment_failed_attempts!
return if ::Gitlab::Database.read_only?
return if ::Gitlab::Database.main.read_only?
increment_failed_attempts
......@@ -1994,7 +1994,7 @@ class User < ApplicationRecord
def consume_otp!
if 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
false
......
......@@ -111,7 +111,7 @@ class AuditEventService
end
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))
save_or_track event
......@@ -120,7 +120,7 @@ class AuditEventService
end
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)
save_or_track event
......
......@@ -4,7 +4,7 @@ module Boards
module Visits
class CreateService < Boards::BaseService
def execute(board)
return unless current_user && Gitlab::Database.read_write?
return unless current_user && Gitlab::Database.main.read_write?
return unless board
model.visited!(current_user, board)
......
......@@ -181,12 +181,12 @@ module DesignManagement
)
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.
# When this is fixed, we can remove the call to
# `with_project_iid_supply` above, since the objects will be instantiated
# 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,
new_rows,
return_ids: true
......@@ -207,9 +207,9 @@ module DesignManagement
)
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.
::Gitlab::Database.bulk_insert( # rubocop:disable Gitlab/BulkInsert
::Gitlab::Database.main.bulk_insert( # rubocop:disable Gitlab/BulkInsert
DesignManagement::Version.table_name,
new_rows,
return_ids: true
......@@ -239,7 +239,7 @@ module DesignManagement
end
# 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,
new_rows
)
......@@ -278,7 +278,7 @@ module DesignManagement
# We cannot use `BulkInsertSafe` due to the LfsObjectsProject#update_project_statistics
# 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,
new_rows,
on_conflict: :do_nothing # Upsert
......
......@@ -99,7 +99,7 @@ module Issuable
yield(event)
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
......
......@@ -18,7 +18,7 @@ module Keys
end
def update?
return false if ::Gitlab::Database.read_only?
return false if ::Gitlab::Database.main.read_only?
last_used = key.last_used_at
......
......@@ -166,7 +166,7 @@ module MergeRequests
strong_memoize(:service_error) do
if !merge_request
ServiceResponse.error(message: 'Invalid argument')
elsif Gitlab::Database.read_only?
elsif Gitlab::Database.main.read_only?
ServiceResponse.error(message: 'Unsupported operation')
end
end
......
......@@ -76,7 +76,7 @@ module Packages
end
def database
::Gitlab::Database
::Gitlab::Database.main
end
end
end
......@@ -11,7 +11,7 @@ module Packages
::Gitlab::UsageDataCounters::PackageEventCounter.count(event_name)
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!(
event_type: event_name,
originator: current_user&.id,
......
......@@ -41,7 +41,7 @@ module Packages
}
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
def raw_dependency_for(dependency)
......
......@@ -15,7 +15,7 @@ module Packages
tags_to_create = @tags - existing_tags
@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
private
......
......@@ -18,7 +18,7 @@ module PersonalAccessTokens
private
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
......
......@@ -21,7 +21,7 @@ module Projects
.update_all(share: update[:share])
end
Gitlab::Database.bulk_insert( # rubocop:disable Gitlab/BulkInsert
Gitlab::Database.main.bulk_insert( # rubocop:disable Gitlab/BulkInsert
RepositoryLanguage.table_name,
detection.insertions(matching_programming_languages)
)
......
......@@ -38,7 +38,7 @@ module Projects
rows = existent_lfs_objects
.not_linked_to_project(project)
.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
linked_existing_objects += existent_lfs_objects.map(&:oid)
......
......@@ -19,7 +19,7 @@ class Repositories::DestroyService < Repositories::BaseService
# never be triggered on a read-only instance.
#
# 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
else
container.run_after_commit do
......
......@@ -23,7 +23,7 @@ module ResourceEvents
label_hash.merge(label_id: label.id, action: ResourceLabelEvent.actions['remove'])
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
Gitlab::UsageDataCounters::IssueActivityUniqueCounter.track_issue_label_changed_action(author: user) if resource.is_a?(Issue)
......
......@@ -25,7 +25,7 @@ module Suggestions
end
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
Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter.track_add_suggestion_action(user: @note.author)
......
......@@ -23,7 +23,7 @@ module Users
private
def record_activity
return if Gitlab::Database.read_only?
return if Gitlab::Database.main.read_only?
today = Date.today
......
......@@ -152,9 +152,9 @@
%span.float-right
#{Rails::VERSION::STRING}
%p
= Gitlab::Database.human_adapter_name
= Gitlab::Database.main.human_adapter_name
%span.float-right
= Gitlab::Database.version
= Gitlab::Database.main.version
%p
= _('Redis')
%span.float-right
......
......@@ -124,7 +124,7 @@ module GitGarbageCollectMethods
def update_repository_statistics(resource)
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)
end
......
......@@ -54,7 +54,7 @@ module Gitlab
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
def assign_issue(project_id, issue_id, assignee_ids)
......@@ -62,7 +62,7 @@ module Gitlab
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
def build_label_attrs(issue_id, label_id)
......
......@@ -11,7 +11,7 @@ class PagesDomainVerificationCronWorker # rubocop:disable Scalability/Idempotent
feature_category :pages
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|
with_context(project: domain.project) do
......
......@@ -12,7 +12,7 @@ class PagesDomainVerificationWorker # rubocop:disable Scalability/IdempotentWork
# rubocop: disable CodeReuse/ActiveRecord
def perform(domain_id)
return if Gitlab::Database.read_only?
return if Gitlab::Database.main.read_only?
domain = PagesDomain.find_by(id: domain_id)
......
......@@ -44,7 +44,7 @@ class ProjectCacheWorker
# statistics to become accurate if they were already updated once in the
# last 15 minutes.
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)
Projects::UpdateStatisticsService.new(project, nil, statistics: statistics).execute
......
......@@ -23,7 +23,7 @@ module Projects
end
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!
rescue StandardError => err
......
......@@ -13,7 +13,7 @@ class ScheduleMergeRequestCleanupRefsWorker
idempotent!
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)
MergeRequestCleanupRefsWorker.perform_with_capacity
......
......@@ -32,7 +32,7 @@
### Performance (1 change)
- Memoize Gitlab::Database.version.
- Memoize Gitlab::Database.main.version.
## 10.8.2 (2018-05-28)
......
......@@ -2006,7 +2006,7 @@
- Don't delete assigned MRs/issues when user is deleted.
- Remove new branch button for confidential issues.
- 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.
- Ignore encrypted attributes in Import/Export.
- Change rspec test to guarantee window is resized before visiting page.
......
# frozen_string_literal: true
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
......@@ -14,7 +14,7 @@ end
if defined?(ActiveRecord::Base)
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"
# as there's no need for the master process to hold a connection
......
......@@ -10,8 +10,8 @@ if Gitlab::Runtime.console?
puts " GitLab:".ljust(justify) + "#{Gitlab::VERSION} (#{Gitlab.revision}) #{Gitlab.ee? ? 'EE' : 'FOSS'}"
puts " GitLab Shell:".ljust(justify) + "#{Gitlab::VersionInfo.parse(Gitlab::Shell.version)}"
if Gitlab::Database.exists?
puts " #{Gitlab::Database.human_adapter_name}:".ljust(justify) + Gitlab::Database.version
if Gitlab::Database.main.exists?
puts " #{Gitlab::Database.main.human_adapter_name}:".ljust(justify) + Gitlab::Database.main.version
Gitlab.ee do
if Gitlab::Geo.connected? && Gitlab::Geo.enabled?
......
......@@ -20,16 +20,16 @@ Gitlab.ee do
end
end
db_config = Gitlab::Database.config ||
db_config = Gitlab::Database.main.config ||
Rails.application.config.database_configuration[Rails.env]
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
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)
end
end
......@@ -4,6 +4,6 @@
# `Shard.connected?` could be cached and return true even though the table doesn't exist
return unless Shard.connected?
return unless ActiveRecord::Migrator.current_version >= 20190402150158
return if Gitlab::Database.read_only?
return if Gitlab::Database.main.read_only?
Shard.populate!
......@@ -20,7 +20,7 @@ module Sidekiq
module NoEnqueueingFromTransactions
%i(perform_async perform_at perform_in).each do |name|
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
raise Sidekiq::Worker::EnqueueFromTransactionError, <<~MSG
`#{self}.#{name}` cannot be called inside a transaction as this can lead to
......
# frozen_string_literal: true
if Gitlab::Database::LoadBalancing.enable?
Gitlab::Database.disable_prepared_statements
Gitlab::Database.main.disable_prepared_statements
Gitlab::Application.configure do |config|
config.middleware.use(Gitlab::Database::LoadBalancing::RackMiddleware)
......
......@@ -20,7 +20,7 @@ class MigrateSamlIdentitiesToScimIdentities < ActiveRecord::Migration[6.0]
record.attributes.extract!("extern_uid", "user_id", "group_id", "active", "created_at", "updated_at")
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
......
......@@ -445,7 +445,7 @@ module EE
override :perform
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)
table_name = next_table(table_name) if deleted_rows.zero?
......
......@@ -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)
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.
When some write actions are not allowed because the node is a
**secondary**, consider adding the `Gitlab::Database.read_only?` or
`Gitlab::Database.read_write?` guard, instead of `Gitlab::Geo.secondary?`.
**secondary**, consider adding the `Gitlab::Database.main.read_only?` or
`Gitlab::Database.main.read_write?` guard, instead of `Gitlab::Geo.secondary?`.
The database itself will already be read-only in a replicated setup,
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
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=)
- [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.
- [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.
......
......@@ -12,13 +12,13 @@ necessary to add database (version) specific behavior.
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`.
This allows you to write code such as:
```ruby
if Gitlab::Database.version.to_f >= 11.7
if Gitlab::Database.main.version.to_f >= 11.7
run_really_fast_query
else
run_fast_query
......@@ -30,7 +30,7 @@ end
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
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.
We have a Rails Middleware that filters any potentially writing
......
......@@ -53,7 +53,7 @@ module Groups
if params[:state].present?
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
Epic.state_ids.key(preference.roadmap_epics_state)
......
......@@ -131,7 +131,7 @@ module EE
end
def show_ultimate_trial_suitable_env?
::Gitlab.com? && !::Gitlab::Database.read_only?
::Gitlab.com? && !::Gitlab::Database.main.read_only?
end
def token_expiration_enforced?
......
......@@ -413,19 +413,19 @@ module EE
end
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
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
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
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
def check_geo_node_allowed_ips
......
......@@ -454,7 +454,7 @@ module EE
def generate_subscription
return unless persisted?
return if ::Gitlab::Database.read_only?
return if ::Gitlab::Database.main.read_only?
create_gitlab_subscription(
plan_code: Plan::FREE,
......
......@@ -37,7 +37,7 @@ class ElasticsearchIndexedNamespace < ApplicationRecord
{ created_at: now, updated_at: now, namespace_id: id }
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!
jobs = batch_ids.map { |id| [id, :index] }
......
......@@ -19,7 +19,7 @@ class NamespaceStatistics < ApplicationRecord
COLUMNS_TO_REFRESH = [:wiki_size].freeze
def refresh!(only: [])
return if Gitlab::Database.read_only?
return if Gitlab::Database.main.read_only?
return unless group?
COLUMNS_TO_REFRESH.each do |column|
......
......@@ -18,7 +18,7 @@ module AuditEvents
return if collection.empty?
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)
end
......
......@@ -133,7 +133,7 @@ module EE
# @return [AuditEvent, nil] if record is persisted or nil if audit events
# features are not enabled
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!
......
......@@ -15,7 +15,7 @@ module Geo
end
def execute
return if Gitlab::Database.read_only?
return if Gitlab::Database.main.read_only?
try_obtain_lease do
log_info('Prune Geo Event Log entries up to id', geo_event_log_id: event_log_min_id)
......
......@@ -15,7 +15,7 @@ module Iterations
return ::ServiceResponse.error(message: _('Cadence is not automated'), http_status: 422) unless cadence.can_be_automated?
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)
......
......@@ -20,8 +20,8 @@ module Iterations
ApplicationRecord.transaction do
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.bulk_insert(ResourceIterationEvent.table_name, add_iteration_events) # rubocop:disable Gitlab/BulkInsert
Gitlab::Database.main.bulk_insert(ResourceIterationEvent.table_name, remove_iteration_events) # rubocop:disable Gitlab/BulkInsert
Gitlab::Database.main.bulk_insert(ResourceIterationEvent.table_name, add_iteration_events) # rubocop:disable Gitlab/BulkInsert
end
end
......
......@@ -10,7 +10,7 @@ module ResourceEvents
end
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
Gitlab::UsageDataCounters::IssueActivityUniqueCounter.track_issue_weight_changed_action(author: user)
......
......@@ -46,7 +46,7 @@ module EE
end
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
......@@ -17,7 +17,7 @@ module Geo
tags :exclude_from_gitlab_com
def perform
return if Gitlab::Database.read_only?
return if Gitlab::Database.main.read_only?
return unless Gitlab::Database.main.healthy?
unless ::GeoNode.secondary_nodes.any?
......
......@@ -18,7 +18,7 @@ class ProjectImportScheduleWorker
tags :needs_own_queue
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)
raise ImportStateNotFound unless project&.import_state
......
......@@ -15,7 +15,7 @@ class UpdateAllMirrorsWorker # rubocop:disable Scalability/IdempotentWorker
RESCHEDULE_WAIT = 1.second
def perform
return if Gitlab::Database.read_only?
return if Gitlab::Database.main.read_only?
scheduled = 0
with_lease do
......
......@@ -13,7 +13,7 @@ class UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker # rubocop:disable Scalab
# rubocop: disable CodeReuse/ActiveRecord
def perform
return if ::Gitlab::Database.read_only?
return if ::Gitlab::Database.main.read_only?
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|
......
......@@ -10,7 +10,7 @@ module EE
override :update_user
def update_user
return if ::Gitlab::Database.read_only?
return if ::Gitlab::Database.main.read_only?
update_user_attributes
update_memberships
......
......@@ -49,7 +49,7 @@ module EE
}
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
......
......@@ -61,7 +61,7 @@ module EE
override :perform
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)
table_name = next_table(table_name) if deleted_rows == 0
......
......@@ -25,7 +25,7 @@ module EE
end
def geo_custom_action?
return unless ::Gitlab::Database.read_only?
return unless ::Gitlab::Database.main.read_only?
return unless ::Gitlab::Geo.secondary_with_primary?
receive_pack? || upload_pack_and_not_replicated?
......@@ -55,7 +55,7 @@ module EE
end
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"
end
......
......@@ -14,7 +14,7 @@ module EE
# This method can be called/loaded before the database
# has been created. With this guard clause we prevent querying
# 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)
[::Gitlab::ImportSources::ImportSource.new('gitlab_custom_project_template',
......
......@@ -66,7 +66,7 @@ module EE
action = route_hash[:action]
if ALLOWLISTED_GEO_ROUTES[controller]&.include?(action)
::Gitlab::Database.db_read_write?
::Gitlab::Database.main.db_read_write?
else
ALLOWLISTED_GEO_ROUTES_TRACKING_DB[controller]&.include?(action)
end
......
......@@ -9,7 +9,7 @@ module Gitlab
return '' unless Gitlab::Geo.secondary?
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 '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 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
context 'when not in a Geo secondary' 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')
end
......@@ -38,7 +38,7 @@ RSpec.describe ApplicationHelper do
context 'when database is read-only' 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(/#{default_maintenance_mode_message}/)
......
......@@ -49,7 +49,7 @@ RSpec.describe Gitlab::BackgroundMigration::PruneOrphanedGeoEvents, geo: false,
end
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 }
end
......
......@@ -51,7 +51,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do
context 'on a read-only instance' 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
it 'does not block user in GitLab' do
......@@ -76,7 +76,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do
context 'on a read-only instance' 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
it 'does not unblock user in GitLab' do
......@@ -102,7 +102,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do
context 'on a read-only instance' 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
it 'does not block user in GitLab' do
......@@ -145,7 +145,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do
end
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)
end
......@@ -181,7 +181,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do
end
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)
end
......@@ -202,7 +202,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do
end
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)
end
......@@ -240,7 +240,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do
end
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: 'Group2', provider: provider)
......@@ -313,7 +313,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do
end
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)
expect { access.update_user }.not_to change(user.keys, :count)
......@@ -377,7 +377,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do
end
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')
expect { access.update_user }.not_to change(user.identities.where(provider: :kerberos), :count)
......@@ -398,7 +398,7 @@ RSpec.describe Gitlab::Auth::Ldap::Access do
end
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
......
......@@ -37,7 +37,7 @@ RSpec.describe Gitlab::Geo::HealthCheck, :geo do
before do
allow(Gitlab::Geo).to receive(:secondary?) { true }
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
context 'when the Geo tracking DB is not configured' do
......@@ -124,8 +124,8 @@ RSpec.describe Gitlab::Geo::HealthCheck, :geo do
describe '#db_replication_lag_seconds' 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'
allow(Gitlab::Database).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_receive_lsn).and_return('pg_last_wal_receive_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 }])
end
......
......@@ -32,7 +32,7 @@ RSpec.describe Gitlab::GitAccess do
context "when in a read-only GitLab instance" do
before do
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
let(:primary_repo_url) { geo_primary_http_url_to_repo(project) }
......
......@@ -40,7 +40,7 @@ RSpec.describe Gitlab::GitAccessWiki do
context 'when in a read-only GitLab instance' do
before do
allow(Gitlab::Database).to receive(:read_only?) { true }
allow(Gitlab::Database.main).to receive(:read_only?) { true }
end
it 'does not give access to upload wiki code' do
......@@ -153,7 +153,7 @@ RSpec.describe Gitlab::GitAccessWiki do
before do
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
let(:primary_repo_url) { geo_primary_http_url_to_repo(project.wiki) }
......
......@@ -121,7 +121,7 @@ RSpec.describe Namespace do
context 'when DB is read-only' do
before do
expect(Gitlab::Database).to receive(:read_only?) { true }
expect(Gitlab::Database.main).to receive(:read_only?) { true }
end
it 'returns free plan' do
......
......@@ -26,7 +26,7 @@ RSpec.describe NamespaceStatistics do
context 'when database is read_only' 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!)
......
......@@ -92,7 +92,7 @@ RSpec.describe AuditEventService, :request_store do
context 'on a read-only instance' 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
it 'does not create an event' do
......
......@@ -7,7 +7,7 @@ RSpec.describe Keys::LastUsedService do
key = create(:key, last_used_at: 1.year.ago)
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
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