agentleFS
Dokkabei97Dokkabei97/forged-claude-code/skills/cto/db-schema-designer/SKILL.md

db-schema-designer

Skill2 starsChanged 9 months agoMITView on GitHub

Designs database schemas from domain model descriptions. Generates ERD, migration scripts, and index strategies for PostgreSQL, MySQL, and MongoDB. Includes Prisma, Drizzle, SQLAlchemy, and raw SQL support.

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Files
SKILL.md

DB Schema Designer - Database Schema Design

Overview

Transforms domain descriptions into optimized database schemas with migrations, indexes, and relationship diagrams.


1. When to Apply

TriggerBehavior
New project data modelingFull schema design workflow
"database schema", "ERD"Interactive schema builder
Adding new entity/tableIncremental schema update

2. Design Workflow

Step 1: Domain Analysis

From user description, extract:

  • Entities: Nouns → tables/collections
  • Relationships: Verbs → foreign keys/references
  • Attributes: Properties → columns/fields
  • Cardinality: one-to-one, one-to-many, many-to-many

Step 2: Schema Generation

Prisma Example:

model User {
  id        String   @id @default(cuid())
  email     String   @unique
  name      String?
  role      Role     @default(USER)
  posts     Post[]
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  @@index([email])
}

model Post {
  id        String   @id @default(cuid())
  title     String
  content   String?
  published Boolean  @default(false)
  author    User     @relation(fields: [authorId], references: [id])
  authorId  String
  tags      Tag[]
  createdAt DateTime @default(now())

  @@index([authorId])
  @@index([published, createdAt])
}

Step 3: Index Strategy

## Index Recommendations

| Table | Index | Type | Reason |
|-------|-------|------|--------|
| users | email | UNIQUE | Login lookup |
| posts | authorId | B-TREE | Filter by author |
| posts | (published, createdAt) | COMPOSITE | Published feed query |
| posts | title | GIN (trigram) | Full-text search |

Step 4: Migration Script

Generate migration for chosen ORM/tool.

Step 5: ERD (Mermaid)

erDiagram
    User ||--o{ Post : writes
    Post }o--o{ Tag : has
    User {
        string id PK
        string email UK
        string name
        enum role
    }
    Post {
        string id PK
        string title
        string content
        boolean published
        string authorId FK
    }

3. Design Principles

  1. Start normalized, denormalize when needed — 3NF first, optimize later
  2. Always add timestamps — createdAt, updatedAt on every table
  3. Use UUIDs/CUIDs for IDs — avoids enumeration attacks
  4. Soft delete when data matters — deletedAt instead of DELETE
  5. Index foreign keys — always index FK columns
  6. Plan for multi-tenancy early — add tenantId if SaaS

4. Tool Coordination

ToolPurpose
WriteGenerate schema files, migrations
ReadAnalyze existing schema
BashRun migrations (npx prisma migrate, alembic upgrade)

5. Boundaries

Will:

  • Design schemas from domain descriptions
  • Generate Prisma/Drizzle/SQLAlchemy models
  • Create migration scripts
  • Recommend index strategies
  • Generate ERD diagrams (Mermaid)

Will Not:

  • Set up database servers
  • Perform data migration between databases
  • Optimize queries (use performance-profiler)
  • Design caching strategies

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.