Using deep clone to extract a subset db from production
Closed this issue · 2 comments
I'm sorry to use the issue tracker for "questions"
I already use your great gem to "version" a graph of objects
But I'd like to reuse a bit the same mechanism to subset my production database and store this graph in a separate db (dev or staging) (ideally preserving the ids ?)
I assumed I could load the graph then call ActiveRecord::Base.establish_connection(config)
Since I don't know much about the implementation of ActiveRecord and your gem.
Do you think it's a viable solution :
- preload all the relationships on prod db
- call ActiveRecord::Base.establish_connection to connect to dev db
- call deep_clone ?
Hi,
What you are trying to do is not very common.. I think only most recent versions of AR do support switching databases, see https://guides.rubyonrails.org/active_record_multiple_databases.html.
That being said: I think you should first call deep_clone while connected to the prod db. This will create a tree structure in memory of the data that is in your prod db. After that, you should somehow save the duped record to the dev db, something like ActiveRecord::Base.connected_to(role: :writing, shard: :default) { new_project.save! }
. But all this is highly theoretical imo :)
As an alternative, I would suggest that creating (JSON) export/import functionality would probably be more robust.
Thanks.