Database patterns

From c0x12c/ai-toolkit · View interactive version

Database patterns is an AI agent skill from the GitHub repository c0x12c/ai-toolkit. Database design patterns including schema design, migrations, soft deletes, and Exposed ORM. Use when creating tables, writing migrations, or implementing repositories.

How to use this skill

Skill file

Database Patterns — Quick Reference

Hard Rules

| Rule | Do | Don't |

|------|------|-------|

| Data types | TEXT | VARCHAR |

| Primary keys | UUID | SERIAL, BIGINT |

| Soft delete | deleted_at TIMESTAMP | DELETE FROM |

| Foreign keys | App-level validation | REFERENCES, ON DELETE CASCADE |

| Standard columns | id, created_at, updated_at, deleted_at | Skip any of these |

Migration Template

SQL migration with table, trigger, and partial indexes for soft delete.

See code-templates.md for the complete SQL template.

Exposed Table Object

Extend UUIDTable, use text() not varchar(), add standard timestamp columns.

See code-templates.md for the complete template.

Entity Data Class

Implement Entity<Instant>, include all business fields + createdAt, updatedAt, deletedAt.

See code-templates.md for the complete template.

Repository Pattern

Interface + Default* implementation. Reads on db.replica, writes on db.primary. Soft delete via deletedAt update. convert() method maps ResultRow to entity.

See code-templates.md for the full interface + implementation code.

When Creating a New Table

Full checklist:

  1. SQL migration file (next number in sequence)
  2. Table object in module-repository/table/
  3. Entity data class in module-repository/entity/
  4. Enum/constants in module-repository/constant/ (if needed)
  5. Repository interface + implementation
  6. Factory bean for repository
  7. Repository tests

Flyway Rules

Gotchas

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.