Commit 6b02a494 authored by Thong Kuah's avatar Thong Kuah

Merge branch 'backport-database-tasks' into 'master'

Backport `database_tasks:` from Rails 7.x

See merge request gitlab-org/gitlab!82902
parents f0af40a8 dee10e18
......@@ -11,6 +11,8 @@ require File.expand_path('config/application', __dir__)
relative_url_conf = File.expand_path('config/initializers/relative_url', __dir__)
require relative_url_conf if File.exist?("#{relative_url_conf}.rb")
require File.expand_path('config/initializers/01_active_record_database_tasks_configuration_flag.rb', __dir__)
Gitlab::Application.load_tasks
Knapsack.load_tasks if defined?(Knapsack)
# frozen_string_literal: true
if Rails::VERSION::MAJOR >= 7
raise "Remove `#{__FILE__}`. This is backport of `database_tasks:` Rails 7.x feature."
end
# This backports `database_tasks:` feature to skip running migrations for some databases
# PR: https://github.com/rails/rails/pull/42794/files
module DatabaseTasks
module ActiveRecordDatabaseConfigurations
def configs_for(env_name: nil, name: nil, include_replicas: false)
configs = super
unless include_replicas
if name
configs = nil unless configs&.database_tasks?
else
configs = configs.select do |db_config|
db_config.database_tasks?
end
end
end
configs
end
end
module ActiveRecordDatabaseConfigurationsHashConfig
def database_tasks? # :nodoc:
!replica? && !!configuration_hash.fetch(:database_tasks, true)
end
end
end
ActiveRecord::DatabaseConfigurations.prepend(DatabaseTasks::ActiveRecordDatabaseConfigurations)
ActiveRecord::DatabaseConfigurations::HashConfig.prepend(DatabaseTasks::ActiveRecordDatabaseConfigurationsHashConfig)
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