Database schema design

From Xiaowen-Jiang/agent-enterprise · View interactive version

Database schema design is an AI agent skill from the GitHub repository Xiaowen-Jiang/agent-enterprise. Design normalized database schemas with tables, relationships, indexes, and migrations

How to use this skill

Skill file

Process

  1. Identify entities — Map domain objects to tables (users, orders, products, etc.)
  2. Define relationships — One-to-one, one-to-many, many-to-many
  3. Normalize to 3NF — Eliminate redundancy, ensure each fact is stored once
  4. Choose primary keys — UUID vs auto-increment, composite keys when needed
  5. Design indexes — Based on query patterns (WHERE, JOIN, ORDER BY)
  6. Plan constraints — NOT NULL, UNIQUE, FOREIGN KEY, CHECK
  7. Write migration — CREATE TABLE statements, ALTER TABLE for existing schemas

Output Format

## Schema Design: [Feature/Module Name]

### Entity-Relationship Summary
- User (1) → (N) Order
- Order (N) ← → (N) Product (via order_items)

### Tables

#### users
| Column | Type | Constraints | Notes |
|--------|------|-------------|-------|
| id | UUID | PK | |
| email | VARCHAR(255) | UNIQUE, NOT NULL | Login identifier |
| created_at | TIMESTAMP | NOT NULL, DEFAULT NOW() | |

#### orders
| Column | Type | Constraints | Notes |
|--------|------|-------------|-------|
| id | UUID | PK | |
| user_id | UUID | FK → users.id, NOT NULL | |

### Indexes
- users(email) — unique lookup
- orders(user_id, created_at) — user's recent orders

### Migration SQL
[CREATE TABLE / ALTER TABLE statements]

Guidelines

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.