rails/rails — pull request #10792 by schneems (2013-05-30 01:49:20+00:00)
Title: Do not hit database on empty migration check

Rails will perform a "pending migration" check on every page load in development starting in Rails 4.0. An exception will be raised if the current version of migrations stored in the database is not greater than or equal to the last version from the db/migrate folder. This check requires a database connection which may not exist.

The problem comes when someone creates a new application using a non sqlite database

```
$ rails new -d postgresql
```

If someone runs this then visits the server they will get an error because they likely have not created the database yet though our migration check is attempting to get the schema version from the database. This PR fixes that problem.

If there are no migrations in db/migration then there cannot be migrations pending, so a database connection is not needed. This PR checks to see if there are 0 migrations, and if so `needs_migration?` will return false instead of hitting the database to detect the current_version.

ATP Active Record