Copying entities between DBs while maintaining relationships

I’m looking at a scenario that involves copying selected entities between databases. I need to maintain the relationships between those entities, as defined by their :db.type/ref attributes.

But if I write an entity to a different DB, it will be assigned a new entity id, which seems like it will break the relationship? So can external keys be used for relationships instead?

would love to know what you come up with or end up doing!

I would recommend that you always have some kind of external ID for entities in you system.
Once you have this, you can do what you describe by ensuring that the new entities you ‘copy’ over include the correct references via the external ID, not the entity ID.