mohitagw15856/pm-claude-skills/database-schema-design
Claude Code and agent skill by mohitagw15856/pm-claude-skills
- community
Checking that the SKILL.md file is still in the repository.
Document or design a database schema with entity relationships, table definitions, constraints, indexes, and access patterns. Use when asked to design a database, document an existing schema, model entities and relationships, define table structures, plan an index strategy, or produce a data model for review. Produces a structured schema document covering an ER diagram, table DDL definitions, index strategy, access pattern analysis, normalization decisions, and migration notes.
Install
npx vskill@latest install mohitagw15856/pm-claude-skills/database-schema-designSKILL.md
The same SKILL.md was published earlier as mohitagw15856/pm-claude-skills/database-schema-design.
Database Schema Design Skill
Produce a complete database schema design document for a given domain. A schema document is not just a list of tables — it is a record of decisions: what was modelled, how entities relate, which queries the schema is optimised for, and what trade-offs were made.
A good schema design document lets an engineer understand the data model, query it correctly, extend it safely, and write migrations without breaking things.
Required Inputs
Ask for these if not already provided:
- Domain description — what the system does; what business objects are being modelled
- Entities and relationships — the main things in the domain and how they relate (e.g. "a User has many Orders; an Order has many OrderItems; an OrderItem references a Product")
- Expected query patterns — the most important read and write queries (e.g. "fetch all orders for a user, sorted by date"; "look up a product by SKU")
- Database engine — PostgreSQL, MySQL, SQLite, CockroachDB, etc. — this affects DDL syntax and available types
- Expected data volume — approximate row counts, growth rate, and any partitioning needs
- Constraints — any existing conventions, naming standards, or migration constraints to respect
Output Format
Database Schema Design: [Domain / Service Name]
Service: [Name] | Team: [Team name] Author: [Name] | Reviewed by: [Name] Date: [Date] | Database engine: [PostgreSQL X.X / MySQL X.X / etc.] Status: [Draft / Reviewed / Approved]
1. Overview
[2–3 sentences describing the domain being modelled, the scope of this schema, and any key design philosophy (e.g. "this schema prioritises read performance for the customer-facing API over write simplicity", or "designed for eventual migration to multi-tenancy")]
In scope:
- [Entity or subsystem]
- [Entity or subsystem]
Out of scope:
- [e.g. Analytics / reporting tables — separate schema]
- [e.g. Audit log tables — covered in separate design doc]
2. Entity Relationship Diagram
Relationship summary:
| Entity A | Relationship | Entity B | Notes | |
|---|---|---|---|---|
| organisations | has many | users | An org can have many users | |
| users | has many | [table_a] | Soft-deleted on user deletion | |
| [table_a] | has many | [table_b] | Cascade delete | |
| [table_b] | belongs to | [table_a] | Non-nullable FK | |
| [table_c] | many-to-many (via [join_table]) | [table_d] | Join table with metadata |
3. Table Definitions
organisations
[1 sentence describing what this table stores and its role in the domain.]
| Column | Type | Nullable | Default | Notes | |
|---|---|---|---|---|---|
| id | UUID | No | gen_random_uuid() | Surrogate PK — UUID preferred over serial for distributed use | |
| name | VARCHAR(255) | No | — | Display name; not unique | |
| slug | VARCHAR(100) | No | — | URL-safe identifier; unique across all orgs | |
| plan | VARCHAR(50) | No | 'free' | Constrained to known values via CHECK | |
| settings | JSONB | No | {} | Flexible config; avoid for queryable fields | |
| created_at | TIMESTAMPTZ | No | now() | Always use TIMESTAMPTZ, not TIMESTAMP | |
| updated_at | TIMESTAMPTZ | No | now() | Updated via trigger (see below) |
users
[1 sentence describing what this table stores.]
| Column | Type | Nullable | Default | Notes | |
|---|---|---|---|---|---|
| id | UUID | No | gen_random_uuid() | — | |
| org_id | UUID | No | — | FK to organisations; RESTRICT prevents orphaning | |
| VARCHAR(254) | No | — | RFC 5321 max length; unique per org (not globally) | ||
| role | VARCHAR(50) | No | 'member' | Application-level RBAC | |
| deleted_at | TIMESTAMPTZ | Yes | NULL | Soft delete; NULL = active |
Soft delete policy: Rows with deleted_at IS NOT NULL are considered deleted. All application queries MUST filter WHERE deleted_at IS NULL unless explicitly fetching deleted records. Use a view or ORM scope to enforce this.
[table_a]
[Description of what this table models.]
| Column | Type | Nullable | Notes | |
|---|---|---|---|---|
| user_id | UUID | No | CASCADE delete — when user is deleted, their [table_a] rows are too | |
| [field_1] | VARCHAR(255) | No | [Reason for length constraint] | |
| status | VARCHAR(50) | No | State machine: pending → active → archived (no other transitions) | |
| metadata | JSONB | No | [What is stored here and why it's not a typed column] |
[join_table] (Many-to-many)
[Description of the relationship this table represents.]
Why a composite PK: The combination of [table_c]_id + [table_d]_id is the natural key — each association is unique and the primary key doubles as the uniqueness constraint without needing a separate index.
4. Index Strategy
For each table, define which indexes are created and why. Include the query they are designed to serve.
| Table | Index name | Columns | Type | Query served | Notes | |
|---|---|---|---|---|---|---|
| users | users_org_id_idx | (org_id) | B-tree | SELECT * FROM users WHERE org_id = $1 | FK lookup; required for join performance | |
| users | users_email_lower_idx | (lower(email)) | B-tree (functional) | WHERE lower(email) = lower($1) | Case-insensitive email lookup | |
| users | users_active_by_org_idx | (org_id, created_at DESC) | B-tree | WHERE org_id = $1 AND deleted_at IS NULL ORDER BY created_at DESC | Partial index candidate (see below) | |
| [table_a] | [table_a]_user_id_status_idx | (user_id, status) | B-tree | WHERE user_id = $1 AND status = 'active' | Compound — order matters | |
| [table_a] | [table_a]_metadata_gin_idx | metadata | GIN | WHERE metadata @> '{"key": "value"}' | Only add if JSONB queried frequently |
Partial indexes (PostgreSQL):
Index design principles applied:
- FKs that appear in JOIN conditions always have an index
- Compound indexes follow selectivity order: most selective column first
- Functional indexes for case-insensitive lookups
- GIN indexes only where JSONB containment queries are frequent
- Partial indexes for status-filtered queries on large tables
5. Access Pattern Analysis
Document the primary queries this schema is designed to serve. For each, show the query, the indexes used, and any caveats.
AP-1: Fetch all active users for an organisation (paginated)
Frequency: Very high — called on every dashboard load Query:
Index used: users_active_by_org_idx (org_id, created_at DESC) Notes: Use keyset pagination (WHERE created_at < $cursor) at scale; OFFSET degrades past ~10k rows.
AP-2: Look up a user by email (case-insensitive)
Frequency: High — every authentication attempt Query:
Index used: users_email_lower_idx Notes: Returns multiple rows if same email exists across orgs. Application resolves by org context.
AP-3: Fetch [table_a] items for a user by status
Frequency: High Query:
Index used: [table_a]_user_id_status_idx Notes: Compound index covers both filter columns. Status filter must come second in the index because user_id is more selective.
AP-4: [Add further access patterns as needed]
6. Normalization Decisions
Document deliberate choices to normalize or denormalize, with reasoning.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 96 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/database-schema-design/SKILL.md
Popularity
- Repository stars
- 1,502
- Repository forks
- 264
- 7-day trend score
- 35
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 12 Jul 2026, 4 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/mohitagw15856/pm-claude-skills/database-schema-design)