Skip to main content
skill CX Codex

database-patterns · yonatangross — Claude Code skill: schema and setup

The database-patterns skill guides schema design, Alembic migrations, and database versioning. It fits work on normalization, migration branches, and schema drift.

MIT 238 installs ★ 305 updated 2026-11-07

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add yonatangross/orchestkit --skill database-patterns -a claude-code
Open on GitHub

What database-patterns does

The skill covers database schema work with Alembic and version control. It helps an agent plan normalized structures, handle data migrations, manage migration branches, and detect differences between environments.

Its rules include SQL and NoSQL design, 1NF–3NF normalization, B-tree, GIN, and HNSW indexes, partial and covering indexes, document embedding, and references. Other sections address changelogs, migration locks, zero-downtime changes, and database selection between PostgreSQL and MongoDB.

It supports Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, and OpenCode. The material is built around Alembic and PostgreSQL rather than replacing their documentation; SQLAlchemy 2.0 async applications are part of the stated scope.

What it helps with

  • design a normalized SQL or NoSQL schema
  • write a batch Alembic data migration
  • resolve a migration branch conflict
  • detect schema drift across environments
  • choose PostgreSQL indexes for a query

Example prompts for the agent

  • Design a normalized schema for the orders and customers tables.
  • Create an Alembic migration that adds a required field without downtime.
  • Check the project for schema drift between environments and suggest a fix.

How to install database-patterns

1Skills CLI (Vercel)

npx skills add yonatangross/orchestkit --skill database-patterns -a claude-code

2Manually: put the files in place

~/.claude/skills/database-patterns/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/database-patterns/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about database-patterns

How do I install database-patterns in Claude Code?

Run npx skills add yonatangross/orchestkit --skill database-patterns -a claude-code, then check ~/.claude/skills/database-patterns/SKILL.md.

What does database-patterns do?

It guides schema design, Alembic migrations, database versioning, schema-drift checks, and SQL or NoSQL design decisions.

Which technologies does database-patterns cover?

The skill covers Alembic, PostgreSQL, SQLAlchemy 2.0 async applications, SQL schemas, and NoSQL patterns. Its database-selection rules compare PostgreSQL with MongoDB.

Source text

SKILL.md · MIT
---
name: database-patterns
license: MIT
compatibility: "Claude Code 2.1.277+."
description: "Schema design, Alembic migrations and database versioning. Use when creating migrations, designing or normalizing schemas, or fixing schema drift."
user-invocable: false
disable-model-invocation: false
targets:
  - library: sqlalchemy
    version: ">=2.1.1"
metadata:
  owner-agent: "database-engineer"
  category: document-asset-creation
  version: "2.0.0"
  author: "OrchestKit"
  complexity: "medium"
  tags: "database, migrations, alembic, schema-design, versioning, postgresql, sql, nosql"
allowed-tools: "Read Glob Grep WebFetch WebSearch"
paths: ["**/migrations/**", "**/models/**", "alembic.ini", "**/schema*"]
path_patterns: ["*.sql", "**/migrations/**", "**/alembic/**", "**/prisma/**"]
---

<!-- directive-density: intentional (teaches migration anti-patterns; NEVER markers describe real production-break conditions, not aspirational guidance) -->

# Database Patterns

Comprehensive patterns for database migrations, schema design, and version management. Each category has individual rule files in `rules/` loaded on-demand.

## Quick Reference

| Category | Rules | Impact | When to Use |
|----------|-------|--------|-------------|
| [Alembic Migrations](#alembic-migrations) | 2 | CRITICAL | Data migrations, branch management |
| [Schema Design](#schema-design) | 3 | HIGH | Normalization, indexing strategies, NoSQL patterns |
| [Versioning](#versioning) | 2 | HIGH | Changelogs, schema drift detection |
| [Zero-Downtime Migration](#zero-downtime-migration) | 2 | CRITICAL | Expand-contract, pgroll, rollback monitoring |

| [Database Selection](#database-selection) | 1 | HIGH | Choosing the right database, PostgreSQL vs MongoDB, cost analysis |

**Total: 10 rules across 5 categories**

This skill is a wrap around Alembic and PostgreSQL, not a replacement for their
docs. Read `references/ork-delta.md` first: it holds the
version floors, corrections and house conventions that upstream does not carry.
Everything in the table below was removed on purpose.

## Upstream coverage (do not restate)

These topics are vendor documentation. Fetch them from the source instead of
re-teaching them here.

| Topic | First-party source |
|-------|--------------------|
| Alembic autogenerate, async `env.py` template, `revision`/`upgrade`/`downgrade`/`history` CLI | https://alembic.sqlalchemy.org/en/latest/autogenerate.html (our one correction to the async template is in `references/ork-delta.md`) |
| Migration branches, merge revisions, tuple `down_revision`, branch labels | https://alembic.sqlalchemy.org/en/latest/branches.html |
| Multi-database `env.py`, batched backfill recipes, migration hooks, environment-conditional migrations | https://alembic.sqlalchemy.org/en/latest/cookbook.html |
| Rollback and data-integrity test harnesses | `references/migration-testing.md` |
| JSONB operators, indexing and storage tradeoffs | https://www.postgresql.org/docs/current/datatype-json.html (normal forms and the house denormalization call stay in `rules/schema-normalization.md`) |
| Full index-type reference and syntax (B-tree, GIN, partial, covering, `CREATE INDEX CONCURRENTLY`, `REINDEX`) | https://www.postgresql.org/docs/current/sql-createindex.html (the house subset we actually apply stays in `rules/schema-indexing.md`) |
| `lock_timeout`, `statement_timeout`, advisory locks during migration | https://www.postgresql.org/docs/current/runtime-config-client.html and `rules/versioning-drift.md` |
| Enum type changes | https://www.postgresql.org/docs/current/datatype-enum.html |
| Table partitioning | https://www.postgresql.org/docs/current/ddl-partitioning.html |
| Trigger functions | https://www.postgresql.org/docs/current/plpgsql-trigger.html |
| Foreign-key cascade semantics | https://www.postgresql.org/docs/current/ddl-constraints.html |
| Temporal and audit-trail tables, CDC change logs, stored-procedure and view versioning | https://www.postgresql.org/docs/18/sql-createtable.html (read `references/ork-delta.md` before assuming these give row history) |
| HNSW and vector index tuning (`m`, `ef_construction`, `hnsw.ef_search`) | https://github.com/pgvector/pgvector |
| Generic pre-deployment, backup and schema-review checklists | https://alembic.sqlalchemy.org/en/latest/tutorial.html |
| Async SQLAlchemy sessions, FastAPI wiring, connection pool tuning | `ork:python-backend` skill |

## Quick Start

```python
# Alembic: Auto-generate migration from model changes
# alembic revision --autogenerate -m "add user preferences"

def upgrade() -> None:
    op.add_column('users', sa.Column('org_id', UUID(as_uuid=True), nullable=True))
    op.execute("UPDATE users SET org_id = 'default-org-uuid' WHERE org_id IS NULL")

def downgrade() -> None:
    op.drop_column('users', 'org_id')
```

```sql
-- Schema: Normalization to 3NF with proper indexing
-- PG18: prefer uuidv7() (time-ordered, better B-tree locality) over gen_random_uuid() (random v4)
CREATE TABLE orders (
    id UUID PRIMARY KEY DEFAULT uuidv7(),
    customer_id UUID NOT NULL REFERENCES customers(id),
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX idx_orders_customer_id ON orders(customer_id);
```

## Alembic Migrations

Migration management with Alembic for SQLAlchemy 2.0 async applications.

| Rule | File | Key Pattern |
|------|------|-------------|
| Data Migration | `rules/alembic-data-migration.md` | Batch backfill, two-phase NOT NULL, zero-downtime |
| Branching | `rules/alembic-branching.md` | Feature branches, merge migrations, conflict resolution |

Autogenerate setup is upstream. Our one deviation from Alembic's async `env.py`
template (the `in_greenlet()` guard) is in `references/ork-delta.md`.

## Schema Design

SQL and NoSQL schema design with normalization, indexing, and constraint patterns.

| Rule | File | Key Pattern |
|------|------|-------------|
| Normalization | `rules/schema-normalization.md` | 1NF-3NF, when to denormalize, JSON vs normalized |
| Indexing | `rules/schema-indexing.md` | B-tree, GIN, HNSW, partial/covering indexes |
| NoSQL Patterns | `rules/schema-nosql.md` | Embed vs reference, document design, sharding |

## Versioning

Database version control and change management across environments.

| Rule | File | Key Pattern |
|------|------|-------------|
| Changelog | `rules/versioning-changelog.md` | Schema version table, semantic versioning, audit trails |
| Drift Detection | `rules/versioning-drift.md` | Environment sync, checksum verification, migration locks |

Rollback testing lives in `references/migration-testing.md`;
the docstring convention for lossy downgrades is in
`references/ork-delta.md`.

## Database Selection

Decision frameworks for choosing the right database. Default: PostgreSQL.

| Rule | File | Key Pattern |
|------|------|-------------|
| Selection Guide | `rules/db-selection.md` | PostgreSQL-first, tier-based matrix, anti-patterns |

## Key Decisions

| Decision | Recommendation | Rationale |
|----------|----------------|-----------|
| Async dialect | `postgresql+asyncpg` | Native async support for SQLAlchemy 2.0 |
| NOT NULL column | Two-phase: nullable first, then alter | Avoids locking, backward compatible |
| Large table index | `CREATE INDEX CONCURRENTLY` | Zero-downtime, no table locks |
| Normalization target | 3NF for OLTP | Reduces redundancy while maintaining query performance |
| Primary key strategy | UUID for distributed, INT for single-DB | Context-appropriate key generation |
| Soft deletes | `deleted_at` timestamp column | Preserves audit trail, enables recovery |
| Migration granularity | One logical change per file | Easier rollback and debugging |
| Production deployment | Generate SQL, review, then apply | Never auto-run in production |

## Anti-Patterns (FORBIDDEN)

```python
# NEVER: Add NOT NULL without default or two-phase approach
op.add_column('users', sa.Column('org_id', UUID, nullable=False))  # LOCKS TABLE!

# NEVER: Use blocking index creation on large tables
op.create_index('idx_large', 'big_table', ['col'])  # Use CONCURRENTLY

# NEVER: Skip downgrade implementation
def downgrade():
    pass  # WRONG - implement proper rollback

# NEVER: Modify migration after deployment - create new migration instead

# NEVER: Run migrations automatically in production
# Use: alembic upgrade head --sql > review.sql

# NEVER: Run CONCURRENTLY inside transaction
op.execute("BEGIN; CREATE INDEX CONCURRENTLY ...; COMMIT;")  # FAILS

# NEVER: Delete migration history
command.stamp(alembic_config, "head")  # Loses history

# NEVER: Skip environments (Always: local -> CI -> staging -> production)
```

## Detailed Documentation

| Resource | Description |
|----------|-------------|
| `references/ork-delta.md` | Our corrections and house conventions. Read this first |
| `references/migration-testing.md` | Upgrade/downgrade cycle and data-integrity test harnesses |
| `references/postgres-vs-mongodb.md` | Head-to-head comparison behind the PostgreSQL-first default |
| `references/db-migration-paths.md` | Cross-engine migration risk matrix |
| `references/cost-comparison.md` | Managed database cost analysis |
| `references/storage-and-cms.md` | Object storage and CMS selection |
| `scripts/` | Migration template, model change detector |

## Zero-Downtime Migration

Safe database schema changes without downtime using expand-contract pattern and online schema changes.

| Rule | File | Key Pattern |
|------|------|-------------|
| Expand-Contract | `rules/migration-zero-downtime.md` | Expand phase, backfill, contract phase, pgroll automation |
| Rollback & Monitoring | `rules/migration-rollback.md` | pgroll rollback, lock monitoring, replication lag, backfill progress |

## Related Skills

- `sqlalchemy-2-async` - Async SQLAlchemy session patterns
- `ork:testing-integration` - Integration testing patterns including migration testing
- `caching` - Cache layer design to complement database performance
- `ork:performance` - Performance optimization patterns

© OrchestKit · MIT · yonatangross/orchestkit

Similar skills

All skills for Data and databases →

database-patterns by other authors comes first.

database-patterns majiayu000 database-patterns guides AI agents on pairing PostgreSQL with Redis: schema types, indexing, JSONB usage, caching strategies, and stampede prevention. CX Codex +1 162installs database-patterns c0x12c database-patterns hands your agent a fixed set of database rules: column types, UUID keys, soft deletes and migration templates. Useful when it writes tables or repositories. CX Codex +1 ★ 111repo stars database-management-patterns manutej database-management-patterns — a reference skill for PostgreSQL and MongoDB work: schema design, indexing, transactions, replication and sharding. CX Codex +1 467installs database-architect davila7 Turns Claude Code into a database architect for greenfield and legacy systems. It guides database selection, schema design, partitioning, and safe migration plans. CX Codex +1 586installs database-cloud-optimization-database-architect Seth Hobson database-cloud-optimization-database-architect designs data layers from scratch and restructures existing schemas. Guides engine selection, indexing, partitioning, and caching strategies. CX Codex ★ 42,780repo stars database-design alirezarezvani database-design is a Claude Code prompt with templates for relational schemas, NoSQL and data warehouses; it asks the model for an ERD, DDL, indexes and a scaling plan. GP ChatGPT ★ 788repo stars database-design-patterns curiositech database-design-patterns guides relational schema design, 3NF normalization, index selection, and zero-downtime migrations using the expand-contract pattern. CX Codex +1 152installs design-database-schema davila7 The design-database-schema command plans database structures around requirements, relationships, and query patterns. Use it to draft a schema or rethink an existing one. CX Codex +1 1,021installs

From the same set86

The whole set →
python-backend python-backend — a skill for Claude Code and Codex providing async Python patterns when editing *.py or package files. Enforces conventions for FastAPI, SQLAlchemy 2.0, and asyncio. CX Codex +1 250installs accessibility accessibility — a Claude Code skill for building accessible web interfaces. It activates for work on screen reader support, keyboard navigation, focus handling, and ARIA components. CX Codex +1 246installs memory-fabric memory-fabric is a Claude Code skill that orchestrates knowledge graph retrieval, parses queries, deduplicates facts, and ranks results. It runs when designing or debugging agent memory mechanics. CX Codex +1 244installs multimodal-llm multimodal-llm — a skill for Claude Code and Codex that routes tasks across vision, speech, and video models. The agent activates it when handling image analysis, audio transcription, or video generation APIs. CX Codex +1 243installs architecture-patterns architecture-patterns enforces clean architecture, backend layer boundaries, and directory limits. Triggers when designing module boundaries or running refactoring tasks. CX Codex +1 236installs performance This skill helps diagnose slow web pages, React renders, backend requests, and LLM inference across a performance review. CX Codex +1 233installs github-operations The github-operations skill handles GitHub issues, pull requests, milestones, and Projects v2 with gh, REST, and GraphQL patterns. It activates for GitHub resource management. CX Codex +1 230installs remember remember is a Claude Code skill that forwards a typed command to memory to store a decision or pattern in a knowledge graph. It runs when /ork:remember is entered. CX Codex +1 229installs

Project sponsors

Companies that keep this analytics open