Multi User ActiveResource

My higher level objective is to develop a way to move particular database entries from my development platform to my staging platform and then to my production platform. Unfortunately, there may be reasons to go the other way as well. And, these entries have "owners" and also are interconnected. So, not only does Foo have a belongs_to :user in it, it also has has_many :dogs, etc. Thus most fields will just move over but the id fields and the foreign keys will change.

One approach is some outside SQL process.

A second approach is to have sever 1 contact server 2 via ActiveResource to move the records over. I've not used ActiveResource before. It would seem to be easier to do that if server 1 could contact server 2 on behalf of the current user instead of a specific "admin" user. That is mostly what I'm asking with this email: is that possible and if so, can you point me to the documentation on how to do it?

A third approach would be to tell ActiveRecord to open a new database connection to the other server and move the records that way.

If anyone has any other suggested approaches, that would be great as well.

Thank you, pedz

I'll help you with the database end a little.

This example takes into account the following:

I have two production servers - linux server A, and linux server B. I have one development windows box - dev box C. All three use MySql for database handling. I have putty installed locally.

The first thing I do is I set the port for dev box C to something other than 3306. In this case my dev box C can act as the staging server. I set the port to 3400. Server A is the server I want the new data to go to and Server B houses the data I want to retrieve.

I open Putty and go to tunnelling and activate it with SSH. I open Server B with Putty and now tunnelling is active. At this point, if I open an instance of MySql with port 3306 it will locally connect to Server B securely through SSH. This allows you to not use remote DB handlers. At the same time, I have port 3400 open as a connection with MySql. I now can operate two database instances simultaneously.

From here, you can do quite a few things. You could easily send development data to the localhost:3306 connection from localhost:3400 using Rails. You could also use capistrano for performing mysql data dumps as well: http://codesnippets.joyent.com/posts/show/1215.

If you want to transparently work with your second database from here, you could use this gem: https://github.com/karledurante/secondbase.

I hope some of the information helps.

This one might be slightly better: GitHub - thiagopradi/octopus: Database Sharding for ActiveRecord