[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6FJZADXCS0ER8SK572SHRSR":3,"skill-same:01M6FJZADXCS0ER8SK572SHRSR":49},{"skillNo":4,"name":5,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":22,"linkOnly":23,"markdownContent":24,"markdownBody":24,"frontMatter":25,"refName":26,"commitSha":27,"skillDirectory":28,"forksCount":29,"repositoryHtmlUrl":30,"repositoryHomepageUrl":31,"ownerHtmlUrl":32,"ownerBlogUrl":6,"ownerDescription":33,"updatedAt":34,"install":35,"resources":48},"01M6FJZADXCS0ER8SK572SHRSR","convex-schema-validator",null,"ComeOnOliver\u002Fskillshub","ComeOnOliver","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F43215937?v=4","01M6E5JNFECJAAVFE0W7SMWWD2","Haoran Shu","01M6E5JNNDQS7AJZDYFQ8TPZCK",67,"MIT","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fwaynesutton\u002Fconvexskills\u002Fconvex-schema-validator\u002FSKILL.md",[],[18,19,20,21],"convex","schema","convex schema validator","schema validator","2026-11-10 10:12:30",false,"# Convex Schema Validator\n\nDefine and validate database schemas in Convex with proper typing, index configuration, optional fields, unions, and strategies for schema migrations.\n\n## Documentation Sources\n\nBefore implementing, do not assume; fetch the latest documentation:\n\n- Primary: https:\u002F\u002Fdocs.convex.dev\u002Fdatabase\u002Fschemas\n- Indexes: https:\u002F\u002Fdocs.convex.dev\u002Fdatabase\u002Findexes\n- Data Types: https:\u002F\u002Fdocs.convex.dev\u002Fdatabase\u002Ftypes\n- For broader context: https:\u002F\u002Fdocs.convex.dev\u002Fllms.txt\n\n## Instructions\n\n### Basic Schema Definition\n\n```typescript\n\u002F\u002F convex\u002Fschema.ts\nimport { defineSchema, defineTable } from \"convex\u002Fserver\";\nimport { v } from \"convex\u002Fvalues\";\n\nexport default defineSchema({\n  users: defineTable({\n    name: v.string(),\n    email: v.string(),\n    avatarUrl: v.optional(v.string()),\n    createdAt: v.number(),\n  }),\n  \n  tasks: defineTable({\n    title: v.string(),\n    description: v.optional(v.string()),\n    completed: v.boolean(),\n    userId: v.id(\"users\"),\n    priority: v.union(\n      v.literal(\"low\"),\n      v.literal(\"medium\"),\n      v.literal(\"high\")\n    ),\n  }),\n});\n```\n\n### Validator Types\n\n| Validator | TypeScript Type | Example |\n|-----------|----------------|---------|\n| `v.string()` | `string` | `\"hello\"` |\n| `v.number()` | `number` | `42`, `3.14` |\n| `v.boolean()` | `boolean` | `true`, `false` |\n| `v.null()` | `null` | `null` |\n| `v.int64()` | `bigint` | `9007199254740993n` |\n| `v.bytes()` | `ArrayBuffer` | Binary data |\n| `v.id(\"table\")` | `Id\u003C\"table\">` | Document reference |\n| `v.array(v)` | `T[]` | `[1, 2, 3]` |\n| `v.object({})` | `{ ... }` | `{ name: \"...\" }` |\n| `v.optional(v)` | `T \\| undefined` | Optional field |\n| `v.union(...)` | `T1 \\| T2` | Multiple types |\n| `v.literal(x)` | `\"x\"` | Exact value |\n| `v.any()` | `any` | Any value |\n| `v.record(k, v)` | `Record\u003CK, V>` | Dynamic keys |\n\n### Index Configuration\n\n```typescript\nexport default defineSchema({\n  messages: defineTable({\n    channelId: v.id(\"channels\"),\n    authorId: v.id(\"users\"),\n    content: v.string(),\n    sentAt: v.number(),\n  })\n    \u002F\u002F Single field index\n    .index(\"by_channel\", [\"channelId\"])\n    \u002F\u002F Compound index\n    .index(\"by_channel_and_author\", [\"channelId\", \"authorId\"])\n    \u002F\u002F Index for sorting\n    .index(\"by_channel_and_time\", [\"channelId\", \"sentAt\"]),\n    \n  \u002F\u002F Full-text search index\n  articles: defineTable({\n    title: v.string(),\n    body: v.string(),\n    category: v.string(),\n  })\n    .searchIndex(\"search_content\", {\n      searchField: \"body\",\n      filterFields: [\"category\"],\n    }),\n});\n```\n\n### Complex Types\n\n```typescript\nexport default defineSchema({\n  \u002F\u002F Nested objects\n  profiles: defineTable({\n    userId: v.id(\"users\"),\n    settings: v.object({\n      theme: v.union(v.literal(\"light\"), v.literal(\"dark\")),\n      notifications: v.object({\n        email: v.boolean(),\n        push: v.boolean(),\n      }),\n    }),\n  }),\n\n  \u002F\u002F Arrays of objects\n  orders: defineTable({\n    customerId: v.id(\"users\"),\n    items: v.array(v.object({\n      productId: v.id(\"products\"),\n      quantity: v.number(),\n      price: v.number(),\n    })),\n    status: v.union(\n      v.literal(\"pending\"),\n      v.literal(\"processing\"),\n      v.literal(\"shipped\"),\n      v.literal(\"delivered\")\n    ),\n  }),\n\n  \u002F\u002F Record type for dynamic keys\n  analytics: defineTable({\n    date: v.string(),\n    metrics: v.record(v.string(), v.number()),\n  }),\n});\n```\n\n### Discriminated Unions\n\n```typescript\nexport default defineSchema({\n  events: defineTable(\n    v.union(\n      v.object({\n        type: v.literal(\"user_signup\"),\n        userId: v.id(\"users\"),\n        email: v.string(),\n      }),\n      v.object({\n        type: v.literal(\"purchase\"),\n        userId: v.id(\"users\"),\n        orderId: v.id(\"orders\"),\n        amount: v.number(),\n      }),\n      v.object({\n        type: v.literal(\"page_view\"),\n        sessionId: v.string(),\n        path: v.string(),\n      })\n    )\n  ).index(\"by_type\", [\"type\"]),\n});\n```\n\n### Optional vs Nullable Fields\n\n```typescript\nexport default defineSchema({\n  items: defineTable({\n    \u002F\u002F Optional: field may not exist\n    description: v.optional(v.string()),\n    \n    \u002F\u002F Nullable: field exists but can be null\n    deletedAt: v.union(v.number(), v.null()),\n    \n    \u002F\u002F Optional and nullable\n    notes: v.optional(v.union(v.string(), v.null())),\n  }),\n});\n```\n\n### Index Naming Convention\n\nAlways include all indexed fields in the index name:\n\n```typescript\nexport default defineSchema({\n  posts: defineTable({\n    authorId: v.id(\"users\"),\n    categoryId: v.id(\"categories\"),\n    publishedAt: v.number(),\n    status: v.string(),\n  })\n    \u002F\u002F Good: descriptive names\n    .index(\"by_author\", [\"authorId\"])\n    .index(\"by_author_and_category\", [\"authorId\", \"categoryId\"])\n    .index(\"by_category_and_status\", [\"categoryId\", \"status\"])\n    .index(\"by_status_and_published\", [\"status\", \"publishedAt\"]),\n});\n```\n\n### Schema Migration Strategies\n\n#### Adding New Fields\n\n```typescript\n\u002F\u002F Before\nusers: defineTable({\n  name: v.string(),\n  email: v.string(),\n})\n\n\u002F\u002F After - add as optional first\nusers: defineTable({\n  name: v.string(),\n  email: v.string(),\n  avatarUrl: v.optional(v.string()), \u002F\u002F New optional field\n})\n```\n\n#### Backfilling Data\n\n```typescript\n\u002F\u002F convex\u002Fmigrations.ts\nimport { internalMutation } from \".\u002F_generated\u002Fserver\";\nimport { v } from \"convex\u002Fvalues\";\n\nexport const backfillAvatars = internalMutation({\n  args: {},\n  returns: v.number(),\n  handler: async (ctx) => {\n    const users = await ctx.db\n      .query(\"users\")\n      .filter((q) => q.eq(q.field(\"avatarUrl\"), undefined))\n      .take(100);\n\n    for (const user of users) {\n      await ctx.db.patch(user._id, {\n        avatarUrl: `https:\u002F\u002Fapi.dicebear.com\u002F7.x\u002Finitials\u002Fsvg?seed=${user.name}`,\n      });\n    }\n\n    return users.length;\n  },\n});\n```\n\n#### Making Optional Fields Required\n\n```typescript\n\u002F\u002F Step 1: Backfill all null values\n\u002F\u002F Step 2: Update schema to required\nusers: defineTable({\n  name: v.string(),\n  email: v.string(),\n  avatarUrl: v.string(), \u002F\u002F Now required after backfill\n})\n```\n\n## Examples\n\n### Complete E-commerce Schema\n\n```typescript\n\u002F\u002F convex\u002Fschema.ts\nimport { defineSchema, defineTable } from \"convex\u002Fserver\";\nimport { v } from \"convex\u002Fvalues\";\n\nexport default defineSchema({\n  users: defineTable({\n    email: v.string(),\n    name: v.string(),\n    role: v.union(v.literal(\"customer\"), v.literal(\"admin\")),\n    createdAt: v.number(),\n  })\n    .index(\"by_email\", [\"email\"])\n    .index(\"by_role\", [\"role\"]),\n\n  products: defineTable({\n    name: v.string(),\n    description: v.string(),\n    price: v.number(),\n    category: v.string(),\n    inventory: v.number(),\n    isActive: v.boolean(),\n  })\n    .index(\"by_category\", [\"category\"])\n    .index(\"by_active_and_category\", [\"isActive\", \"category\"])\n    .searchIndex(\"search_products\", {\n      searchField: \"name\",\n      filterFields: [\"category\", \"isActive\"],\n    }),\n\n  orders: defineTable({\n    userId: v.id(\"users\"),\n    items: v.array(v.object({\n      productId: v.id(\"products\"),\n      quantity: v.number(),\n      priceAtPurchase: v.number(),\n    })),\n    total: v.number(),\n    status: v.union(\n      v.literal(\"pending\"),\n      v.literal(\"paid\"),\n      v.literal(\"shipped\"),\n      v.literal(\"delivered\"),\n      v.literal(\"cancelled\")\n    ),\n    shippingAddress: v.object({\n      street: v.string(),\n      city: v.string(),\n      state: v.string(),\n      zip: v.string(),\n      country: v.string(),\n    }),\n    createdAt: v.number(),\n    updatedAt: v.number(),\n  })\n    .index(\"by_user\", [\"userId\"])\n    .index(\"by_user_and_status\", [\"userId\", \"status\"])\n    .index(\"by_status\", [\"status\"]),\n\n  reviews: defineTable({\n    productId: v.id(\"products\"),\n    userId: v.id(\"users\"),\n    rating: v.number(),\n    comment: v.optional(v.string()),\n    createdAt: v.number(),\n  })\n    .index(\"by_product\", [\"productId\"])\n    .index(\"by_user\", [\"userId\"]),\n});\n```\n\n### Using Schema Types in Functions\n\n```typescript\n\u002F\u002F convex\u002Fproducts.ts\nimport { query, mutation } from \".\u002F_generated\u002Fserver\";\nimport { v } from \"convex\u002Fvalues\";\nimport { Doc, Id } from \".\u002F_generated\u002FdataModel\";\n\n\u002F\u002F Use Doc type for full documents\ntype Product = Doc\u003C\"products\">;\n\n\u002F\u002F Use Id type for references\ntype ProductId = Id\u003C\"products\">;\n\nexport const get = query({\n  args: { productId: v.id(\"products\") },\n  returns: v.union(\n    v.object({\n      _id: v.id(\"products\"),\n      _creationTime: v.number(),\n      name: v.string(),\n      description: v.string(),\n      price: v.number(),\n      category: v.string(),\n      inventory: v.number(),\n      isActive: v.boolean(),\n    }),\n    v.null()\n  ),\n  handler: async (ctx, args): Promise\u003CProduct | null> => {\n    return await ctx.db.get(args.productId);\n  },\n});\n```\n\n## Best Practices\n\n- Never run `npx convex deploy` unless explicitly instructed\n- Never run any git commands unless explicitly instructed\n- Always define explicit schemas rather than relying on inference\n- Use descriptive index names that include all indexed fields\n- Start with optional fields when adding new columns\n- Use discriminated unions for polymorphic data\n- Validate data at the schema level, not just in functions\n- Plan index strategy based on query patterns\n\n## Common Pitfalls\n\n1. **Missing indexes for queries** - Every withIndex needs a corresponding schema index\n2. **Wrong index field order** - Fields must be queried in order defined\n3. **Using v.any() excessively** - Lose type safety benefits\n4. **Not making new fields optional** - Breaks existing data\n5. **Forgetting system fields** - _id and _creationTime are automatic\n\n## References\n\n- Convex Documentation: https:\u002F\u002Fdocs.convex.dev\u002F\n- Convex LLMs.txt: https:\u002F\u002Fdocs.convex.dev\u002Fllms.txt\n- Schemas: https:\u002F\u002Fdocs.convex.dev\u002Fdatabase\u002Fschemas\n- Indexes: https:\u002F\u002Fdocs.convex.dev\u002Fdatabase\u002Findexes\n- Data Types: https:\u002F\u002Fdocs.convex.dev\u002Fdatabase\u002Ftypes\n",{},"main","def8531e65114c0fca8fb8551c1871ee0eed705c","skills\u002Fwaynesutton\u002Fconvexskills\u002Fconvex-schema-validator",24,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub","https:\u002F\u002Fskillshub.wtf","https:\u002F\u002Fgithub.com\u002FComeOnOliver","AI & Blockchain Engineer\r\n","2026-06-24 22:07:19",{"source":7,"skillName":5,"commands":36,"prompt":46,"zipAvailable":47},[37,40,43],{"tool":38,"command":39},"npx","npx skills add ComeOnOliver\u002Fskillshub --skill convex-schema-validator",{"tool":41,"command":42},"bunx","bunx skills add ComeOnOliver\u002Fskillshub --skill convex-schema-validator",{"tool":44,"command":45},"pnpm","pnpm dlx skills add ComeOnOliver\u002Fskillshub --skill convex-schema-validator","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fwaynesutton\u002Fconvexskills\u002Fconvex-schema-validator\u002FSKILL.md",true,[],[50,59,68,77,83,89],{"skillNo":51,"name":52,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":53,"categories":54,"keywords":55,"publishedAt":22},"01M6FKJN13GMG4KY57J3QD8GY5","model-hierarchy-skill","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzscole\u002Fmodel-hierarchy-skill\u002Fmodel-hierarchy-skill\u002FSKILL.md",[],[56,57,58],"model","model hierarchy","model hierarchy skill",{"skillNo":60,"name":61,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":62,"categories":63,"keywords":64,"publishedAt":22},"01M6FKJJJ6GCAMR4PPPRD12M5X","zoom-mcp","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-mcp\u002FSKILL.md",[],[65,66,67],"MCP","zoom","zoom mcp",{"skillNo":69,"name":70,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":71,"categories":72,"keywords":73,"publishedAt":22},"01M6FKJE3KYT3KPEZMEEHYKA6K","zoom-apps-sdk","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-apps-sdk\u002FSKILL.md",[],[74,75,76,66],"sdk","zoom apps sdk","apps",{"skillNo":78,"name":79,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":80,"categories":81,"keywords":82,"publishedAt":22},"01M6FKJ9EDH9Q5VWDF8HAJRSP0","windows","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwindows\u002FSKILL.md",[],[79],{"skillNo":84,"name":85,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":22},"01M6FKJ666BEEFC3AE9GJ72Q93","whiteboard","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwhiteboard\u002FSKILL.md",[],[85],{"skillNo":90,"name":91,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":92,"categories":93,"keywords":94,"publishedAt":22},"01M6FKJ21WFCDGTJQ2Q91T9DVW","websockets","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwebsockets\u002FSKILL.md",[],[91]]