Design Database Auto
Battle-tested command for design, optimized, database, schemas. Includes structured workflows, validation checks, and reusable patterns for setup.
Design Database Auto
Design database schemas with guided selection of database engine, ORM framework, normalization strategy, indexing plan, and optimization techniques based on your project context.
When to Use This Command
Run this command when...
- You are starting a new project and need to choose between PostgreSQL, SQLite, Neon, or Turso for your database
- You need to design a normalized schema with proper primary keys, relationships, and constraints
- You want guidance on selecting an ORM (Drizzle, Prisma, or Kysely) based on your project requirements
- You need to plan indexing strategies for query performance including composite and partial indexes
- You want to avoid common anti-patterns like unnecessary JSON columns, missing indexes, and N+1 queries
Quick Start
# .claude/commands/design-database-auto.yaml name: Design Database Auto description: Guided database design with engine, ORM, and schema selection inputs: - name: context description: "Project description and requirements" - name: preference description: "Database preference if any" default: ""
# Design database for a new SaaS application claude "design-database-auto 'multi-tenant SaaS with user teams and billing'" # Design with a specific database preference claude "design-database-auto 'blog platform' --preference sqlite"
Output:
[analyze] Project type: Multi-tenant SaaS
[recommend] Database: PostgreSQL (multi-tenant, relational data)
[recommend] ORM: Drizzle (type-safe, lightweight)
[schema] Designed 8 tables with relationships:
users, teams, team_members, subscriptions,
invoices, permissions, audit_log, settings
[index] 12 indexes recommended (3 composite)
[review] Anti-pattern check: passed
Done. Schema design saved to schema-design.md
Core Concepts
| Concept | Description |
|---|---|
| Database Selection | Context-aware recommendation: PostgreSQL for complex queries, SQLite for simplicity, Neon/Turso for serverless |
| ORM Selection | Drizzle for type safety and performance, Prisma for developer experience, Kysely for SQL-first teams |
| Schema Normalization | Applies 3NF normalization while recognizing practical denormalization for read-heavy workloads |
| Index Planning | Recommends B-tree, hash, GIN, and composite indexes based on expected query patterns |
| Anti-Pattern Detection | Flags common mistakes: SELECT *, JSON overuse, missing foreign keys, N+1 query patterns |
Decision Flow:
ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ
β Project ββββ>β Database ββββ>β ORM β
β Context β β Selection β β Selection β
ββββββββββββββββ ββββββββββββββββ ββββββββ¬ββββββββ
β
ββββββββΌββββββββ
β Schema β
β Design β
ββββββββ¬ββββββββ
β
βββββββββββββββΌβββββββββββ
βΌ βΌ βΌ
ββββββββββ βββββββββββ ββββββββββ
βIndexes β β Review β βOptimizeβ
ββββββββββ βββββββββββ ββββββββββ
Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
context | string | required | Project description, requirements, and expected data patterns |
preference | string | "" | Preferred database: postgres, sqlite, neon, turso (overrides recommendation) |
orm | string | "" | Preferred ORM: drizzle, prisma, kysely (overrides recommendation) |
scale | string | "medium" | Expected scale: small (< 10K rows), medium, large (millions+), or massive |
environment | string | "server" | Deployment: server, serverless, edge, or embedded |
Best Practices
- Start with context, not technology -- Describe your project requirements first and let the command recommend a database. Avoid defaulting to PostgreSQL when SQLite or Turso might be simpler and sufficient.
- Plan indexes based on queries, not schema -- Write your most common queries first, then design indexes to support them. The command suggests indexes but you know your access patterns best.
- Normalize first, denormalize deliberately -- Start with 3NF and only denormalize specific tables when you have measured performance bottlenecks that justify the data redundancy.
- Use EXPLAIN ANALYZE on generated schemas -- After creating tables, run representative queries with EXPLAIN ANALYZE to verify that indexes are actually being used by the query planner.
- Review the anti-pattern report -- The command flags common mistakes. Address each flagged item before proceeding with implementation, especially JSON columns and missing foreign keys.
Common Issues
- Choosing the wrong database for serverless -- Traditional PostgreSQL connections exhaust pool limits in serverless environments. The command recommends Neon or Turso for serverless deployments where connection pooling is limited.
- Over-indexing small tables -- Adding indexes to tables with fewer than 1,000 rows can slow writes without improving reads. Let the command's scale parameter guide index recommendations.
- ORM lock-in concerns -- Choosing an ORM is a significant commitment. The command explains trade-offs but the final decision should involve the team, considering migration effort and learning curve.
Reviews
No reviews yet. Be the first to review this template!
Similar Templates
Git Commit Message Generator
Generates well-structured conventional commit messages by analyzing staged changes. Follows Conventional Commits spec with scope detection.
React Component Scaffolder
Scaffolds a complete React component with TypeScript types, Tailwind styles, Storybook stories, and unit tests. Follows project conventions automatically.
CI/CD Pipeline Generator
Generates GitHub Actions workflows for CI/CD including linting, testing, building, and deploying. Detects project stack automatically.