Hey quick question about optional types
Hey, quick question about optional types. I was able to come up with a way to easily define if a type could be missing. My questions are:
1. is there a more elegant way to do so and
2. is there a way to enforce these types on the convex dashboard. In my understanding, the local
schema.ts
doesn't get applied on the dashboard, but instead the dashboard allows any data to be inserted.

6 Replies
Hey @Mitak, thanks for the feedback!
(1) I think it would be cool to add something like
s.optional(type)
as a shorthand for the null union there. I'll file this as feedback for the folks working on the client library
(2) True, the dashboard isn't super-aware of your schema right now. We've been thinking about this a bit as we add the ability to edit data in the dashboard... would you be happy with a warning letting you know that the data you're modifying/adding doesn't match your schema, or would you want to be fully blocked from making that change?1 - awesome. Much appreciated.
2 - not 100% sure but at the moment, a warning seems a bit better, as I may change the scheme in code, and then it may be out of sync with the data, but I wouldn't want things to crash. A warning on specific data fields would be cool too, where they could have a different color background.
Ideally there's some kind of way to do migrations in a somewhat typesafe way.
(2) Cool thanks! I'll add this to my notes as we build out these features a bit more. I like the idea of having a per-field warning as you edit
p.s. we have a feature in early-access that will let you edit more complex types (Ids, nested objects, arrays, etc) in the dashboard. If you'd like to get in on that early send me a DM with your convex team slug, found in Team Settings!
@alexcole was talking about adding s.optional to schemas. The s.union with s.null is what we have today, but it somewhat confuses
null
and undefined
/missing and I think we can improve on it.Yep, thanks for the feature request! I actually just wrote a PR to add
s.optional(...)
to the schema builder so it should be out in the next release 🙂Old thread, but @Mitak we now have schema validation which makes the dashboard a safer place to make changes, and I wrote a helper for writing data migrations: https://stack.convex.dev/migrating-data-with-mutations
Migrating Data With Mutations
Using mutations to migrate data in Convex.