Overriding creationTime after migrating to Convex
Hi - I'm exploring migrating my project to convex from postgres, so far everything has been smooth but my existing tables currently have a createdAt field that I want to preserve in _creationTime. However, although the types on the patch function suggest that setting _creationTime would be allowed, performing a migration to set modify the time to my existing createdAt time fails.
There are times in my app where I sort over or display this time, so it is important to me that it is persisted, and it would be nice to not have to manually handle adding the time for future documents, since the feature already exists in the db.
Is there a way to set the _creationTime field for this case, or another suggested workaround?
2 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
You'll have to add your own createdAt field if you need to retain those values. I'd recommend making it optional so you can prefer the _creationTime value for new documents but still access the value for pre-migration documents.
The type allows _creationTime for the same reason it allows _id, to simplify upserts. It just ignores the actual values, though.