When building a new Rails app, I’ve found that I constantly have had to drop the database, create it, run a migration and finally the seed.
This as you can tell can be very tedious. It got me thinking ‘What if there was a way to do all of that in one command’. Turns out there is, one way to do it is to create a rake task to run them one after the other.
You can name your task what ever you like:
With this all you have to do is run the following rake command:
NOTE: it goes without saying, NEVER use this in production!
And there you have it, a single rake task for both test and development which drops the database, recreates it again, runs a migration and finally the seeds. Be sure not to use this in production because it will drop any data you have in your database.