The file activerecord/lib/active_record/railties/databases.rake implements the various database rake tasks (such as db:create, db:structure:dump, etc.). However, it currently recognizes particular ActiveRecord connection adapters by name and hard-codes an implementation for each adapter. This means, if you write (or update) a third-party adapter, you must edit this central file in order to get the database rake tasks to work for your adapter.
This patch includes a mechanism to let ActiveRecord adapters provide their own implementation for the standard rake tasks. An adapter may optionally provide a Tasks object that provides implementations of any number of operations. This object must be distinct from the connection adapter itself because some tasks (such as database creation) cannot be run within the context of any one connection. The object, and any and all operations it provides, are all completely optional, so existing adapters will be fully backwards compatible.
This patch also demonstrates how the mechanism will work, by porting the db:charset task. Previously, databases.rake implemented this task using a case statement on the adapter name. Now, the implementations for the various supported adapters (mysql, Postgresql, and sqlite3) have been moved into the adapters themselves via the task mechanism, thus removing the adapter-specific code from databases.rake.
I haven't yet ported the rest of databases.rake because I wanted to get a sign-off on this mechanism before doing that work. If this patch is accepted, I'll go ahead and port the rest of databases.rake. I believe we can drastically reduce the size of databases.rake, and eliminate all the adapter-specific code therein. More importantly, this will allow third-party adapters to provide their own implementations of these tasks without touching the central repository.
Support adapter overrides of database rake tasks
Fix a method name
Let adapters implement db:create and db:dump
Please try to rebase your PR first. Then we can see if this looks good.
Thanks Arun. Sorry, I got really busy, but I will get to rebasing it this week.
Okay, I took a look at recent changes to master, and it looks like someone has put in an alternative solution. I believe it fulfills my use case (that of writing database tasks for new ActiveRecord adapters). Accordingly, I'm closing this pull request. I'll re-open a different pull request if it turns out I need something else.