データベース設計の自動生成とDB設計例

Kiroによるデータベース設計の自動化プロセス

1

要件定義からデータ構造抽出

Kiroがrequirements.mdから必要なエンティティと属性を識別し抽出

2

リレーションシップの自動定義

エンティティ間の関係性(1対多、多対多など)を自動分析・提案

3

ER図の生成

関連性を可視化したER図とドキュメントを自動生成

4

モデル・マイグレーション生成

PostgreSQL用のスキーマ定義とマイグレーションファイルを作成

設計書サンプル - design.md

## データモデル

### User(ユーザー)
id: bigint (主キー)
name: string
email: string (ユニーク)
password: string
created_at: timestamp
updated_at: timestamp

### Product(商品)
id: bigint (主キー)
name: string
description: text
price: decimal(10,2)
category: string
eco_score: integer
image_url: string
stock: integer
created_at: timestamp
updated_at: timestamp

### Order(注文)
id: bigint (主キー)
user_id: bigint (外部キー)
status: enum('pending', 'paid', 'shipped', 'delivered')
total_amount: decimal(10,2)
shipping_address: text
payment_method: string
created_at: timestamp
updated_at: timestamp

Kiroは自動生成後も人間のフィードバックを取り入れ、設計を反復改善します

EcoMarketのDBモデル例

User id: bigint (PK) name: string email: string (unique) password: string Product id: bigint (PK) name: string description: text price: decimal(10,2) category: string eco_score: integer Order id: bigint (PK) user_id: bigint (FK) status: enum total_amount: decimal created_at: timestamp OrderItem id: bigint (PK) order_id: bigint (FK) product_id: bigint (FK) quantity: integer

設計の自動最適化ポイント

  • インデックス設定の自動提案(email, category, created_at フィールド)
  • 適切な外部キー制約と参照整合性の設定
  • データ型の最適化(価格は decimal 型を推奨)
  • 第三正規形(3NF)への適合性確認

Kiroによって設計されたデータベースモデルは、一貫性と拡張性を確保。要件変更時も素早く適応可能。

SE向けAI開発技術レクチャーシリーズ

© 2025 Tech Innovation Team