On Fri, Oct 24, 2008 at 4:53 PM, Ivan Vanderbyl <[EMAIL PROTECTED]> wrote:
> I have a scenario, we have 2 applications running on the same server,
> each on their own domain, (but that's irrelevant), both applications
> have a User model (and table, in separate databases), both use Restful
> auth plugin etc.
> I have set app B to load users from the database of app A with a
> custom connection in the User model, all works smashingly! What I'm
> wondering is, lets say I wanted all users to be in a separate
> database, maybe on another server, which only stores users, is there
> some; possibly undocumented way of telling ActiveRecord::Migration to
> connect to another database when running that migration?
>
> Also, I haven't tried this, but maybe someone has, or knows someone
> else who has: Will my record associations still work? e.g. User
> has_many Orders? or User HABTM Roles if the roles table is on another
> database?

I have a similar situation, but not with a users model.

The way I handled this is using PostgreSQL and multiple schemas, then
one application owns the table, and the other just has a view of it.
This way you keep your DB implementation of this solution transparent
to Rails (Rails will treat a view called 'users' just like a table
called 'users'.

So your DB would look like this:

ProductionDatabase
  Schemas
     App1
         Views
            Users (select * from app2.users)
     App2
         Tables
            Users

Now to make that work, you would need on insert and on delete and on
update rules on your users view obviously.

The other (and probably) more rails way to do it would be to set up a
third authentication application and expose the users table with
ActiveResource.  That way you could then plug as many apps into it as
you want.

The third way I would look into is setting up an LDAP server and
authenticating from both apps against that.

Anyway, hope that helps.



-- 
http://lindsaar.net/
Rails, RSpec and Life blog....

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
or Rails Oceania" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rails-oceania?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to