Gorka Cesium
Gorka Cesium2y ago

how to change a schema to remove an array if there is already data with that array?

quote Schema:
name: v.string(),
items: v.array(v.id("items")) // want to remove this field but there are already quotes in the DB with this field
name: v.string(),
items: v.array(v.id("items")) // want to remove this field but there are already quotes in the DB with this field
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 possible
3 Replies
Michal Srb
Michal Srb2y ago
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.
Gorka Cesium
Gorka CesiumOP2y ago
that is helpful, thank you
Michal Srb
Michal Srb2y ago
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.

Did you find this page helpful?