Design schemas, write migrations, optimize queries, manage connections, and implement data access patterns for SQL and NoSQL databases.
Installation
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Identify database stack: Use detect_project and search for config files (knexfile.js, prisma/schema.prisma, sequelize config, .env with DATABASE_URL, mongod refs).
Schema design:
Normalize tables to 3NF for relational DBs
Define proper data types, constraints, and defaults
Add foreign keys with appropriate ON DELETE/UPDATE actions
Create indexes for frequently queried columns
Add created_at/updated_at timestamps with auto-update triggers
Migration management:
Create migration files with UP and DOWN operations
Use the project's migration tool (Knex, Prisma, Sequelize, Alembic, Django)
Name migrations descriptively: 20240101_create_users_table
Always provide rollback logic in DOWN
Query optimization:
Use EXPLAIN/EXPLAIN ANALYZE to check query plans
Add composite indexes for multi-column WHERE clauses
Avoid SELECT * — specify needed columns
Use pagination (LIMIT/OFFSET or cursor-based)
Implement connection pooling
Data access layer:
Repository pattern: one file per entity with CRUD methods
Parameterized queries to prevent SQL injection
Transaction wrappers for multi-step operations
Error handling with specific database error codes
Seeding: Create seed files with realistic test data for development.
NoSQL patterns (if MongoDB/Redis):
Design document schemas with embedded vs referenced relationships