Back to list
lovedragonball

database-management

by lovedragonball

32🍴 4📅 Jan 17, 2026

SKILL.md


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

LevelDescriptionWhen to Use
1NFNo repeating groupsAlways
2NFNo partial dependenciesTransactional data
3NFNo transitive dependenciesMost applications
DenormalizedRedundant dataRead-heavy workloads

Common Patterns

-- One-to-Many
CREATE 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

# Create migration
npx prisma migrate dev --name add_users_table

# Apply to production
npx prisma migrate deploy

# Reset database
npx prisma migrate reset

Drizzle

# Generate migration
npx drizzle-kit generate:pg

# Push to database
npx 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

-- Single column index
CREATE INDEX idx_users_email ON users(email);

-- Composite index (order matters!)
CREATE INDEX idx_posts_user_date ON posts(user_id, created_at);

-- Partial index
CREATE INDEX idx_active_users ON users(email) WHERE active = true;

Common N+1 Problem

// Bad ❌ - N+1 queries
const users = await User.findAll();
for (const user of users) {
  user.posts = await Post.findAll({ where: { userId: user.id } });
}

// Good ✅ - Eager loading
const users = await User.findAll({
  include: [{ model: Post }]
});

ORM Best Practices

PracticeDescription
Use TransactionsWrap related operations
Connection PoolingReuse connections
Soft DeletesUse deleted_at instead of DELETE
Audit FieldsAlways add created_at, updated_at
Use MigrationsNever modify schema manually

Backup & Recovery

# PostgreSQL backup
pg_dump -U user -d database > backup.sql

# PostgreSQL restore
psql -U user -d database < backup.sql

# MySQL backup
mysqldump -u user -p database > backup.sql

Score

Total Score

50/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

Reviews

💬

Reviews coming soon