"Promoting" Collection data between databases

I currently have a setup where each database is an environment i.e. “Stage” and “Production”. I have a collection called Categories and another collection, Category_Links, which holds refs between two categories.

I’m running into some troubles trying to send the current collection data from the Stage db to the Production db. I could create a json of this data, but each ID is going to be unique meaning the refs in Category_Link will not be able to transfer. My project can probably manage if I keep this limitation in mind, but I’d like to know if there is something that I’m missing or a better way for me to manage this? I looked into multi-tenancy to essentially create a Project DB with shared collection data with environmental child dbs (Stage, Production) but with child unable to read parent dbs this doesn’t seem feasible. Any ideas? All of my other data I assume I’ll have to use the CLI to do a JSON export to then import back into the other database.

Hello @jstoes. The you can create documents with a custom ID, which can help when copying documents from one database to another. I think the biggest challenge may be that you cannot encode native Fauna types as JSON to be used with the CLI import command.

You will need to write a script using the drivers to read data from one database and write it to the other. The drivers properly encode native Fauna types on read and write, so you should be able to read Category_Links from the staging DB and write directly to the Category_Links in the prod DB, preserving the document references within. This assumes that you write the respective Categories with the correct IDs to the prod DB as well.

If you want to save database results as a JSON file that preserves type information, then use the drivers’ respective de/serialization utilities to encode the data to the tagged format when saving to a file, and then decode it when reading the file. For example, you would use the TaggedTypeFormat class if using the JS driver. Even if you do this, you cannot use the CLI import command as it is now. I think this is something we could improve in the future, though, so I’ve recorded it as product feedback.