Question about migrating a site to Rails/Grails
I have a Grails/Rails question.
We have an app in Java and I was wondering if it could be written in Grails or Rails. (I am new to Grails and Rails so I hope these are not stupid questions.)
The issue is that we have multiple data sources. Our app uses a lot of databases.
Our users are divided into groups. We have one global database that holds info for the users, the groups, and some global info as well, and a database for each group. The database for each group contains the data for that group. There is one schema for the global database, and one for all the group databases.
When someone creates an account, entries are created in the global database for a new group and for the user. Then a new database in MySQL is created for that group. This is done via Java EE EntityManagers. There is one EntityManager for the global database. When a new group is created or when a user logs in, the Global EntityManager reads the info from the group table and creates an EntityManager and Connection objects for the group database, and these are stored in the user's session.
We have multiple databases running in one MySQL server. We are not storing some info in a MySQL database, and some in an Oracle database; this seems to be the most common scenario I see when I googled about dealing with multiple databases in Rails. I have done some Googling, and it looks like a lot of pages about dealing with multiple databases in Rails are for dealing with a unique schema in each database. We have two schemas, but one of them is used across a lot of databases. The connection info for each group database is in the global database. Only the info for the global database is in a file. Is adding more entries in database.yml the only way to use more databases?
I found this and I think this might be what I am loo开发者_JAVA百科king for: http://programmerassist.com/article/302
Any ideas?
Grails has a nice Datasources plugin but that is designed for the case where different domain classes come from different DBs, not for multiple DBs for one type of object. However it does provide a method for getting a hibernate template configured for a particular datasource so you should be able to do what you want to do.
The only tricky part might be dynamically adding datasources at runtime. The plugin author is very active in the community and very helpful so I think you should be able to get it working.
If you're a Java web app developer, Grails will be a much easier framework to learn than Rails (IMO, being a Java dev who has used both).
精彩评论