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.
This commit is contained in:
parent
a8da8da202
commit
5fbebc2137
|
@ -71,7 +71,7 @@ def valid_otp_attempt?(user)
|
|||
::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 @@ def index
|
|||
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 @@ def admin_mode_authenticate_with_two_factor_via_otp(user)
|
|||
# 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 @@ def notes_filter
|
|||
# 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 @@ def set_sort_order_from_user_preference(field = sorting_field)
|
|||
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 @@ def render_503_with_exception(exception)
|
|||
|
||||
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 @@ def lfs_check_batch_operation!
|
|||
|
||||
# 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 @@ def errors_on_object(record)
|
|||
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 @@ def locale_path
|
|||
|
||||
# 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 @@ def human_attribute_name(attr, _options = {})
|
|||
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 @@ def define_lock_methods(attribute)
|
|||
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 @@ def assignee_id
|
|||
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 @@ def assignee_ids
|
|||
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 @@ def assignees
|
|||
# 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 @@ def validate_binary_column_exists!(name)
|
|||
end
|
||||
|
||||
def database_exists?
|
||||
Gitlab::Database.exists?
|
||||
Gitlab::Database.main.exists?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -32,7 +32,7 @@ def validate_binary_column_exists!(name)
|
|||
end
|
||||
|
||||
def database_exists?
|
||||
Gitlab::Database.exists?
|
||||
Gitlab::Database.main.exists?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -41,7 +41,7 @@ def ensure_token!(instance)
|
|||
# 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 @@ def validate_binary_column_exists!(name)
|
|||
end
|
||||
|
||||
def database_exists?
|
||||
Gitlab::Database.exists?
|
||||
Gitlab::Database.main.exists?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -289,7 +289,7 @@ def link_merge_requests(relation)
|
|||
"#{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 @@ def self.create_for_designs(design_actions, sha, author)
|
|||
|
||||
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 @@ def self.delete_bulk(merge_request, commits)
|
|||
|
||||
# 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 @@ def migrate_files_to_external_storage!
|
|||
|
||||
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 @@ def migrate_files_to_database!
|
|||
|
||||
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 @@ def create_merge_request_diff_files(rows)
|
|||
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 @@ def self.create_bulk(merge_request_diff_id, commits)
|
|||
)
|
||||
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 @@ def oids(objects, oids: [])
|
|||
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 @@ def total_repository_size
|
|||
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 @@ def update_file_count
|
|||
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 @@ def blocked?
|
|||
end
|
||||
|
||||
before_transition do
|
||||
!Gitlab::Database.read_only?
|
||||
!Gitlab::Database.main.read_only?
|
||||
end
|
||||
|
||||
# rubocop: disable CodeReuse/ServiceClass
|
||||
|
@ -848,11 +848,11 @@ def recently_sent_password_reset?
|
|||
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 @@ def invalidate_personal_projects_count
|
|||
#
|
||||
# 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 @@ def confirmation_period_valid?
|
|||
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 @@ def authentication_event?
|
|||
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 @@ def log_security_event_to_database
|
|||
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 @@ def copy_designs!
|
|||
)
|
||||
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 @@ def copy_versions!
|
|||
)
|
||||
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 @@ def copy_actions!(new_design_ids, new_version_ids)
|
|||
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 @@ def link_lfs_files!
|
|||
|
||||
# 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 @@ def copy_events(table_name, events_to_copy)
|
|||
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 @@ def execute
|
|||
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 @@ def service_error
|
|||
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 @@ def bulk_insert_package_dependency_links(type, dependency_ids)
|
|||
end
|
||||
|
||||
def database
|
||||
::Gitlab::Database
|
||||
::Gitlab::Database.main
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ def execute
|
|||
::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 @@ def create_dependency_link_metadata
|
|||
}
|
||||
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 @@ def execute
|
|||
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 @@ def execute
|
|||
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 @@ def execute
|
|||
.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 @@ def link_existing_lfs_objects(oids)
|
|||
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 @@ def execute
|
|||
# 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 @@ def execute(added_labels: [], removed_labels: [])
|
|||
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 @@ def execute
|
|||
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 @@ def execute
|
|||
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 @@ def flush_ref_caches(resource)
|
|||
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 @@ def label_issue(project_id, issue_id, label_ids)
|
|||
|
||||
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 @@ def assign_issue(project_id, issue_id, assignee_ids)
|
|||
|
||||
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 @@ def perform(project_id, files = [], statistics = [], refresh_statistics = true)
|
|||
# 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 @@ def before_gitaly_call(task, resource)
|
|||
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.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# 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 @@
|
|||
|
||||
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 @@
|
|||
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 @@ def log_pool_size(db, previous_pool_size, current_pool_size)
|
|||
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 ClassMethods
|
|||
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
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# 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 @@ def up
|
|||
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 @@ def epics_state_in_user_preference
|
|||
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 @@ def show_ultimate_trial?(user, callout = ULTIMATE_TRIAL)
|
|||
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 @@ def mirror_capacity_threshold_less_than
|
|||
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 @@ def find_or_create_subscription
|
|||
|
||||
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 @@ def self.index_first_n_namespaces_of_plan(plan, number_of_namespaces)
|
|||
{ 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 @@ def execute
|
|||
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 @@ def prepare_security_event
|
|||
# @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 @@ def initialize(event_log_min_id)
|
|||
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 @@ def execute
|
|||
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 @@ def execute
|
|||
|
||||
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 @@ def initialize(resource, user)
|
|||
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 @@ def replicate_snippet_changes(snippet)
|
|||
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 @@ class PruneEventLogWorker # rubocop:disable Scalability/IdempotentWorker
|
|||
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 Access
|
|||
|
||||
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 @@ def perform(start_id, stop_id)
|
|||
}
|
||||
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 @@ def vacuum!
|
|||
|
||||
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 @@ def geo_custom_action
|
|||
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 @@ def primary_ssh_url_to_repo
|
|||
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 @@ def ee_import_table
|
|||
# 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 @@ def geo_node_update_route?
|
|||
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 @@ def perform_checks
|
|||
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 @@
|
|||
|
||||
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 @@
|
|||
|
||||
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 @@
|
|||
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 @@
|
|||
|
||||
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 @@
|
|||
|
||||
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 @@
|
|||
|
||||
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 @@
|
|||
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 @@
|
|||
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 @@
|
|||
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 @@
|
|||
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 @@
|
|||
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 @@
|
|||
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 @@
|
|||
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 @@
|
|||
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 @@
|
|||
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 @@ def download_ability
|
|||
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 @@
|
|||
|
||||
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 @@
|
|||
|
||||
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 @@
|
|||
|
||||
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 @@
|
|||
|
||||
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 @@
|
|||
|
||||
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 @@
|
|||
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)
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue