I have a SQLAlchemy-based tool for selectively copying data between two different databases for testing purposes. I use the merge() function to take model objects from one session and store them in another session. I'd like to be able to store the source objects in some intermediate form and then merge() them at some later point in time.
It seems like there are a few options to accomplish this:
- Exporting
DELETE/INSERTSQL statements. Seems pretty straightforward, I think I can get SQLAlchemy to give me theINSERTstatements, and maybe even theDELETEs. - Exproting the data to a SQLite database file with the same (or similar) schema, that could then be read in as a source at a later point in time.
- Serializing the data in some manner and then reading them back into memory for the merge. I don't know if SQLAlchemy has something like this built-in or not. I'm not sure what the challenges would be in rolling this myself.
Has anyone tackled this problem before? If so, what was your solution?
EDIT: I found a tool built on top of SQLAlchemy called dataset that provides the freeze functionality I'm looking for, but there seems to be no corresponding thaw functionality for restoring the data.