Migrating a DB and Relationships
I'm looking at the import options and seeing that we can't include
_id
in the objects unless we have a Snapshot.
See here: https://docs.convex.dev/database/import-export/import#features
I'm totally fine with Convex creating new _id
s, but I don't understand how relationships can be maintained when migrating from another service where I don't have the Snapshot.
Since I'm migrating from MongoDB and I've got production data, it's unclear how to maintain those relationships. For instance, if a user has a list of tasks, the Task object has a user property with the _id of the user OR the User object has an array called tasks that has the _id for all of the users tasks. Either way, it is unclear how to preserve those relationships on import.
Anyone know how to do this or a good resource for understanding the process?Importing Data Snapshots | Convex Developer Hub
Import data into Convex
5 Replies
The first example sounds like a straightforward foreign key which you define in schema.ts
Convex has an array type for the column, but I believe there are limitations
With regard to the size of the array. The limitations are in the docs
You can temporarily have a separate id field with an index on it, import things, then run a migration where you look up the object by id, then replace it with the _id. The field type could be v.union(v.string(), v.id(…))
@kurtlibby note there's no performance penalty for using a different column as the foreign key join column as long as you add an index.
_id
gets some special treatment in APIs like ctx.db.get(id)
but you're not limited to using that column for foreign keys.I was able to get a sample set of data migrated over and did a migration from the mongo _id to the convex _id. not too difficult. Thanks for the pointers everyone!
@rgz