users
├── id (UUID, PK)
├── name (VARCHAR)
├── email (VARCHAR, UNIQUE)
├── role (ENUM: admin, employee)
├── password_hash (VARCHAR)
├── is_active (BOOLEAN, DEFAULT true)
├── must_change_password (BOOLEAN, DEFAULT true) ← 初回ログイン強制変更フラグ
├── created_at (TIMESTAMP)
└── updated_at (TIMESTAMP)
categories
├── id (UUID, PK)
├── name (VARCHAR)
├── description (TEXT)
├── is_restricted (BOOLEAN, DEFAULT false) ← 将来のアクセス制御拡張ポイント
├── created_at (TIMESTAMP)
└── updated_at (TIMESTAMP)
documents
├── id (UUID, PK)
├── title (VARCHAR)
├── category_id (FK → categories.id)
├── current_version_id (FK → document_versions.id, nullable)
├── created_by (FK → users.id)
├── created_at (TIMESTAMP)
└── updated_at (TIMESTAMP)
document_versions
├── id (UUID, PK)
├── document_id (FK → documents.id)
├── content (TEXT) -- 抽出済みテキスト
├── content_tsv (TSVECTOR) -- PostgreSQL全文検索用(GIN index)
├── file_path (VARCHAR) -- UUID形式の相対パス(絶対パス禁止)
├── file_type (ENUM: pdf, docx, xlsx, text)
├── version_no (INTEGER)
├── change_summary (TEXT) -- 変更概要(任意)
├── ingestion_status (ENUM: pending, processing, completed, failed) ← 追加
├── ingestion_error_message (TEXT, nullable) ← 追加
├── created_by (FK → users.id)
├── created_at (TIMESTAMP)
└── updated_at (TIMESTAMP)
chat_sessions
├── id (UUID, PK)
├── user_id (FK → users.id)
├── title (VARCHAR, nullable) -- セッション一覧表示用(最初の質問から自動生成)
├── created_at (TIMESTAMP)
└── updated_at (TIMESTAMP)
chat_messages
├── id (UUID, PK)
├── session_id (FK → chat_sessions.id)
├── role (ENUM: user, assistant)
├── content (TEXT) -- テキスト回答
├── mermaid_content (TEXT, nullable) -- Mermaid図(別カラムで保存)
├── sources_json (JSONB, nullable) -- 引用元情報
├── created_at (TIMESTAMP)
└── updated_at (TIMESTAMP)
audit_logs ← 新規追加(監査・コンプライアンス対応)
├── id (UUID, PK)
├── user_id (FK → users.id, nullable) -- 未ログイン操作も記録可
├── action (ENUM: login, logout, document_view, document_upload,
│ document_update, document_delete, chat_query, user_create,
│ user_update, user_delete, version_restore)
│ -- document_view は任意記録(大量ログ懸念あり・Phase 4 実装時に要否判断)
├── target_id (UUID, nullable) -- 操作対象のリソースID
├── target_type (VARCHAR, nullable) -- 'document' / 'user' / 'category' 等
├── ip_address (VARCHAR)
├── created_at (TIMESTAMP)
└── (updated_atなし:監査ログは不変)