Partial schema
Is it possible to have a partial schema? I have a table called lead with data in it. The schema is
lead: defineTable(v.any())
. I want to add an index, so I need to define the fields.
As there is existing data in the table, I'm getting this error:
9 Replies
No, you can't have some fields defined and some fields not, you'll either want to add them to the schema or turn off schema validation (perhaps temporarily).
You can have some tables defined and some not, but not fields on a table.
You could always just add the fields you're not solid on as optional, and then make things required when you're ready to firm things up.
You can also use
v.any()
for said fieldsOr you could do
and store in metadata an object with any fields you want.
Thanks, I've gone with turning of the validation for now.
I like the metadata idea, but I'm using
npx convex import
to get my csv data in, and would need to wrangle the schema in my data pipeline.to have schema validation for other tables, you could use
v.any()
for the table. And if you want the types w/o validation, you can cast:
also whenever you do import in your data and get it stable, try the "Show Schema" > "Generated" buttons in the dashboard to jumpstart writing out a full schema
For some reason the "Generated" tab only ever showed
v.any()
?
It unfortunately can't always infer the schema from your data -- common causes are fields that aren't valid identifiers (identifiers are alphanumeric and underscore strings), which can't be used in schema definitions or objects with a lot of keys (where we give up and say
v.any()
)Yes it's definatly that, good to know why, I appreciate the help 🙂