Suppose that a user has multiple items. Each item would have complex configuration - multiple tables with relationships. Each configuration table would have an id and a item_id which is a FK to items table.
My question is given that we have a relational database and we export all tables to a text format (csv,json, etc) how can we reimport this data for another item as cloned? Importing just data would be easy since a new id will be generated for every row. However creating a id means that foreign keys would be invalid.
The only way I figured to solve this issue is to store data first(without FKs) for all tables and then knowing each table new PK update foreign keys. I could use a dictionary to map old ids with new ones.
Is there a cleaner way to achieve something like that?