Kenni
Kenni4mo ago

How can i update a table in convex with

How can i update a table in convex with a new field?
7 Replies
Matt Luo
Matt Luo4mo ago
you can add a column to that table in the schema.ts file
Kenni
KenniOP4mo ago
Yes, but then it has conflicts with the existing data. and i dont want to have it optional.
Matt Luo
Matt Luo4mo ago
Can you say more about your situation? Are you trying to preserve important data? If so, I think you need to do a update of data (for that new column) for each document. If you are rapidly developing, you can stop schema validation on that particular table, i.e. take the table out of the schema.ts
v
v4mo ago
You can leave it optional then fill it then make it required again
Kenni
KenniOP4mo ago
I found a way. First creating an Optional Field, set it to a value, and then remove the Optional
v
v4mo ago
Genius
Matt Luo
Matt Luo4mo ago
Yes. I can now see how my message didn’t implicitly convey that. I think some of the alter table stuff isn’t intuitive because fundamentally, I think convex often prioritizes preventing MySQL foot guns over exposing easy alter table statements. You could have a simple alter table add column experience, but then accidentally cause performance issues by updating every row under the hood.

Did you find this page helpful?