database-patterns
Skill0 starsChanged 5 months agoMITView on GitHub
Database design and migration patterns — SQL/NoSQL schema modeling, normalization, indexing, and versioned migrations. Use when designing schemas or evolving a database safely.
5 other projects use a version of this.
Adopted by
Most recently taken up by
- xsovad06/sovatheir own version, first seen Nov 8, 2026
- jokob-sk/NetAlertXtheir own version, first seen Nov 1, 2026
- netalertx/NetAlertXtheir own version, first seen Nov 1, 2026
- Nadav011/apex-skillstheir own version, first seen Apr 22, 2026
- zebbern/termstacktheir own version, first seen Apr 16, 2026
Other versions5 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 5
- jokob-sk/NetAlertX★ 7.4ksame name
- netalertx/NetAlertX★ 7.4ksame name
- zebbern/termstack★ 4same name
- xsovad06/sova★ 3same name
- Nadav011/apex-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository20 other files it gives its agents.
- context-engineeringSkill
- multi-agent-patternsSkill
- prompt-injection-defenseSkill
- rag-retrievalSkill
- adr-writerSkill
- ci-cdSkill
- playwright-e2eSkill
- structural-searchSkill
- react-server-componentsSkill
- shadcn-uiSkill
- tailwind-v4Skill
- zustand-stateSkill
- accessibilitySkill
- api-designSkill
- debuggingSkill
- security-patternsSkill
- typescript-patternsSkill
- proposal-writerSkill
- task-prioritizationSkill
- sitecore-xmcloudSkill
The file
Files
<!-- 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 | 3 | CRITICAL | Autogenerate, data migrations, branch management |
| Schema Design | 3 | HIGH | Normalization, indexing strategies, NoSQL patterns |
| Versioning | 3 | HIGH | Changelogs, rollback plans, schema drift detection |
| Zero-Downtime Migration | 2 | CRITICAL | Expand-contract, pgroll, rollback monitoring |
| Database Selection | 1 | HIGH | Choosing the right database, PostgreSQL vs MongoDB, cost analysis |
Total: 12 rules across 5 categories
Quick Start
# 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')-- 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 |
| Autogenerate | ${CLAUDE_SKILL_DIR}/rules/alembic-autogenerate.md | Auto-generate from models, async env.py, review workflow |
| Data Migration | ${CLAUDE_SKILL_DIR}/rules/alembic-data-migration.md | Batch backfill, two-phase NOT NULL, zero-downtime |
| Branching | ${CLAUDE_SKILL_DIR}/rules/alembic-branching.md | Feature branches, merge migrations, conflict resolution |
Schema Design
SQL and NoSQL schema design with normalization, indexing, and constraint patterns.
| Rule | File | Key Pattern |
| Normalization | ${CLAUDE_SKILL_DIR}/rules/schema-normalization.md | 1NF-3NF, when to denormalize, JSON vs normalized |
| Indexing | ${CLAUDE_SKILL_DIR}/rules/schema-indexing.md | B-tree, GIN, HNSW, partial/covering indexes |
| NoSQL Patterns | ${CLAUDE_SKILL_DIR}/rules/schema-nosql.md | Embed vs reference, document design, sharding |
Versioning
Database version control and change management across environments.
| Rule | File | Key Pattern |
| Changelog | ${CLAUDE_SKILL_DIR}/rules/versioning-changelog.md | Schema version table, semantic versioning, audit trails |
| Rollback | ${CLAUDE_SKILL_DIR}/rules/versioning-rollback.md | Rollback testing, destructive rollback docs, CI verification |
| Drift Detection | ${CLAUDE_SKILL_DIR}/rules/versioning-drift.md | Environment sync, checksum verification, migration locks |
Database Selection
Decision frameworks for choosing the right database. Default: PostgreSQL.
| Rule | File | Key Pattern |
| Selection Guide | ${CLAUDE_SKILL_DIR}/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)
# 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 |
${CLAUDE_SKILL_DIR}/references/ | Advanced patterns: Alembic, normalization, migration, audit, environment, versioning |
${CLAUDE_SKILL_DIR}/checklists/ | Migration deployment and schema design checklists |
${CLAUDE_SKILL_DIR}/examples/ | Complete migration examples, schema examples |
${CLAUDE_SKILL_DIR}/scripts/ | Migration templates, 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 | ${CLAUDE_SKILL_DIR}/rules/migration-zero-downtime.md | Expand phase, backfill, contract phase, pgroll automation |
| Rollback & Monitoring | ${CLAUDE_SKILL_DIR}/rules/migration-rollback.md | pgroll rollback, lock monitoring, replication lag, backfill progress |
Related Skills
sqlalchemy-2-async- Async SQLAlchemy session patternsork:testing-integration- Integration testing patterns including migration testingcaching- Cache layer design to complement database performanceork:performance- Performance optimization patterns
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

