Project

General

Profile

Feature #36933 » 0001-In-production-mode-check-for-pending-migration-on-bo.patch

Marius BĂLTEANU, 2025-09-07 11:32

View differences:

config/additional_environment.rb.example
# # set up external systems like Sidekiq and Redis.
# config.active_job.queue_adapter = :inline
#
# Halt boot if there are pending migrations
# config.redmine_halt_on_pending_migrations = true
# ...
#
config/application.rb
:same_site => :lax
)
# Configure redmine_halt_on_pending_migrations only for production so that additional environment file
# can change it (environments/ENV.rb would take precedence over it)
config.redmine_halt_on_pending_migrations = false if Rails.env.production?
if File.exist?(File.join(File.dirname(__FILE__), 'additional_environment.rb'))
instance_eval File.read(File.join(File.dirname(__FILE__), 'additional_environment.rb'))
end
config/initializers/05-check_pending_migrations.rb
if Rails.env.production? && (defined?(Rails::Server) || defined?(Rails::Console))
begin
ActiveRecord::Migration.check_all_pending!
rescue ActiveRecord::PendingMigrationError
if Rails.configuration.redmine_halt_on_pending_migrations
error_message = "\e[31m[HALT] Pending migrations found. Boot process is stopping.\e[0m"
puts "\n#{'=' * 60}\n"
puts error_message
puts "Please run `bundle exec rake db:migrate` to apply migrations."
puts "#{'=' * 60}\n\n"
# Abort the process with a non-zero exit code to indicate failure.
abort
else
warning_message = "\e[33m[WARNING] You have pending migrations. Run `bundle exec rake db:migrate` to apply them.\e[0m"
puts "\n#{'=' * 60}\n"
puts warning_message
puts "#{'=' * 60}\n\n"
end
end
end
(2-2/2)