Mark
Mark

Reputation: 6445

Is it better to transfer records between databases via mysql or rails?

We're running a production server with various lessons on it, and are in the process of creating a demo server with limited access. Each lesson takes around an hour to create in our CMS, and I'm trying to create a way to transfer lessons created there into our other environment through a button click. My end aim is to have records with identical primary ID's in both databases

My first question is, is tackling this through Ruby rather than SQL the right way to go? I can setup a service that submits a request to the demo server, with the correct params, but this will create new records with ID's that don't match up. Is it preferable for me to write a script that would take the object attributes as arguments, and create the records directly via mysql? And if so what's the best approach for that? Invoking a rake task?

Apologies for the open ended question but I'm not sure where else I can ask, and have found no resources on copying records between databases in a rails app (just duplicating objects within the same environment)

Upvotes: 0

Views: 36

Answers (1)

Vasfed
Vasfed

Reputation: 18454

If the demo server is not read-only - in generic situation you easily can face situation where ids that you're going to inject - are already taken.

As for process itself - I'd introduce a serialisation format for lessons (json dump or any other), so that they can be imported and exported in a single transaction. Then you can either allow users manually transfer these dumps or add an api that will do that (in this case you're adding a knowledge about demo server to the production one, which is not always desirable architecture-wise)

Upvotes: 1

Related Questions