I have two apps on Heroku and I would like them to use the same dedicated database. The problem is that this new app has the same models/tables than the other one.
My questions are:
-
Should I change the name for the tables on the new app?
-
If yes, what about the name of my models? Is it possible to map a model with a table with a different name? (Like
Usermodel withnew_usertable instead ofuser).
Any good advices on how to do this will be appreciated.
Thanks!
In general this is probably not as good an idea as it may seem. Rails is designed to assume it has 100% control over the database.
Even if you are able to get your tables separated and not colliding, you will still have challenges with the
schema_migrationstable. That table holds all the migrations for rails and would contain a mix of all migration records for both applications. This would confuse the apps whenever, for example, you tried to runrake db:rollbackor other rake commands.There could also be issues with having your
schema.rbfile potentially get out of synch between the two applications.I’d recommend looking hard at the reasons you want to share the database and see if there are other ways to accomplish what you are trying to do. For example, you might consider using Active Resources to connect the applications restfully.