# database-patterns

Hands your agent a fixed set of database rules: column types, UUID keys, soft deletes and migration templates. Useful when it writes tables or repositories.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · ★ 109
- Author: c0x12c
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/c0x12c/ai-toolkit/tree/HEAD/toolkit/skills/database-patterns/SKILL.md
- Updated: 2026-06-18
- HTML: https://affpapa.org/en/nevibecode/skills/database-patterns

## What it does

The skill feeds the agent a short rulebook for schemas and migrations. The hard rules are blunt: TEXT columns instead of VARCHAR, UUID primary keys instead of SERIAL or BIGINT, soft deletes through a `deleted_at TIMESTAMP` column rather than `DELETE FROM`, and foreign keys validated in application code instead of `REFERENCES` with `ON DELETE CASCADE`. Every table carries `id`, `created_at`, `updated_at` and `deleted_at`.

Templates cover the rest. There is a SQL migration with a table, a trigger and partial indexes for soft deletes, an Exposed table object extending `UUIDTable`, an entity data class implementing `Entity<Instant>`, and a repository laid out as an interface plus a `Default*` implementation. Reads go to `db.replica`, writes to `db.primary`, and a `convert()` method maps `ResultRow` to the entity. A checklist walks through the seven steps of adding a table, from the migration file to repository tests.

A gotchas section catches the usual mistakes. `.value` applies to `id` alone — `row[Table.projectId]` already returns a UUID, so adding `.value` elsewhere breaks compilation. If your entity extends `SoftDeleteTable`, redeclaring `createdAt`, `updatedAt` or `deletedAt` triggers a duplicate column error. Flyway rules are strict too: never fill a gap in a deployed migration sequence, and never rename a migration that has already shipped.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add c0x12c/ai-toolkit --skill database-patterns -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/database-patterns/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/database-patterns/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add c0x12c/ai-toolkit --skill database-patterns -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/database-patterns/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add c0x12c/ai-toolkit --skill database-patterns -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/database-patterns/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install c0x12c/ai-toolkit database-patterns
```

2. **Manually: put the files in place**
- File: `.github/skills/database-patterns/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add c0x12c/ai-toolkit --skill database-patterns -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/c0x12c/ai-toolkit --path toolkit/skills/database-patterns
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/database-patterns/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add c0x12c/ai-toolkit --skill database-patterns -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/c0x12c/ai-toolkit/tree/HEAD/toolkit/skills/database-patterns/SKILL.md

## When to use it
- pick one rule for column and key types
- write a SQL migration with a trigger and partial indexes
- build a repository that reads replicas and writes the primary
- add a table through the seven-step checklist
- separate soft deletes from hard `DELETE` statements

## Example prompts
- Create the projects table following database-patterns
- Write a migration for a new table with soft delete
- Build a repository for this entity reading from `db.replica`

## Similar
- [golang-database-patterns](https://affpapa.org/en/nevibecode/skills/golang-database-patterns.md) — skill · 403 installs
- [database-management-patterns](https://affpapa.org/en/nevibecode/skills/database-management-patterns.md) — skill · 466 installs
- [database-schema-designer](https://affpapa.org/en/nevibecode/skills/database-schema-designer.md) — skill · 692 installs
- [database-architect](https://affpapa.org/en/nevibecode/agents/database-architect.md) — subagent · 12224 installs
- [database-migration](https://affpapa.org/en/nevibecode/skills/bobmatnyc-database-migration.md) — skill · 416 installs
- [create-database-migrations](https://affpapa.org/en/nevibecode/commands/create-database-migrations.md) — command · 329 installs

From the same set: [c0x12c/ai-toolkit](https://affpapa.org/en/nevibecode/by/c0x12c/ai-toolkit.md) — 11 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
