Multiple databases - sites sharing same schema, code and webserver(webserver cluster)

I solved multiple databases issue in my own project, kind of CMS for
multiple sites each having its own db.

My solution works as usual if site (site URL) is
'localhost' or if db:migrate is called
If browsed to which is forwarded to the rails app then it
connects to prefix_example_com database
(where prefix_ can be configured or be empty string)
Added a new rake task db:migrate_all which would migrate all site
databases defined somewhere in sql
Each developer (rails application copy) can have it's own database
settings in config/dblogin.yml which shell not be under version

Code pasted at Paste: