class ActiveRecord::Migration::CheckPending

This class is used to verify that all migrations have been run before loading a web page if config.active_record.migration_error is set to :page_load.

Public Class Methods

new(app, file_watcher: ActiveSupport::FileUpdateChecker) click to toggle source
# File lib/active_record/migration.rb, line 649
def initialize(app, file_watcher: ActiveSupport::FileUpdateChecker)
  @app = app
  @needs_check = true
  @mutex = Mutex.new
  @file_watcher = file_watcher
end

Public Instance Methods

call(env) click to toggle source
# File lib/active_record/migration.rb, line 656
def call(env)
  @mutex.synchronize do
    @watcher ||= build_watcher do
      @needs_check = true
      ActiveRecord::Migration.check_pending_migrations
      @needs_check = false
    end

    if @needs_check
      @watcher.execute
    else
      @watcher.execute_if_updated
    end
  end

  @app.call(env)
end

Private Instance Methods

build_watcher(&block) click to toggle source
# File lib/active_record/migration.rb, line 675
def build_watcher(&block)
  current_environment = ActiveRecord::ConnectionHandling::DEFAULT_ENV.call
  all_configs = ActiveRecord::Base.configurations.configs_for(env_name: current_environment)
  paths = all_configs.flat_map { |config| config.migrations_paths || Migrator.migrations_paths }.uniq
  @file_watcher.new([], paths.index_with(["rb"]), &block)
end