class OkComputer::ActiveRecordMigrationsCheck

Public Instance Methods

check() click to toggle source

Public: Check if migrations are pending or not

# File lib/ok_computer/built_in_checks/active_record_migrations_check.rb, line 4
def check
  return unsupported unless supported?

  if needs_migration?
    mark_failure
    mark_message "Pending migrations"
  else
    mark_message "NO pending migrations"
  end
end
needs_migration?() click to toggle source
# File lib/ok_computer/built_in_checks/active_record_migrations_check.rb, line 15
def needs_migration?
  if ActiveRecord::Migrator.respond_to?(:needs_migration?) # Rails <= 5.1
    ActiveRecord::Migrator.needs_migration?
  else # Rails >= 5.2
    ActiveRecord::Base.connection.migration_context.needs_migration?
  end
end
supported?() click to toggle source
# File lib/ok_computer/built_in_checks/active_record_migrations_check.rb, line 23
def supported?
  ActiveRecord::Migrator.respond_to?(:needs_migration?) ||
    (ActiveRecord::Base.connection.respond_to?(:migration_context) &&
     ActiveRecord::Base.connection.migration_context.respond_to?(:needs_migration?))
end

Private Instance Methods

unsupported() click to toggle source

Private: Fail the check if ActiveRecord cannot check migration status

# File lib/ok_computer/built_in_checks/active_record_migrations_check.rb, line 32
def unsupported
  mark_failure
  mark_message "This version of ActiveRecord does not support checking whether migrations are pending"
end