convex-schema-validator
Defining and validating database schemas with proper typing, index configuration, optional fields, unions, and migration strategies for schema changes
By waynesutton · 2,856 installs
npx skills add waynesutton/convexskills --skill convex-schema-validator
Source repository · Upstream listing
Convex Schema Validator
Define and validate database schemas in Convex with proper typing, index configuration, optional fields, unions, and strategies for schema migrations.
Documentation Sources
Before implementing, do not assume; fetch the latest documentation:
Primary: https://docs.convex.dev/database/schemas
Indexes: https://docs.convex.dev/database/indexes
Data Types: https://docs.convex.dev/database/types
For broader context: https://docs.convex.dev/llms.txt
Instructions
Basic Schema Definition
Validator Types
Validator TypeScript Type Example
v.string() string "hello"
v.number() number 42 , 3.14
v.boolean() boolean true , false
v.null() null null
v.int64() bigint 9007199254740993n
v.bytes() ArrayBuffer Binary data
v.id("table") Id<"table" Document reference
v.array(v) T[] [1, 2, 3]
v.object({}) { ... } { name: "..." }
v.optional(v) T \ undefined Optional field
v.union(...) T1 \ T2 Multiple types
v.literal(x) "x" Exact value
v.any() any Any value
v.record(k, v) Record<K, V Dynamic keys
Index Configuration
Complex Types
Discriminated Unions
Optional vs Nullable Fields
Index Naming Convention
Always include all indexed fields in the index name:
Schema Migration Strategies
Adding New Fields
Backfilling Data
Making Optional Fields Required
Examples
Complete E commerce Schema
Using Schema Types in Functions
Best Practices
Never run npx convex deploy unless explicitly instructed
Never run any git commands unless explicitly instructed
Always define explicit schemas rather than relying on inference
Use descriptive index names that include all indexed fields
Start with optional fields when adding new columns
Use discriminated unions for polymorphic data
Validate data at the schema level, not just in functions
Plan index strategy based on query patterns
Common Pitfalls
1. Missing indexes for queries Every withIndex needs a corresponding schema index
2. Wrong index field order Fields must be queried in order defined
3. Using v.any() excessively Lose type safety benefits
4. Not making new fields optional Breaks existing data
5. Forgetting system fields id and creationTime are automatic
References
Convex Documentation: https://docs.convex.dev/
Convex LLMs.txt: https://docs.convex.dev/llms.txt
Schemas: https://docs.convex.dev/database/schemas
Indexes: https://docs.convex.dev/database/indexes
Data Types: https://docs.convex.dev/database/types