Topic: share a User Database

What would be a good way of sharing a database. I've been wanting to avoid multi-database apps and still want to. So I was thinking about making an app that only dealt with users. and having other apps contact it, rather than the database. That said how would you go about associations?

Class SomeModel
   has_many :users
end

Class Users #model wont have a table in this database
   belongs_to :some_model
end


when all the user info is in another app would this work? can I alias the info, and would rails deal with id's appropriately.

or is there a better way with dealing with all this?

--

Re: share a User Database

I'm not sure what a "user" application would do for you.  It seems this would just add an unecessary layer of code.  Why not just access the user database directly from each application that needs it?

You can use the built in optimistic locking in Active Record by adding an integer column called lock_version to tables.  (See Agile pp 222-224)

Re: share a User Database

yes your right, although most articles I've read say stay away from multiple databases in Rails, and I would like to. And with REST/respond_to it seems just as easy to do it this way. also it would allow 3'rd party use of the database without compromising the database itself (although thats something I'm not planning on). Or am I wrong with all this?

basically I want one user database with many apps (about 4 or 5), I'm not 100% sure which way to go on this.

Optimistic locking (page 387 in 2nd Editioin) is if you are worried that the information accesses in the same database will intefear with each other. I dont think I'll need this here.

--

Re: share a User Database

How about sharing one database with all apps? This way all apps are using the same information.

Railscasts - Free Ruby on Rails Screencasts

Re: share a User Database

Or if you really wanted to go overboard you could move the user information into an LDAP directory and authenticate against that....