Database Schema Designer
Design production-ready database schemas with best practices built-in.
Quick Start
Just describe your data model:
You'll get a complete SQL schema like:
What to include in your request:
- Entities (users, products, orders)
- Key relationships (users have orders, orders have items)
- Scale hints (high-traffic, millions of records)
- Database preference (SQL/NoSQL) - defaults to SQL if not specified
Triggers
Key Terms
Quick Reference
Process Overview
Commands
Workflow: Start with design schema → iterate with normalize → optimize with add indexes → evolve with migration
Core Principles
Anti-Patterns
Verification Checklist
After designing a schema:
- Every table has a primary key
- All relationships have foreign key constraints
- ON DELETE strategy defined for each FK
- Indexes exist on all foreign keys
- Indexes exist on frequently queried columns
- Appropriate data types (DECIMAL for money, etc.)
- NOT NULL on required fields
- UNIQUE constraints where needed
- CHECK constraints for validation
- created_at and updated_at timestamps
- Migration scripts are reversible
- Tested on staging with production data
<details> <summary><strong>Deep Dive: Normalization (SQL)</strong></summary>
Normal Forms
1st Normal Form (1NF)
2nd Normal Form (2NF)
3rd Normal Form (3NF)
When to Denormalize
</details> <details> <summary><strong>Deep Dive: Data Types</strong></summary>String Types
Numeric Types
Date/Time Types
Boolean
</details> <details> <summary><strong>Deep Dive: Indexing Strategy</strong></summary>When to Create Indexes
Index Types
Composite Index Order
Rule: Most selective column first, or column most queried alone.
Index Pitfalls
</details> <details> <summary><strong>Deep Dive: Constraints</strong></summary>Primary Keys
Foreign Keys
Other Constraints
</details> <details> <summary><strong>Deep Dive: Relationship Patterns</strong></summary>One-to-Many
Many-to-Many
Self-Referencing
Polymorphic
</details> <details> <summary><strong>Deep Dive: NoSQL Design (MongoDB)</strong></summary>Embedding vs Referencing
Embedded Document
Referenced Document
MongoDB Indexes
</details> <details> <summary><strong>Deep Dive: Migrations</strong></summary>Migration Best Practices
Adding a Column (Zero-Downtime)
Renaming a Column (Zero-Downtime)
Migration Template
</details> <details> <summary><strong>Deep Dive: Performance Optimization</strong></summary>Query Analysis
N+1 Query Problem
Optimization Techniques
</details>Extension Points
- Database-Specific Patterns: Add MySQL vs PostgreSQL vs SQLite variations
- Advanced Patterns: Time-series, event sourcing, CQRS, multi-tenancy
- ORM Integration: TypeORM, Prisma, SQLAlchemy patterns
- Monitoring: Query performance tracking, slow query alerts


