schema-builder

Designs Convex database schemas with validators, indexes, and relational structure.

Updated Jun 8, 2024
One-click install
npx skills add https://github.com/shadeiskndr/portfolio --skill schema-builder-shadeiskndr
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: schema-builder
Source: https://github.com/shadeiskndr/portfolio/tree/main/.agents/skills/schema-builder
Command: npx skills add https://github.com/shadeiskndr/portfolio --skill schema-builder-shadeiskndr

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Convex schemas that lack clear relationships, indexes, and strong validators can lead to slow queries, inconsistent data, and brittle application logic.

Core Features & Use Cases

  • Schema template generation: Start from a best-practice Convex defineSchema/defineTable structure with correct field validators and timestamp patterns.
  • Relationship and indexing guidance: Use document-relational patterns (ID references), and add single-field and compound indexes for common access paths.
  • Validator and modeling patterns: Apply strict v.* validators, enum-style unions, and safe handling of arrays vs relational tables (e.g., junction tables for many-to-many).
  • Use case example: Redesign a nested users -> posts -> comments structure into normalized relational tables with userId/postId foreign keys and matching indexes for efficient lookup.

Quick Start

Create or update your Convex convex/schema.ts by describing your entities and the queries you need, then ask for a schema that includes validators, relationship IDs, and appropriate indexes.

Frequently Asked Questions about schema-builder

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I define relationships in a Convex database schema?

Convex database schema relationships are defined using document-relational patterns with ID references. You establish foreign keys like `userId` or `postId` to connect normalized tables, replacing nested document structures to maintain data consistency.

What's the best way to structure indexes for Convex tables?

The best way to structure indexes for Convex tables is by adding single-field and compound indexes for common access paths. You should explicitly index foreign keys and frequent filters to prevent inefficient queries and ensure fast data retrieval.

When should I use junction tables instead of arrays in Convex?

You should use junction tables instead of arrays in Convex for many-to-many relationships and safe bounded-array handling. Normalizing nested documents into relational tables prevents invalid data and avoids the limitations of unbounded array growth.

How do I apply strict validators to a Convex schema?

Strict validators are applied to a Convex schema using `v.*` typing and enum-style unions. This enforces explicit field validation within the `defineSchema` and `defineTable` structure, preventing invalid data entry at the database level.

Can I refactor nested documents into normalized relations in Convex?

Yes, you can refactor nested documents into normalized relations in Convex by converting embedded structures like `users -> posts -> comments` into separate tables. This process uses ID references for foreign keys and matching indexes for efficient lookup.

Why are my Convex database queries running slowly?

Convex database queries run slowly when schemas lack clear relationships, compound indexes, and strong validators. Adding explicit indexing for foreign keys and common filters ensures efficient data access paths and prevents brittle application logic.