This project is archived and is in readonly mode.

#5313 open
Russell Quinn

Rake tasks db:create and db:drop are not consistent in behaviour

Reported by Russell Quinn | August 6th, 2010 @ 08:56 AM

db:drop drops the database for the current RAILS_ENV or development if not defined.

db:create creates the database for the current RAILS_ENV, but if this is set to development then it also creates the test database if this is configured.

This behaviour is hidden (the Rake task description doesn't mention it) and it makes doing a rake db:drop followed by a rake db:create complain about the test database already existing.

For example, the following happens if RAILS_ENV=development or there is no RAILS_ENV defined (hence defaulting to development):

$ rake db:drop
$ rake db:create
database_test already exists

Maybe rake db:drop should also drop the test database? But this also leads to sneaky functionality. My vote is that the two tasks simply do exactly what they state. rake db:create:all and rake db:drop:all can typically be used to create and drop development and test databases as the commands only operate on local databases and production is usually remote.

Patch attached to update the rake task and only mention of this behaviour (in a guide.)

Russell.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>