@startuml Meeting Service Database Schema
!theme mono

'=== Core Tables ===
entity "meetings" {
  * **meeting_id : VARCHAR(50)
  --
  title : VARCHAR(200) NOT NULL
  purpose : VARCHAR(500)
  description : TEXT
  scheduled_at : TIMESTAMP NOT NULL
  started_at : TIMESTAMP
  ended_at : TIMESTAMP [V3]
  status : VARCHAR(20) NOT NULL
  organizer_id : VARCHAR(50) NOT NULL
  created_at : TIMESTAMP
  updated_at : TIMESTAMP
  template_id : VARCHAR(50)
}

entity "meeting_participants" {
  * **meeting_id : VARCHAR(50) [FK]
  * **user_id : VARCHAR(100)
  --
  invitation_status : VARCHAR(20)
  attended : BOOLEAN
  created_at : TIMESTAMP
  updated_at : TIMESTAMP
}

entity "minutes" {
  * **id : VARCHAR(50)
  --
  meeting_id : VARCHAR(50) [FK] NOT NULL
  user_id : VARCHAR(100) [V3] 
  title : VARCHAR(200) NOT NULL
  status : VARCHAR(20) NOT NULL
  version : INT NOT NULL
  created_by : VARCHAR(50) NOT NULL
  finalized_by : VARCHAR(50)
  finalized_at : TIMESTAMP
  created_at : TIMESTAMP
  updated_at : TIMESTAMP
}

entity "minutes_sections" {
  * **id : VARCHAR(50)
  --
  minutes_id : VARCHAR(50) [FK] NOT NULL
  type : VARCHAR(50) NOT NULL
  title : VARCHAR(200) NOT NULL
  **content : TEXT
  order : INT
  verified : BOOLEAN
  locked : BOOLEAN
  locked_by : VARCHAR(50)
  created_at : TIMESTAMP
  updated_at : TIMESTAMP
}

'=== V3 New Tables ===
entity "agenda_sections" {
  * **id : VARCHAR(36)
  --
  minutes_id : VARCHAR(36) [FK] NOT NULL
  meeting_id : VARCHAR(50) [FK] NOT NULL
  agenda_number : INT NOT NULL
  agenda_title : VARCHAR(200) NOT NULL
  ai_summary_short : TEXT
  discussions : TEXT
  decisions : JSON
  pending_items : JSON
  opinions : JSON
  **todos : JSON [V4]
  created_at : TIMESTAMP
  updated_at : TIMESTAMP
}

entity "ai_summaries" {
  * **id : VARCHAR(36)
  --
  meeting_id : VARCHAR(50) [FK] NOT NULL
  summary_type : VARCHAR(50) NOT NULL
  source_minutes_ids : JSON NOT NULL
  result : JSON NOT NULL
  processing_time_ms : INT
  model_version : VARCHAR(50)
  keywords : JSON
  statistics : JSON
  created_at : TIMESTAMP
}

entity "todos" {
  * **todo_id : VARCHAR(50)
  --
  meeting_id : VARCHAR(50) [FK] NOT NULL
  minutes_id : VARCHAR(50) [FK]
  title : VARCHAR(200) NOT NULL
  description : TEXT
  assignee_id : VARCHAR(50) NOT NULL
  due_date : DATE
  status : VARCHAR(20) NOT NULL
  priority : VARCHAR(20)
  extracted_by : VARCHAR(50) [V3]
  section_reference : VARCHAR(200) [V3]
  extraction_confidence : DECIMAL(3,2) [V3]
  completed_at : TIMESTAMP
  created_at : TIMESTAMP
  updated_at : TIMESTAMP
}

'=== Relationships ===
meetings ||--o{ meeting_participants : "1:N [V2]"
meetings ||--o{ minutes : "1:N"
meetings ||--o{ agenda_sections : "1:N [V3]"
meetings ||--o{ ai_summaries : "1:N [V3]"
meetings ||--o{ todos : "1:N"
minutes ||--o{ minutes_sections : "1:N"
minutes ||--o{ agenda_sections : "1:N [V3]"

'=== Legend ===
legend right
  V2 = Migration 2 (2025-10-27)
  V3 = Migration 3 (2025-10-28)
  V4 = Migration 4 (2025-10-28)
  [FK] = Foreign Key
  **bold** = Important fields
end legend

@enduml
