how to change a schema to remove an array if there is already data with that array?
quote Schema:
how can I delete the
items
field from the schema without having to delete all the data in the quotes
table?
I tried to mark the column "items" as null but it wasn't possible3 Replies
Hey @Gorka Cesium , you can write an internal mutation that loops over all documents in the table and removes the items field, via
db.patch(id, {items: undefined});
You can either disable schema validation while you're running this mutation, or you can first change the schema to v.optional(v.array(v.id("items")))
, run the mutation, then remove the field completely.
You can run the internal mutation via npx convex run
, optionally passing in the --prod
flag if you need to do this on your prod deployment.that is helpful, thank you
This Stack article covers more details: https://stack.convex.dev/migrating-data-with-mutations
Migrating Data With Mutations
Using mutations to migrate data in Convex.