#Simple issue I faced while deleting a field in a schema

4 messages · Page 1 of 1 (latest)

shrewd robin
#

My issue is the following:
I had a property in a table that I want to have it removed, and as simple as this I just couldn't figure out how to remove the previous fields that were in the database previously
I simply want advice on how to write a function to run once to remove anything that was there previously for that field, I temporarily gave it an "optional",
the schema in question:

export const settingsSchema = {
  userId: v.id("users"),
  responseType: literals("chat","single-message"),
- theme: v.optional(literals("dark","light")),
  keepChat: v.number(), // How long to keep the chats for // max of 30 days
  attachments:v.object({
      audio: v.boolean(),
      images: v.boolean(),
    }),
  model: literals("gemini-1.0-pro","gemini-1.0-pro-latest","gemini-1.0-pro-001","gemini-1.5-flash","gemini-1.5-flash-latest","gemini-1.5-pro-latest","gemini-1.5-pro"),
  languages: literals("ar","bn","bg","zh","hr","cs","da","nl",
    "en","et","fi","fr","de","el","iw","hi","hu","id","it","ja",
    "ko","lv","lt","no","pl","pt","ro","ru","sr","sk","sl","es",
    "sw","sv","th","tr","uk","vi")
}

and the Error Message:

Document with ID "md71n8fp1c83tax5r7q9bg5phn73v75g" in table "settings" does not match the schema: Object contains extra field theme that is not in the validator.

fathom thistleBOT
#

Thanks for posting in #1088161997662724167.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.

    - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
    - Use [search.convex.dev](https://search.convex.dev) to search Docs, Stack, and Discord all at once.
    - Additionally, you can post your questions in the Convex Community's #1228095053885476985 channel to receive a response from AI.
    - Avoid tagging staff unless specifically instructed.

    Thank you!
remote drum
#

If I remember correctly, you have to clear all of the field values first (set them to undefined), then the field can be removed from the schema.

#

For situations like this I'll write an internal mutation that collects all records and clears the relevant field, then run this function from the dashboard.