<< All versions
Skill v1.0.0
currentAutomated scan100/100sir-chawakorn/power-ranger-toolkit/database-management
──Details
PublishedOctober 20, 2026 at 07:38 PM
Content Hashsha256:5cc1fd0335acb660...
Git SHAda26dc2dcc16
──Files
Files (1 file, 2.6 KB)
SKILL.md2.6 KBactive
SKILL.md · 126 lines · 2.6 KB
version: "1.0.0" name: database-management description: Database schema design, migrations, query optimization, and ORM best practices. Use for database setup, performance tuning, and data modeling.
🗄️ Database Management Skill
Schema Design Patterns
Normalization Levels
| Level | Description | When to Use | |
|---|---|---|---|
| 1NF | No repeating groups | Always | |
| 2NF | No partial dependencies | Transactional data | |
| 3NF | No transitive dependencies | Most applications | |
| Denormalized | Redundant data | Read-heavy workloads |
Common Patterns
sql
-- One-to-ManyCREATE TABLE users (id SERIAL PRIMARY KEY, name VARCHAR(100));CREATE TABLE posts (id SERIAL PRIMARY KEY,user_id INTEGER REFERENCES users(id),content TEXT);-- Many-to-Many (Junction Table)CREATE TABLE tags (id SERIAL PRIMARY KEY, name VARCHAR(50));CREATE TABLE post_tags (post_id INTEGER REFERENCES posts(id),tag_id INTEGER REFERENCES tags(id),PRIMARY KEY (post_id, tag_id));
Migration Strategies
Prisma
bash
# Create migrationnpx prisma migrate dev --name add_users_table# Apply to productionnpx prisma migrate deploy# Reset databasenpx prisma migrate reset
Drizzle
bash
# Generate migrationnpx drizzle-kit generate:pg# Push to databasenpx drizzle-kit push:pg
Safe Migration Checklist
- [ ] Backup database first
- [ ] Test on staging environment
- [ ] Plan rollback strategy
- [ ] Run during low-traffic hours
- [ ] Monitor after deployment
Query Optimization
Index Strategies
sql
-- Single column indexCREATE INDEX idx_users_email ON users(email);-- Composite index (order matters!)CREATE INDEX idx_posts_user_date ON posts(user_id, created_at);-- Partial indexCREATE INDEX idx_active_users ON users(email) WHERE active = true;
Common N+1 Problem
javascript
// Bad ❌ - N+1 queriesconst users = await User.findAll();for (const user of users) {user.posts = await Post.findAll({ where: { userId: user.id } });}// Good ✅ - Eager loadingconst users = await User.findAll({include: [{ model: Post }]});
ORM Best Practices
| Practice | Description | |
|---|---|---|
| Use Transactions | Wrap related operations | |
| Connection Pooling | Reuse connections | |
| Soft Deletes | Use deleted_at instead of DELETE | |
| Audit Fields | Always add created_at, updated_at | |
| Use Migrations | Never modify schema manually |
Backup & Recovery
bash
# PostgreSQL backuppg_dump -U user -d database > backup.sql# PostgreSQL restorepsql -U user -d database < backup.sql# MySQL backupmysqldump -u user -p database > backup.sql