Web Dev Cody
Web Dev Cody14mo ago

A way to provide default values on new schema items?

so I'm trying to add a new field to a convex table and I'd like to make it required. Is there no way to add a field and have it auto-fill with a default value? Is the only way to make it v.optional() first, then update all my data, then remove the v.optional?
4 Replies
lee
lee14mo ago
yes there's no way to create a field with values populated in all documents. you can do what you described. or whenever you read the field you can do doc.field ?? <default>, or you can use a library like Ents that do this automatically https://labs.convex.dev/convex-ents/schema#field-defaults (cc @Michal Srb )
Ent Schema - Convex Ents
Relations, default values, unique fields and more for Convex
Web Dev Cody
Web Dev CodyOP14mo ago
I forget, are Ent's beta or prod ready
lee
lee14mo ago
it's more like a community-supported library. https://labs.convex.dev/convex-ents/status
Project Status - Convex Ents
Relations, default values, unique fields and more for Convex
Web Dev Cody
Web Dev CodyOP14mo ago
ok cool I'll check it out

Did you find this page helpful?