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

ฐานข้อมูล (Database Schema)

เอกสารโครงสร้างฐานข้อมูลของระบบ RLPD Phase 2 — ทุกระบบมี structure เดียวกัน สร้างจาก live DB โดยตรง (scripts/build_db_docs.py)

AI-friendly entry points

  • catalog.json — manifest รวมทุกระบบ + ทุกตาราง (เปิดไฟล์เดียวรู้ว่ามีอะไร อยู่ไหน ย้าย single DB แล้วยัง)
  • <system>/schema.json — โครงสร้างเต็มแบบ machine-readable ต่อระบบ (tables → columns → type/constraint/pk/fk/description) parse ได้ 100%
  • md ทุกไฟล์มี YAML front-matter (system / database / migrated / tables …)

โครงสร้างมาตรฐาน (เหมือนกันทุกระบบ)

docs/database/
  index.md              # หน้านี้
  catalog.json          # manifest รวมทุกระบบ
  legacy_db_inventory.md
  <system>/             # s4_mediation, s5_lawyer, s6_ocipa, s7_witness, s8_website, s9_webportal
    index.md            # overview + table inventory (front-matter)
    schema.json         # machine-readable schema
    data_dict.md        # data dictionary (ทุกคอลัมน์ + คำอธิบาย)
    er_diagram.md       # ER diagram / FK

ทุกระบบ

System DB Host ย้าย single DB? Tables Columns FK มีคำอธิบาย แหล่งคำอธิบาย
S4 Mediation PSDBPRDDB .149 ✅ ใช่ 95 1,911 0 95% docx (curated)
S7 Witness PSDBPRDDB .149 ✅ ใช่ 109 1,475 4 30% live rebuild*
S9 Web Portal PSDBPRDDB .149 ✅ ใช่ 48 437 13 78% docx (curated)
S5 Lawyer 134/1 rlpd_134 .43 ❌ legacy 29 405 0 1% MS_Description
S6 OCIPA RLPD02 .43 ❌ legacy 259 1,570 306 79% MS_Description
S8 Website RLPD_WEB .226 ❌ legacy 81 758 0 42% MS_Description

* S7: docx เดิมเป็น schema อุดมคติ ไม่ตรง DB จริง (~350 phantom columns) จึง rebuild จาก live; คำอธิบาย carry เฉพาะคอลัมน์ที่ชื่อตรงกับ docx (ที่เหลือว่างตามจริง ไม่เดา)

ระบบใหม่ S1/S2/S3 ยังไม่มี schema (กำลังพัฒนาบน single DB)

การย้ายเข้า Single DB

S5/S6/S8 production ยังเดินบน legacy (เขียนข้อมูลจริง) — ดู 🗄️ Legacy DB Inventory สำหรับแผน migrate · ทุกหน้า legacy มี banner "ยังไม่ได้ย้าย"

Schema อื่นใน single DB (นอก 9 ระบบ — ข้ามไปก่อน)

PSDBPRDDB ยังมี ComplaintSystem (13 ตาราง) และ TorturePrevention (25 ตาราง, น่าจะเป็นระบบ พ.ร.บ.ป้องกันการทรมานฯ แยกต่างหาก) — ยังไม่จัดทำเอกสารเพราะไม่อยู่ในกรอบ 9 ระบบ

Regenerate

# โครงสร้าง + คำอธิบาย ต่อระบบ (creds ผ่าน ENV — ไม่ commit รหัสผ่าน)
DB_HOST=... DB_PORT=... DB_NAME=... DB_USER=... DB_PASS=... \
    python3 scripts/build_db_docs.py <S4|S5|S6|S7|S8|S9> 2026-06-14

# ER diagram (single-DB systems)
DB_HOST=... python3 scripts/generate_erd.py <S4|S7|S9>
# ER diagram (legacy systems)
DB_HOST=... python3 scripts/gen_legacy_db_docs.py <slug> "<title>"

# manifest รวม
python3 scripts/build_catalog.py 2026-06-14