ข้ามไปที่เนื้อหา

S7 — ระบบคุ้มครองพยาน — Entity Relationship Diagram

แหล่งที่มา

สร้างจาก live production DB (schema WITNESS) + ความสัมพันธ์เชิงตรรกะที่ระบุไว้ใน index.md §4 โดย scripts/generate_erd.py — regenerate ได้ (ดูคำสั่งท้ายหน้า)

  • เส้นทึบ ||--o{ = Explicit FK constraint (บังคับใน DB จริง)
  • เส้นประ ||..o{ = Logical relationship (อนุมานจาก naming/แอป — ไม่มี FK constraint ใน DB)

Explicit Foreign Keys

ระบบนี้มี explicit FK constraint จริง 4 รายการในฐานข้อมูล

erDiagram
    Users ||--o{ Honorable_Meeting_Agenda : "CreatedId"
    PetitionProtection ||--o{ Honorable_Meeting_Agenda : "PetitionId"
    Users ||--o{ Honorable_Meeting_Agenda : "UpdatedId"
    Users_Honorable ||--o{ Honorable_Meeting_Agenda : "UsersHonorableId"
Parent Child Column ON UPDATE ON DELETE
Users Honorable_Meeting_Agenda CreatedId NO_ACTION NO_ACTION
PetitionProtection Honorable_Meeting_Agenda PetitionId NO_ACTION NO_ACTION
Users Honorable_Meeting_Agenda UpdatedId NO_ACTION NO_ACTION
Users_Honorable Honorable_Meeting_Agenda UsersHonorableId NO_ACTION NO_ACTION

Logical Relationships (Entity Relationship Diagram)

แยกตามกลุ่มงาน (functional group) เพื่อให้แต่ละไดอะแกรมอ่านได้ — ความสัมพันธ์เหล่านี้อนุมานจากรูปแบบการตั้งชื่อคอลัมน์ และตรวจสอบแล้วว่าตารางมีอยู่จริงใน live DB

Logical Relationships (No FK Constraint)

erDiagram
    Users ||..o{ UserRoles : "UserId"
    Roles ||..o{ RolesPermission : "RoleId"
    Tm_ProtectionTeam ||..o{ Tm_ProtectionTeamPerson : "ProtectionTeamId"
    Users ||..o{ Tm_ProtectionTeamUser : "UserId"
    Users ||..o{ Notification : "UserId"

⚠️ Validation — ความสัมพันธ์ที่อ้างถึงตารางที่ไม่พบใน DB

รายการต่อไปนี้ระบุไว้ใน index.md แต่ตารางที่อ้างถึงไม่พบใน live DB (อาจเป็น typo, ตารางถูกลบ, หรือชื่อย่อในเอกสาร):

  • Logical Relationships (No FK Constraint): PetitionProtection.CaseTypeId -> CaseType (ไม่พบ: column PetitionProtection.CaseTypeId)
  • Logical Relationships (No FK Constraint): PetitionProtection.OffenseId -> Offense (ไม่พบ: column PetitionProtection.OffenseId)
  • Logical Relationships (No FK Constraint): PetitionProtection.OwnerId -> Users (ไม่พบ: column PetitionProtection.OwnerId)
  • Logical Relationships (No FK Constraint): PetitionProtection.DepartmentId -> Department (ไม่พบ: column PetitionProtection.DepartmentId)
  • Logical Relationships (No FK Constraint): Petitioner.PetitionProtectionId -> PetitionProtection (ไม่พบ: column Petitioner.PetitionProtectionId)
  • Logical Relationships (No FK Constraint): Witness.PetitionProtectionId -> PetitionProtection (ไม่พบ: column Witness.PetitionProtectionId)
  • Logical Relationships (No FK Constraint): Expense.PetitionProtectionId -> PetitionProtection (ไม่พบ: column Expense.PetitionProtectionId)
  • Logical Relationships (No FK Constraint): District.ProvinceId -> Province (ไม่พบ: column District.ProvinceId)
  • Logical Relationships (No FK Constraint): SubDistrict.DistrictId -> District (ไม่พบ: column SubDistrict.DistrictId)
  • Logical Relationships (No FK Constraint): ProtectionTraceCase.PetitionProtectionId -> PetitionProtection (ไม่พบ: column ProtectionTraceCase.PetitionProtectionId)

Regenerate

DB_HOST=<host> DB_PORT=<port> DB_USER=<login> DB_PASS=<pass> \
    python3 scripts/generate_erd.py S7