What is the best way to sync my rails model with an external database ?
I can use a callback on my model to update the external table. But in
the other direction, when the external db change some data and would
sync my activerecord model ? I can only think at a REST request of
update of some record. Or a cron sync script, problematic with large db.
There’s better solutions ?
What is the best way to sync my rails model with an external database ?
What exactly is your use case for this? It’s hard to give advice on a
question that vague.
I can use a callback on my model to update the external table. But in
the other direction, when the external db change some data and would
sync my activerecord model ? I can only think at a REST request of
update of some record. Or a cron sync script, problematic with large db.
There’s better solutions ?
From the little you’ve said, REST sounds like a good solution.
But…why do you need to synchronize at all? Can you just query the
external DB as necessary and avoid duplicating the data?
the only time you need to reload the models is if the schema of the db
changes, any other time it the data changes rails will always pull the
latest data, it appears that what you want to know is how to update the
view
when the database changes. is that so ?
What is the best way to sync my rails model with an external database ?
What exactly is your use case for this? It’s hard to give advice on a
question that vague.
Ok. I manage products data in a rails e-commerce but I need sync with
data in an external ERP. I can’t operate on ERP data, they could give me
only some views. I see these views as external db connection in rails,
but I wouldn’t use cron script for checking for change, I would like
have a callback on change made by the ERP. The only solution that I can
see is that the ERP made a call to my app (/product/updated/115) and
then I sync that product.
But if there was possibly made activerecord knowing what the ERP is
doing on the external db…
I can use a callback on my model to update the external table. But in
the other direction, when the external db change some data and would
sync my activerecord model ? I can only think at a REST request of
update of some record. Or a cron sync script, problematic with large db.
There’s better solutions ?
From the little you’ve said, REST sounds like a good solution.
But…why do you need to synchronize at all? Can you just query the
external DB as necessary and avoid duplicating the data?
In general is a typical problem of integration with company resources.
They don’t want give you access direct on db, but they want you work on
sync db.
There’s some better practices, general/typical solution pattern ?
If your app doesn’t really have to do anything with the data
(validate, transform, etc) then I’d try to solve this on the db level.
MySQL replication comes to mind though I’m not sure how that will work
with db views.
Keep us posted on how it goes!
Cheers,
Simon
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.