rails 3.1 db:test:prepare and "pending migrations" problem
Recent switch to Rails 3.1.0.rc4, and I'm having trouble getting our CI builds to run. It boils down to the following simplified case:
-bash-3.2$ echo $RAILS_ENV test -bash-3.2$ bundle exec rake db:drop db:create db:test:prepare You have 21 pending migrations: 20100628174219 InitialSchema 20100706175001 AddCompanyToClassifieds 20100720132917 CartItemActionMigration 20100811192506 AddJobTitleToDirect开发者_StackOverfloworyListings ...
If I replace that command with bundle exec rake db:drop db:create db:migrate db:test:prepare
it works fine.
In digging deeper the core db:test:prepare
task has db:abort_if_pending_migrations
as a pre-requisite.
Now am I just missing something obvious, or is that completely pointless? Running db:test:prepare
(in the standard case) calls db:schema:load
which executes schema.rb -- whose entire point is to load the schema without running all migrations. By failing to run unless all migrations have been executing (thus forcing a db:migrate
prior to db:test:prepare
), does it not make itself utterly useless?
I guess I can add the extra db:migrate
to my CI build process, but I'd like to know what I'm doing wrong.
I believe db:test:prepare
is not intended to run in the TEST environment (otherwise you could just run db:schema:load
yourself). Normally you would run db:test:prepare
in the development environment. The check for pending migrations is then quite useful (you will know if your coworkers committed some new migrations before you run and fail a bunch of tests). Since running the tests runs db:test:prepare
anyway, you should rarely need to run that by hand (certainly not for your CI builds). Omit the call to db:test:prepare
.
精彩评论