Dynamic database config based on url - possible?

Hi there, I am dealing with a legacy database.
We have 3 separate MySQL databases with identicle structure.
We have one Rails Instance.

based on the url:

domain.com/one
domain.com/two
domain.com/three

i need to use database one, two, or three respectivly.

All the app files are identicle the only reason the databases are split
is because the CMS had no way to separate the content between sites so
they just used different databases. The database scema are rails
friendly so i am using AR associations.

My thought was to have a parent class (DbSwitch) that took an
initialization parameter(site) and picked a db_config but I don’t think
that will work for the find statments as i will have to pass an
initialization param in the find. Item.new(“one”) is fine but how do
i add the “one” to the item.find(:all) ?

My other thought was to set an environment var per-user depending on the
url and then just leave the app alone. Is that possible?

Any sugestions would be greatly appriciated…

Dinshaw G. wrote:

Hi there, I am dealing with a legacy database.
We have 3 separate MySQL databases with identicle structure.
We have one Rails Instance.

based on the url:

domain.com/one
domain.com/two
domain.com/three

i need to use database one, two, or three respectivly.

If at all possible it would seem a much more maintainable solution to
run 3 rails intances, one for each cms.

If at all possible it would seem a much more maintainable solution to
run 3 rails intances, one for each cms.

Thanks Michael. The other thought i had was if i could somehow read the
request var inside the database.yml and do a switch. Does anyone knnow
if there is a way to make evenironment vars available in database.yml?