本文へ移動
cccskills
無料GitHub で公開

database-patterns

Database design patterns including schema design, migrations, soft deletes, and Exposed ORM. Use when creating tables, writing migrations, or implementing repositories.

インストール方法を見る

含まれるファイル(2)

  • SKILL.md2.8 KB
  • code-templates.md3.2 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Database Patterns — Quick Reference

Hard Rules

RuleDoDon't
Data typesTEXTVARCHAR
Primary keysUUIDSERIAL, BIGINT
Soft deletedeleted_at TIMESTAMPDELETE FROM
Foreign keysApp-level validationREFERENCES, ON DELETE CASCADE
Standard columnsid, created_at, updated_at, deleted_atSkip 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

  • NEVER add a migration that fills a gap in deployed sequence
  • NEVER rename an already-deployed migration file
  • Migration numbers must be sequential from the latest
  • Keep migrations simple and focused (one table per migration)

Gotchas

  • Only id uses .value -- everything else is direct. row[Table.id].value gives UUID, but row[Table.projectId] already returns UUID. Adding .value to non-id columns causes compile errors.
  • gen_random_uuid() vs uuid_generate_v4() -- pick one per project. Mixing them works but confuses code review. Check existing migrations for which one the project uses.
  • Don't re-declare createdAt, updatedAt, deletedAt if extending SoftDeleteTable. They're inherited. Declaring them again causes duplicate column errors.
  • Forgetting WHERE deleted_at IS NULL on indexes wastes space. Every index on a soft-delete table should be partial. Full indexes include dead records nobody queries.
  • Text columns that hold JSON should still use text() in Exposed. JSONB in Postgres, text() in Kotlin, serialize/deserialize in the entity layer.

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Creates RPC-style endpoint following layered architecture (Controller → Manager → Repository). Use when creating new API endpoints or CRUD operations.

日本語の概要は準備中です。原文の説明を表示しています。

c0x12c/ai-toolkit1072026年6月18日 更新

Write blog posts, guides, tutorials, and long-form content. Sounds like a real person, not AI. Use when the user wants polished written content.

日本語の概要は準備中です。原文の説明を表示しています。

c0x12c/ai-toolkit1072026年6月18日 更新

Design RPC-style APIs with layered architecture (Controller → Manager → Repository). Use when creating new API endpoints, designing API contracts, or reviewing API patterns.

日本語の概要は準備中です。原文の説明を表示しています。

c0x12c/ai-toolkit1072026年6月18日 更新

Run a structured brainstorm session for startup ideas. Takes a theme or problem and generates ideas with quick gut-checks. Use when the user wants to explore a space or generate new ideas.

日本語の概要は準備中です。原文の説明を表示しています。

c0x12c/ai-toolkit1072026年6月18日 更新

Run real browser QA with Playwright. Use when testing a frontend feature, verifying UI before PR, smoke testing after deploy, or investigating reported visual bugs.

日本語の概要は準備中です。原文の説明を表示しています。

c0x12c/ai-toolkit1072026年6月18日 更新

CI/CD pipeline patterns for GitHub Actions, PR automation, and deployment workflows. Use when setting up CI, fixing broken pipelines, automating PR checks, or configuring deployment.

日本語の概要は準備中です。原文の説明を表示しています。

c0x12c/ai-toolkit1072026年6月18日 更新

c0x12c のスキルをすべて見る

このスキルの問題を報告する