Skip to content

Rails DB Rake Tasks

metaskills edited this page Sep 13, 2010 · 17 revisions

As of 2.3.6 of the adapter, we compliant to the rake task interfaces in the :db namespace of rails. That means for new developers that are working with a non-legacy DB that is accurately reflected by schema.rb can now use the standard rake tasks for just about everything except actually setting up the new/test databases.

The only problem is that the we have not yet committed patches yet upstream to rails to remove Windows specific command interpolation from their databases.rake task. So, we have to do two things. First, here is an extension to Rake that allows us to method chain tasks.

Next, here are the overrides for each task in a default rails application. Some notes about them – first, we are not supporting any native SQL structure dump. No scptxfr or anything like that. Because we have a mixed dev community these are left blank. The override rake task finally allows you to build your own platform specific task now without rails core task blowing up on us. The main task is db:test:purge. We now use our own #recreate_database method which basically just removes all the tables prior to a schema load. If the database is not there and/or an exception is raised, it calls #recreate_database! with the database name from your configuration. The bang method will attempt to create your database. Hopefully the connection user has perms for this.