Database schema designer

From borghei/Claude-Skills · View interactive version

Database schema designer is an AI agent skill from the GitHub repository borghei/Claude-Skills. Design a new relational schema from product requirements: tables, ORM models, RLS, indexes, migrations and an ERD. Use when modelling a new feature, adding multi-tenancy or soft deletes, or writing Drizzle/Prisma/Alembic schemas.

How to use this skill

Skill file

Database Schema Designer

The agent turns product requirements into a normalized relational schema with the cross-cutting columns, constraints, Row-Level Security, indexes, migrations and generated types the application needs, for PostgreSQL, MySQL or SQLite with Drizzle, Prisma, TypeORM or Alembic.

Core Capabilities

When to Use

Clarify First

Before designing the schema, settle the inputs below. When one is missing or vague and would change the result, ask about it; when it wouldn't, use a sensible default and say which one you used.

Ask about the two or three inputs that matter most for this request, not the whole list. If the user wants a result straight away, produce it and state your assumptions at the top.

Workflow

  1. Model. List the entities, their relationships and cardinalities from the requirements; normalize to 3NF, then denormalize only where a read path needs it and say why.
  2. Add the cross-cutting columns each table needs: id, created_at, updated_at, and where required deleted_at, organization_id, version.
  1. Write the DDL or ORM schema, with a foreign-key index on every FK column, partial indexes for soft-deleted tables, and RLS policies for multi-tenant tables (see references/schema-design-and-security.md).
  2. Validate with schema_validator.py and fix every error; then render the ERD with erd_generator.py and check that it matches the requirements.
  3. Migrate. For a change to an existing schema, diff the two DDL versions with migration_diffr.py, review the forward and rollback SQL, and use the zero-downtime patterns in references/indexes-and-migrations.md for large tables.

Quick Start

python3 scripts/schema_validator.py assets/sample_schema_v1.sql               # warnings only (exit 0)
python3 scripts/schema_validator.py assets/sample_schema_v2.sql               # new table without FK indexes (exit 1)
python3 scripts/migration_diffr.py assets/sample_schema_v1.sql assets/sample_schema_v2.sql   # forward + rollback SQL
python3 scripts/erd_generator.py assets/sample_schema_v2.sql                  # Mermaid ERD

Tools Overview

| Tool | What it does | Key flags | Exit codes |

|------|--------------|-----------|------------|

| scripts/schema_validator.py <file.sql> | Missing PK, sequential PK, FK without index, nullable FK, missing timestamps, soft deletes without a partial index, tables with no index, naming | --json, --strict (warnings fail too) | 0 clean, 1 errors (or warnings with --strict), 2 bad input |

| scripts/migration_diffr.py <old.sql> <new.sql> | Added/removed tables and columns, type and nullability changes, index changes, with rollback | --json, --no-rollback, -o <file> | 0 no differences, 1 differences found, 2 bad input |

| scripts/erd_generator.py <file.sql> | Mermaid erDiagram with PK/FK markers and a table summary | -o <file.mmd>, --json | 0, 2 bad input |

Anti-Patterns

Mistake: Exposing sequential integer IDs in URLs and APIs.

Why it happens: SERIAL is the default in most tutorials.

Instead: Use UUIDv7 or CUID2 for anything that leaves the database; sequential IDs leak volume and invite enumeration.

Mistake: Multi-tenant tables that rely on the application to filter by tenant.

Why it happens: A WHERE organization_id = ? in the repository layer feels sufficient.

Instead: Add RLS policies keyed on the tenant column so a missed filter returns nothing instead of another tenant's rows.

Mistake: Foreign keys without an index.

Why it happens: PostgreSQL does not create one automatically.

Instead: Index every FK column; joins and cascading deletes scan the child table otherwise. schema_validator.py reports each one.

Files

Reference Documentation

Load the reference that matches the task — keep this file lean and pull detail on demand:

Scope & Limitations

This skill covers:

This skill does NOT cover:

Related skills: engineering/database-designer (analysis and index tuning of existing schemas), engineering/migration-architect (cross-service rollout), engineering/api-design-reviewer (API resources from the schema).

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.