mirror of
https://github.com/postalserver/postal.git
synced 2026-12-05 15:55:50 +00:00
* chore(rails): Upgrade to Rails 8.1.4 * chore(rails): Upgrade to Rails 8.1.4 * chore(deps): upgrade rails to 8.1.4.1 Rails 8.1.4.1 is a security release for the 8.1 line. This also changes how Rails is constrained in the Gemfile. Previous upgrades have always pinned an exact version (e.g. "= 7.1.6"); this uses "~> 8.1.4", ">= 8.1.4.1" instead: - "~> 8.1.4" accepts any 8.1.x release from 8.1.4 onwards, but not 8.2. Later patch and security releases can be taken with `bundle update rails` without editing the Gemfile, while moving to a new minor version remains a deliberate change. - ">= 8.1.4.1" stops the constraint resolving to any version older than the fixes in this release. The installed version is still fixed by Gemfile.lock, so builds remain reproducible. The Gemfile now states which versions are acceptable rather than repeating what the lockfile already pins. --------- Co-authored-by: Richard Patching <richard@justaddpixels.com>
61 lines
1.6 KiB
Ruby
61 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# This initializer will wait for all pending migrations to be applied before
|
|
# continuing to start the application. This is useful when running the application
|
|
# in a cluster where migrations are run in a separate job which runs at the same
|
|
# time as the other processes.
|
|
|
|
class MigrationWaiter
|
|
|
|
ATTEMPTS = Postal::Config.migration_waiter.attempts
|
|
SLEEP_TIME = Postal::Config.migration_waiter.sleep_time
|
|
|
|
class << self
|
|
|
|
def wait
|
|
attempts_remaining = ATTEMPTS
|
|
loop do
|
|
pending_migrations = ActiveRecord::Base.connection_pool.migration_context.open.pending_migrations.size
|
|
if pending_migrations.zero?
|
|
Postal.logger.info "no pending migrations, continuing"
|
|
return
|
|
end
|
|
|
|
attempts_remaining -= 1
|
|
|
|
if attempts_remaining.zero?
|
|
Postal.logger.info "#{pending_migrations} migration(s) are still pending after #{ATTEMPTS} attempts, exiting"
|
|
Process.exit(1)
|
|
else
|
|
Postal.logger.info "waiting for #{pending_migrations} migration(s) to be applied (#{attempts_remaining} remaining)"
|
|
sleep SLEEP_TIME
|
|
end
|
|
end
|
|
end
|
|
|
|
def wait_if_appropriate
|
|
# Don't wait if not configured
|
|
return unless Postal::Config.migration_waiter.enabled?
|
|
|
|
# Don't wait in the console, rake tasks or rails commands
|
|
return if console? || rake_task? || rails_command?
|
|
|
|
wait
|
|
end
|
|
|
|
def console?
|
|
Rails.const_defined?("Console")
|
|
end
|
|
|
|
def rake_task?
|
|
Rake.application.top_level_tasks.any?
|
|
end
|
|
|
|
def rails_command?
|
|
caller.any? { |c| c =~ /rails\/commands/ }
|
|
end
|
|
|
|
end
|
|
|
|
end
|