Accident schema: rename employee_name -> submitter_email (clearer semantic)
Database migration: - ALTER TABLE accidents RENAME COLUMN employee_name TO submitter_email - ALTER TABLE accidents RENAME COLUMN responsible_person TO injured_person - ALTER TABLE accidents RENAME COLUMN employee_id TO injured_person_id Reason: Accident.employee_name contained submitter EMAIL (not staff name), causing confusion when joining with attendance_records.employee_name (real name). New column names are self-documenting. API backward-compat: - All API responses still use "employee_name" / "responsible_person" field names - Internal SQL mapping translates submitter_email/injured_person -> employee_name/responsible_person - Frontend code unchanged Verified: - /api/accident/1 returns employee_name = submitter_email content - /api/accident/records returns 2 records OK (was 500 before fix) - /api/employees/list still returns 12 staff (accident excluded) - Data preserved (1st record id=1 submitter_email = info@scmedical.hk)
This commit is contained in:
+13
-3
@@ -25,19 +25,29 @@ class User(Base):
|
||||
|
||||
|
||||
class Accident(Base):
|
||||
"""意外記錄 Accident Reports
|
||||
|
||||
IMPORTANT — Column naming convention (2026-07-19 cleanup):
|
||||
- submitter_email: The Google Form submitter's email (NOT the injured person)
|
||||
- injured_person: Name of the staff who got hurt (was: responsible_person)
|
||||
- injured_person_id: Employee ID (was: employee_id)
|
||||
|
||||
This naming makes it clear these are different concepts, preventing
|
||||
accidental joins with attendance_records.employee_name (which IS a real name).
|
||||
"""
|
||||
__tablename__ = "accidents"
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
date = Column(Date, nullable=False)
|
||||
time = Column(String(10), nullable=True)
|
||||
location = Column(String(255), nullable=False)
|
||||
employee_name = Column(String(255), nullable=False)
|
||||
employee_id = Column(String(100))
|
||||
submitter_email = Column(String(255), nullable=False)
|
||||
injured_person_id = Column(String(100))
|
||||
department = Column(String(100))
|
||||
description = Column(Text, nullable=False)
|
||||
severity = Column(String(50), nullable=False)
|
||||
medical_report = Column(Text, nullable=True)
|
||||
action_taken = Column(Text, nullable=True)
|
||||
responsible_person = Column(String(255), nullable=True)
|
||||
injured_person = Column(String(255), nullable=True)
|
||||
|
||||
# Excel-derived (Google Form) extra columns (full map) -- 2026-07-18
|
||||
patient_or_staff = Column(Text, nullable=True) # Excel col 8
|
||||
|
||||
Reference in New Issue
Block a user