database-operations
Drizzle ORMを使用したデータベース操作を支援。スキーマ変更、マイグレーション、シードデータ投入、DBリセットで使用。トリガー例:「DBを更新」「スキーマ変更」「テーブル追加」「カラム追加」「シード実行」「マイグレーション」
When & Why to Use This Skill
This Claude skill streamlines database management workflows using Drizzle ORM and PostgreSQL. It automates complex tasks such as schema modifications, database migrations, seed data population, and environment resets, ensuring a consistent and efficient development-to-production pipeline.
Use Cases
- Schema Evolution: Effortlessly update database structures by adding new tables or columns and synchronizing them with the live database using Drizzle Kit.
- Development Environment Reset: Quickly wipe and re-initialize local databases with fresh seed data to maintain a clean testing state.
- Production Migration Management: Generate and execute safe, version-controlled migration scripts to deploy database changes to production environments without data loss.
- Full-Stack Consistency: Ensure that Zod schemas, API routes, and seed files remain synchronized with database changes through automated checklists and structured procedures.
| name | database-operations |
|---|---|
| description | Drizzle ORMを使用したデータベース操作を支援。スキーマ変更、マイグレーション、シードデータ投入、DBリセットで使用。トリガー例:「DBを更新」「スキーマ変更」「テーブル追加」「カラム追加」「シード実行」「マイグレーション」 |
Database Operations
Drizzle ORM + PostgreSQL。設定は db/ ディレクトリに集約。
コマンド
| コマンド | 説明 |
|---|---|
make db-reset |
DB完全リセット(ボリューム削除→スキーマ適用→シード) |
make db |
PostgreSQLコンテナ起動 |
pnpm db:push |
スキーマ変更をDBに反映 |
pnpm db:seed |
シードデータ投入 |
pnpm db:studio |
Drizzle Studio起動 |
スキーマ変更手順
db/schema.tsを編集db/seed.tsを更新(新カラムに対応)make db-resetを実行
// db/schema.ts 例
export const destinationsTable = pgTable("destinations", {
id: bigserial("id", { mode: "number" }).primaryKey(),
slug: varchar("slug", { length: 255 }).notNull().unique(),
nameJp: varchar("name_jp", { length: 255 }).notNull(),
});
本番マイグレーション
開発環境は make db-reset で完全リセット。本番環境はマイグレーション使用:
# マイグレーション生成
pnpm drizzle-kit generate --config db/drizzle.config.ts
# マイグレーション実行
pnpm drizzle-kit migrate --config db/drizzle.config.ts
関連ファイル更新チェックリスト
スキーマ変更時は以下も確認:
-
db/seed.ts- シードデータ -
shared/src/schemas/entities/- Zodスキーマ -
backend/src/routes/- APIでのカラム参照
トラブルシューティング
エラーが発生した場合は troubleshooting.md を参照。