
Database Design
Pick the right datastore and indexing strategy for a solo-built app instead of defaulting to Postgres for every prototype.
Install
npx skills add https://github.com/sickn33/antigravity-awesome-skills --skill database-designWhat is this skill?
- Context-driven decision tree: PostgreSQL vs Neon/Supabase vs Turso vs SQLite vs PlanetScale/CockroachDB
- Explicit trade-off table for serverless PG, edge SQLite, vector (pgvector), and global MySQL scale
- Five scoping questions: deployment, query complexity, edge/serverless, vectors, global distribution
- Indexing principles: WHERE/JOIN/ORDER BY/FK columns vs write-heavy over-indexing
- B-tree and related index-type guidance tied to query patterns
Adoption & trust: 1.5k installs on skills.sh; 40.1k GitHub stars; 3/3 security scanners passed (skills.sh audits).
Recommended Skills
Supabase Postgres Best Practicessupabase/agent-skills
Lark Baselarksuite/cli
Convex Migration Helperget-convex/agent-skills
Neon Postgresneondatabase/agent-skills
Firebase Firestore Standardfirebase/agent-skills
Postgresql Table Designwshobson/agents
Journey fit
Primary fit
Schema and datastore choices are implemented during Build, but the skill’s decision tree is meant before you lock architecture. Database selection, indexing, and relational modeling map directly to backend data layers—not frontend or DevOps-only work.
Common Questions / FAQ
Is Database Design safe to install?
skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.
SKILL.md
READMESKILL.md - Database Design
# Database Selection (2025) > Choose database based on context, not default. ## Decision Tree ``` What are your requirements? │ ├── Full relational features needed │ ├── Self-hosted → PostgreSQL │ └── Serverless → Neon, Supabase │ ├── Edge deployment / Ultra-low latency │ └── Turso (edge SQLite) │ ├── AI / Vector search │ └── PostgreSQL + pgvector │ ├── Simple / Embedded / Local │ └── SQLite │ └── Global distribution └── PlanetScale, CockroachDB, Turso ``` ## Comparison | Database | Best For | Trade-offs | |----------|----------|------------| | **PostgreSQL** | Full features, complex queries | Needs hosting | | **Neon** | Serverless PG, branching | PG complexity | | **Turso** | Edge, low latency | SQLite limitations | | **SQLite** | Simple, embedded, local | Single-writer | | **PlanetScale** | MySQL, global scale | No foreign keys | ## Questions to Ask 1. What's the deployment environment? 2. How complex are the queries? 3. Is edge/serverless important? 4. Vector search needed? 5. Global distribution required? # Indexing Principles > When and how to create indexes effectively. ## When to Create Indexes ``` Index these: ├── Columns in WHERE clauses ├── Columns in JOIN conditions ├── Columns in ORDER BY ├── Foreign key columns └── Unique constraints Don't over-index: ├── Write-heavy tables (slower inserts) ├── Low-cardinality columns ├── Columns rarely queried ``` ## Index Type Selection | Type | Use For | |------|---------| | **B-tree** | General purpose, equality & range | | **Hash** | Equality only, faster | | **GIN** | JSONB, arrays, full-text | | **GiST** | Geometric, range types | | **HNSW/IVFFlat** | Vector similarity (pgvector) | ## Composite Index Principles ``` Order matters for composite indexes: ├── Equality columns first ├── Range columns last ├── Most selective first └── Match query pattern ``` # Migration Principles > Safe migration strategy for zero-downtime changes. ## Safe Migration Strategy ``` For zero-downtime changes: │ ├── Adding column │ └── Add as nullable → backfill → add NOT NULL │ ├── Removing column │ └── Stop using → deploy → remove column │ ├── Adding index │ └── CREATE INDEX CONCURRENTLY (non-blocking) │ └── Renaming column └── Add new → migrate data → deploy → drop old ``` ## Migration Philosophy - Never make breaking changes in one step - Test migrations on data copy first - Have rollback plan - Run in transaction when possible ## Serverless Databases ### Neon (Serverless PostgreSQL) | Feature | Benefit | |---------|---------| | Scale to zero | Cost savings | | Instant branching | Dev/preview | | Full PostgreSQL | Compatibility | | Autoscaling | Traffic handling | ### Turso (Edge SQLite) | Feature | Benefit | |---------|---------| | Edge locations | Ultra-low latency | | SQLite compatible | Simple | | Generous free tier | Cost | | Global distribution | Performance | # Query Optimization > N+1 problem, EXPLAIN ANALYZE, optimization priorities. ## N+1 Problem ``` What is N+1? ├── 1 query to get parent records ├── N queries to get related records └── Very slow! Solutions: ├── JOIN → Single query with all data ├── Eager loading → ORM handles JOIN ├── DataLoader → Batch and cache (GraphQL) └── Subquery → Fetch related in one query ``` ## Query Analysis Mindset ``` Before optimizing: ├── EXPLAIN ANALYZE the query ├── Look for Seq Scan (full table scan) ├── Check actual vs estimated rows └── Identify missing indexes ``` ## Optimization Priorities 1. **Add missing indexes** (most common issue) 2. **Select only needed columns** (not SELECT *) 3. **Use proper JOINs** (avoid subqueries when possible) 4. **Limit early** (pagination at database level) 5. **Cache** (when appropriate) # ORM Selection (2025) > Choose ORM based on deployment and DX needs. ## Decision Tree ``` What's the context? │ ├── Edge deployment / Bundle size matters │ └── Drizzle (smallest, SQL-like) │ ├── Best DX / Schema-first │ └── Prisma (migrations, studio) │ ├──