mirror of
https://github.com/duthaho/claudekit.git
synced 2026-06-13 05:34:56 +03:00
3.7 KiB
3.7 KiB
name, description
| name | description |
|---|---|
| databases | Use when working with PostgreSQL, MongoDB, or Redis — including schema design, queries, indexing, migrations, connection pooling, caching layers, or any database operation. Also activate for keywords like SQL, aggregation pipeline, BSON, ioredis, alembic, prisma migrate, django migrate, EXPLAIN ANALYZE, ORM configuration, or NoSQL data modeling. |
Databases
When to Use
- PostgreSQL database operations, SQL query optimization, schema design
- JSONB document storage, full-text search, window functions, CTEs
- MongoDB document modeling, aggregation pipelines, semi-structured data
- Redis caching, session storage, rate limiting, pub/sub, job queues, distributed locks
- Database migrations — adding/modifying tables, columns, indexes, constraints
- Resolving migration conflicts, rolling back failed migrations
When NOT to Use
- Simple key-value caching within a single process — use
functools.lru_cacheorMap - File-based storage that doesn't need a database engine
- Static data or configuration that belongs in environment variables
Quick Reference
| Topic | Reference | Key tools |
|---|---|---|
| PostgreSQL | references/postgresql.md |
SQL, SQLAlchemy, Prisma, EXPLAIN ANALYZE, pg_stat_statements |
| MongoDB | references/mongodb.md |
Aggregation, Mongoose, Motor, document schemas, ESR indexing |
| Redis | references/redis.md |
Caching, pub/sub, ioredis, BullMQ, session storage, distributed locks |
| Migrations | references/migrations.md |
Alembic, Prisma Migrate, Django migrations, rollback strategies |
Best Practices
- Use parameterized queries everywhere. Never concatenate user input into SQL strings.
- Design schema around access patterns. Ask "how will I read this?" before "how does this relate?" Embed data fetched together (MongoDB); normalize data accessed independently (PostgreSQL).
- Index foreign keys and query fields. PostgreSQL doesn't auto-index FK child columns. MongoDB queries without indexes trigger full collection scans.
- Use appropriate consistency levels.
TIMESTAMPTZoverTIMESTAMP(PostgreSQL).w: "majority"for durable writes (MongoDB). TTLs on every Redis cache key. - Monitor query performance.
pg_stat_statements(PostgreSQL),db.setProfilingLevel(1)(MongoDB), connection pool metrics (all). - Use bulk/batch operations.
bulkWrite(MongoDB),COPY(PostgreSQL), pipelines (Redis) for high-throughput writes. - Never edit deployed migrations. Create a new migration instead of modifying one already applied.
- Test rollback paths. Always verify your downgrade/rollback strategy before deploying schema changes.
Common Pitfalls
- N+1 queries from ORM lazy loading. Use eager loading (
joinedload,select_related,$lookupwith caution). - Table locks during migrations. Use
CREATE INDEX CONCURRENTLY(PostgreSQL). Batch backfills for large tables. - Unbounded growth. Dead tuples from UPDATE-heavy workloads (PostgreSQL). Arrays exceeding 16MB document limit (MongoDB). Redis keys without TTLs.
- OFFSET pagination on large datasets. Use keyset/cursor pagination instead.
- Connection exhaustion. Use connection pools (PgBouncer, application-level pools). Never open per-request connections.
- Cache stampede. When a popular Redis key expires, many requests hit the DB simultaneously. Use distributed locks or stale-while-revalidate.
- Running
migrate resetin production. This drops all data.
Related Skills
backend-frameworks— Framework-specific ORM integrationerror-handling— Database error handling patternslogging— Query logging and slow query detection