New: Earn 20% as an AgentAlley affiliate. Share your link and earn on every sale you refer. Join now New: Earn 20% as an affiliate. Join now

Designs relational and document database schemas

Database schema designer

by OneWave-AI · MIT license · ★ 306 on GitHub

Database schema designer cover

Designs relational and document database schemas from requirements or an existing app - tables and collections, keys, relationships, constraints, indexes driven by real query patterns, ERDs, and reversible migration scripts - with…

---
name: database-schema-designer
description: Designs relational and document database schemas from requirements or an existing app - tables and collections, keys, relationships, constraints, indexes driven by real query patterns, ERDs, and reversible migration scripts - with PostgreSQL (including Supabase) as the default and MySQL, SQLite, and MongoDB supported. Use when the user wants to model data for a new app or feature, review or fix an existing schema, choose keys or indexes, plan multi-tenancy, normalize or denormalize, or write CREATE TABLE statements or migrations, even if they just describe their app and ask "how should I store this". For moving data between database providers, use database-migrator.
---

# Database Schema Designer

Design a schema that enforces the data's rules in the database and makes the app's real queries fast.

## Workflow

1. **Collect requirements.** Get from the conversation or codebase, and ask only for what blocks the design:
   - Engine and version (default: PostgreSQL 18; check `docker-compose.yml`, ORM config, or Supabase project if present)
   - Entities and how they relate, in plain language
   - The 5-10 most frequent or most important queries, including filters and sort order
   - Volume and growth (rows per table per year), read/write mix
   - Tenancy (single app, multi-tenant by organization), retention, audit, and compliance needs (PII, deletion requests)
   - ORM or migration tool in use (Prisma, Drizzle, Rails, Django, Alembic, Supabase migrations, plain SQL)

Overview

Design a schema that enforces the data's rules in the database and makes the app's real queries fast.

Manual install (npx, ZIP)
Claude Codenpx skills add OneWave-AI/claude-skills --skill database-schema-designer -g -a claude-code
Claude Code (degit)npx degit OneWave-AI/claude-skills/database-schema-designer#main ~/.claude/skills/database-schema-designer-2
Claude.ai / desktopZip the folder and upload it under Settings → Capabilities → Skills.
Codex, Cursor, other agentsPoint them at SKILL.md. The other files are plain text.

Connects with Agent Alley MCP · agentalley.io/mcp

Files included

  • SKILL.md6.1 KB
Read SKILL.md here
OneWave-AI/main1 file shown
SKILL.md
Show the full text62 lines
database-schema-designer-2/SKILL.md62 lines · 6.1 KB

Database Schema Designer

Design a schema that enforces the data's rules in the database and makes the app's real queries fast.

Workflow

  1. Collect requirements. Get from the conversation or codebase, and ask only for what blocks the design:

    • Engine and version (default: PostgreSQL 18; check docker-compose.yml, ORM config, or Supabase project if present)
    • Entities and how they relate, in plain language
    • The 5-10 most frequent or most important queries, including filters and sort order
    • Volume and growth (rows per table per year), read/write mix
    • Tenancy (single app, multi-tenant by organization), retention, audit, and compliance needs (PII, deletion requests)
    • ORM or migration tool in use (Prisma, Drizzle, Rails, Django, Alembic, Supabase migrations, plain SQL)
  2. Model entities and relationships. List entities, attributes, and cardinality (1:1, 1:N, N:M). Normalize to 3NF by default; denormalize only for a named query that needs it, and say which.

  3. Choose keys and types using references/postgres.md (or references/other-engines.md for MySQL, SQLite, MongoDB). Defaults for Postgres: bigint generated always as identity or uuid DEFAULT uuidv7() primary keys, text over varchar(n), timestamptz for every timestamp, numeric for money.

  4. Encode the rules as constraints. NOT NULL wherever a value is required, UNIQUE for natural keys, CHECK for ranges and allowed values, foreign keys with a deliberate ON DELETE choice for each. Data rules that live only in app code get broken by the next script or admin fix.

  5. Derive indexes from the queries in step 1, not from a checklist. For each query, name the index that serves it. Index every foreign key column you join or cascade on (Postgres does not do this automatically). Do not add an index a UNIQUE or primary key already provides.

  6. Write the deliverable: DDL, ERD, index rationale, and migrations with rollback, using references/schema-templates.md and the layout in references/output-format.md. Match the user's migration tool if they have one.

  7. Verify. If a database is available (local Postgres, Docker postgres:18, a Supabase branch), run the DDL, insert a few rows, and EXPLAIN the key queries to confirm the planned indexes are used. Otherwise, walk each query from step 1 against the schema by hand. Then check the list below.

Checks before delivering

  • Every query from step 1 is served by a stated index or is explained as a scan that is fine at the expected size.
  • Every foreign key has an explicit ON DELETE behavior and an index on the referencing column.
  • No timestamp without time zone; no floating point for money; no varchar(255) by habit.
  • updated_at actually updates: a DEFAULT now() only sets it on insert, so add a trigger or set it in the ORM.
  • Uniqueness that should ignore case (emails, usernames) is enforced case-insensitively.
  • Multi-tenant tables carry tenant_id (or org_id), include it in unique constraints and leading index columns, and have row-level security if the database is reachable from clients (always on Supabase).
  • Migrations that touch large existing tables avoid long locks (see migration safety in references/postgres.md).
  • Rollback scripts are real inverses, and destructive rollbacks (dropping a column with data) are called out.

Worked example

Request: "Multi-tenant project tracker: orgs, users who can belong to several orgs, projects per org, tasks per project. The main screen lists a project's open tasks by due date."

  • Entities: orgs, users, org_members (N:M between users and orgs with a role), projects (N:1 org), tasks (N:1 project, optional assignee).
  • Key query: open tasks for one project ordered by due date, so a partial index ON tasks (project_id, due_at) WHERE status <> 'done'.
  • Rules as constraints: UNIQUE (org_id, user_id) on org_members; CHECK (role IN ('owner','admin','member')); status limited by CHECK; unique project name per org with UNIQUE (org_id, name).
  • Deletes: removing an org cascades to projects and tasks; deleting a user sets tasks.assignee_id to null instead of deleting tasks.
  • Tenancy: tasks carries org_id so row-level security can check membership without a join through projects, and a composite foreign key (project_id, org_id) -> projects (id, org_id) keeps the two consistent.

The full DDL for this example is in references/schema-templates.md.

Failure modes

  • Designing tables before knowing the queries, then indexing every column "just in case". Each index slows every write.
  • Postgres ENUM types for values that will change. Adding a value is easy, but removing or renaming one is painful; a CHECK constraint or lookup table is easier to evolve.
  • Soft deletes (deleted_at) added everywhere by default. They leak into every query and unique constraint. Use them where there is a real restore or audit need, and pair them with partial unique indexes.
  • Polymorphic foreign keys (commentable_type + commentable_id) that the database cannot enforce. Prefer separate nullable FKs with a CHECK that exactly one is set, or separate tables.
  • Storing structured, queried fields inside jsonb. JSON is for sparse or truly variable attributes; anything you filter, join, or constrain on deserves a column.
1---
2name: database-schema-designer
3description: Designs relational and document database schemas from requirements or an existing app - tables and collections, keys, relationships, constraints, indexes driven by real query patterns, ERDs, and reversible migration scripts - with PostgreSQL (including Supabase) as the default and MySQL, SQLite, and MongoDB supported. Use when the user wants to model data for a new app or feature, review or fix an existing schema, choose keys or indexes, plan multi-tenancy, normalize or denormalize, or write CREATE TABLE statements or migrations, even if they just describe their app and ask "how should I store this". For moving data between database providers, use database-migrator.
4---
5 
6# Database Schema Designer
7 
8Design a schema that enforces the data's rules in the database and makes the app's real queries fast.
9 
10## Workflow
11 
121. **Collect requirements.** Get from the conversation or codebase, and ask only for what blocks the design:
13 - Engine and version (default: PostgreSQL 18; check `docker-compose.yml`, ORM config, or Supabase project if present)
14 - Entities and how they relate, in plain language
15 - The 5-10 most frequent or most important queries, including filters and sort order
16 - Volume and growth (rows per table per year), read/write mix
17 - Tenancy (single app, multi-tenant by organization), retention, audit, and compliance needs (PII, deletion requests)
18 - ORM or migration tool in use (Prisma, Drizzle, Rails, Django, Alembic, Supabase migrations, plain SQL)
19 
202. **Model entities and relationships.** List entities, attributes, and cardinality (1:1, 1:N, N:M). Normalize to 3NF by default; denormalize only for a named query that needs it, and say which.
21 
223. **Choose keys and types** using [references/postgres.md](references/postgres.md) (or [references/other-engines.md](references/other-engines.md) for MySQL, SQLite, MongoDB). Defaults for Postgres: `bigint generated always as identity` or `uuid DEFAULT uuidv7()` primary keys, `text` over `varchar(n)`, `timestamptz` for every timestamp, `numeric` for money.
23 
244. **Encode the rules as constraints.** `NOT NULL` wherever a value is required, `UNIQUE` for natural keys, `CHECK` for ranges and allowed values, foreign keys with a deliberate `ON DELETE` choice for each. Data rules that live only in app code get broken by the next script or admin fix.
25 
265. **Derive indexes from the queries in step 1**, not from a checklist. For each query, name the index that serves it. Index every foreign key column you join or cascade on (Postgres does not do this automatically). Do not add an index a `UNIQUE` or primary key already provides.
27 
286. **Write the deliverable**: DDL, ERD, index rationale, and migrations with rollback, using [references/schema-templates.md](references/schema-templates.md) and the layout in [references/output-format.md](references/output-format.md). Match the user's migration tool if they have one.
29 
307. **Verify.** If a database is available (local Postgres, Docker `postgres:18`, a Supabase branch), run the DDL, insert a few rows, and `EXPLAIN` the key queries to confirm the planned indexes are used. Otherwise, walk each query from step 1 against the schema by hand. Then check the list below.
31 
32## Checks before delivering
33 
34- Every query from step 1 is served by a stated index or is explained as a scan that is fine at the expected size.
35- Every foreign key has an explicit `ON DELETE` behavior and an index on the referencing column.
36- No timestamp without time zone; no floating point for money; no `varchar(255)` by habit.
37- `updated_at` actually updates: a `DEFAULT now()` only sets it on insert, so add a trigger or set it in the ORM.
38- Uniqueness that should ignore case (emails, usernames) is enforced case-insensitively.
39- Multi-tenant tables carry `tenant_id` (or `org_id`), include it in unique constraints and leading index columns, and have row-level security if the database is reachable from clients (always on Supabase).
40- Migrations that touch large existing tables avoid long locks (see migration safety in [references/postgres.md](references/postgres.md)).
41- Rollback scripts are real inverses, and destructive rollbacks (dropping a column with data) are called out.
42 
43## Worked example
44 
45Request: "Multi-tenant project tracker: orgs, users who can belong to several orgs, projects per org, tasks per project. The main screen lists a project's open tasks by due date."
46 
47- Entities: `orgs`, `users`, `org_members` (N:M between users and orgs with a `role`), `projects` (N:1 org), `tasks` (N:1 project, optional assignee).
48- Key query: open tasks for one project ordered by due date, so a partial index `ON tasks (project_id, due_at) WHERE status <> 'done'`.
49- Rules as constraints: `UNIQUE (org_id, user_id)` on `org_members`; `CHECK (role IN ('owner','admin','member'))`; `status` limited by `CHECK`; unique project name per org with `UNIQUE (org_id, name)`.
50- Deletes: removing an org cascades to projects and tasks; deleting a user sets `tasks.assignee_id` to null instead of deleting tasks.
51- Tenancy: `tasks` carries `org_id` so row-level security can check membership without a join through `projects`, and a composite foreign key `(project_id, org_id) -> projects (id, org_id)` keeps the two consistent.
52 
53The full DDL for this example is in [references/schema-templates.md](references/schema-templates.md).
54 
55## Failure modes
56 
57- Designing tables before knowing the queries, then indexing every column "just in case". Each index slows every write.
58- Postgres `ENUM` types for values that will change. Adding a value is easy, but removing or renaming one is painful; a `CHECK` constraint or lookup table is easier to evolve.
59- Soft deletes (`deleted_at`) added everywhere by default. They leak into every query and unique constraint. Use them where there is a real restore or audit need, and pair them with partial unique indexes.
60- Polymorphic foreign keys (`commentable_type` + `commentable_id`) that the database cannot enforce. Prefer separate nullable FKs with a `CHECK` that exactly one is set, or separate tables.
61- Storing structured, queried fields inside `jsonb`. JSON is for sparse or truly variable attributes; anything you filter, join, or constrain on deserves a column.
62 
View all files on GitHub →

Details

License
MIT
Stars on the repo
★ 306
Checked
Source
OneWave-AI/claude-skills ↗
Creator
OneWave-AI · 16 listings
View creator

Similar skills

See all →
MCPPostgres server with health checksPostgres MCP Procrystaldba/postgres-mcp · by crystaldbaPostgres server with health checks, index tuning and explain plans, with a restricted read-only mode for production.★ 3.3k GitHub starsSkillPostgres best practices maintained by SupabaseSupabase postgres best practicessupabase/agent-skills · by supabasePostgres best practices maintained by Supabase, for Postgres running anywhere. Load this skill BEFORE writing or changing anything that lives in a Postgres database: creating or altering tables and columns (including choosing column types), schema design, migrations and declarative schema files, RLS policies and the tests that verify them, indexes, triggers, database functions, queues and scheduled jobs (pg_cron, pgmq), vector/semantic search (pgvector), and restoring dumps (pg_restore) or importing data. Also load it when diagnosing slow queries, high CPU, timeouts, EXPLAIN plans, connection exhaustion, locking, bloat, or rows visible to the wrong user or tenant. This is not just a performance guide — schema, migration, security, and SQL authoring tasks need these rules too, even for a one-column change or a single query.★ 2.7k GitHub starsSkillDesigns database schemas, indexing strategiesDatabase designCloudAI-X/claude-workflow-v2 · by CloudAI-XDesigns database schemas, indexing strategies, query optimization, and migration patterns for SQL and NoSQL databases. Use when designing tables, optimizing queries, fixing N+1 problems, planning migrations, or when asked about database performance, normalization, ORMs, or data modeling.★ 1.4k GitHub starsSkillExecute database migrations across ORMsDatabase migrationwshobson/agents · by wshobsonExecute database migrations across ORMs and platforms with zero-downtime strategies, data transformation, and rollback procedures. Use when migrating databases, changing schemas, performing data transformations, or implementing zero-downtime deployment strategies.★ 39.9k GitHub starsSkillOptimize vector index performance for latency, recallVector index tuningwshobson/agents · by wshobsonOptimize vector index performance for latency, recall, and memory. Use when tuning HNSW parameters, selecting quantization strategies, or scaling vector search infrastructure.★ 39.9k GitHub starsSkillDesign database schemas, plan data migrationsDatabase Designer - POWERFUL Tier Skillalirezarezvani/claude-skills · by alirezarezvaniUse when the user asks to design database schemas, plan data migrations, optimize queries, choose between SQL and NoSQL, or model data relationships.★ 26.3k GitHub stars

More from OneWave-AI

SkillFinding security vulnerabilities , correctness bugsCode review proOneWave-AI/claude-skills · by OneWave-AIPerforms a deep code review of files, modules, a diff, or a branch - finding security vulnerabilities (mapped to OWASP Top 10:2025), correctness bugs, performance problems, and maintainability issues - and returns severity-ranked findings with evidence and concrete fixes. Use when the user asks to review, audit, or sanity-check code, asks "is this safe", "what's wrong with this", "find bugs", or wants a security or performance pass before shipping. For posting line comments on a GitHub pull request, use git-pr-reviewer.★ 306 GitHub starsSkillMapping mismatched column names to one schemaCSV/Excel MergerOneWave-AI/claude-skills · by OneWave-AIMerges, appends, joins, and deduplicates multiple CSV, TSV, and Excel files (including multi-sheet workbooks) with pandas - mapping mismatched column names to one schema, normalizing keys, resolving conflicting values, tracking which file each row came from, and verifying the row math. Use when the user wants to combine spreadsheets or exports, stack monthly files, consolidate contact or lead lists, VLOOKUP-style join two sheets on an ID or email, or dedupe records across sources, even if they only say "put these together" or "clean up these lists into one".★ 306 GitHub starsSkillBuild and run a labelled eval set for a System One model Evaluating a typed-decision configOneWave-AI/claude-skills · by OneWave-AIBuild and run a labelled eval set for a System One model (Jev, Von, or any typed-decision config), then sweep criteria wordings and thresholds against it. Use when a Jev/Von classification is wrong or unreliable, when choosing between the hosted API and a local open model, when tuning noul thresholds, or before shipping any typed-decision feature. Produces an accuracy-by-wording matrix and a calibrated threshold.★ 306 GitHub starsSkillExtract and analyze data from invoices, receiptsFinancial Document ParserOneWave-AI/claude-skills · by OneWave-AIExtract and analyze data from invoices, receipts, bank statements, and financial documents. Categorize expenses, track recurring charges, and generate expense reports. Use when user provides financial PDFs or images.★ 306 GitHub starsSkillWrites conversion-focused landing page copyLanding page copywriterOneWave-AI/claude-skills · by OneWave-AIWrites conversion-focused landing page copy - headlines, subheads, value propositions, feature and benefit blocks, social proof, FAQs, and CTA button text - using PAS, AIDA, or StoryBrand. Use when the user wants words for a landing page, sales page, product or pricing page, waitlist page, homepage hero, or ad-to-page flow, including rewriting weak copy, generating headline or CTA variants for A/B tests, or turning a product description into page sections. Use landing-page-optimizer instead for auditing an existing page's performance, and a frontend skill for building the page itself.★ 306 GitHub starsSkillAnalyze meeting transcripts to extract decisionsMeeting Intelligence SystemOneWave-AI/claude-skills · by OneWave-AIAnalyze meeting transcripts to extract decisions, action items, blockers, sentiment, and generate follow-up emails. Use when user provides meeting notes, transcripts, or recordings and needs structured summaries or action tracking.★ 306 GitHub stars