Skip to content
Back to skills

Database Design

ASecurity

Schema design, migrations, indexing, naming conventions, and query performance. Prevents N+1 queries, missing indexes, and irreversible schema changes.

  • 7 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added May 27, 2026
developmenttypescriptgotestingdatabaseperformance

Security analysis

A100/100

Scanned May 27, 2026

npx -y skills add Vimalk0703/shipworthy --skill database-design --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Database Design?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Database Design
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/vimalk0703-database-design/badge)](https://www.skillsdirectory.com/skills/vimalk0703-database-design)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: database-design
description: Schema design, migrations, indexing, naming conventions, and query performance. Prevents N+1 queries, missing indexes, and irreversible schema changes.
invoke_when: Use when writing schema definitions, creating migrations, adding database queries, or designing data models.
---

# Database Design

## Naming Conventions
- **Tables**: plural, snake_case (`user_profiles`, `order_items`)
- **Columns**: singular, snake_case (`first_name`, `created_at`)
- **Primary keys**: `id`
- **Foreign keys**: `{table_singular}_id` (`user_id`, `order_id`)
- **Timestamps**: always include `created_at` and `updated_at`
- **Booleans**: prefix with `is_` or `has_`

## Data Integrity
- Every foreign key MUST have a constraint
- Use appropriate column types (don't store dates as strings)
- Set NOT NULL on columns that should never be empty
- Use enums/check constraints for fixed value sets

## Migrations
1. Every schema change goes through a migration — never modify DB directly
2. Migrations must be reversible (include `up` and `down`)
3. One concern per migration
4. Name descriptively: `add_email_verification_to_users`

## Indexing
- **Must index**: foreign keys, WHERE clause columns, ORDER BY columns, JOIN columns
- **Avoid**: indexing every column, missing composite indexes, indexing low-selectivity columns

## N+1 Prevention
```typescript
// BAD: 1 + N queries
for (const user of users) {
  user.orders = await db.orders.findByUserId(user.id);
}
// GOOD: 2 queries
const users = await db.users.findAll({ include: ['orders'] });
```

## Rules
- Never query inside a loop
- Set LIMIT on all list queries
- Use pagination for large result sets
- Log slow queries (>100ms)
- Maintain seed data for dev/testing

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.