feat: Phase 6 — alarm system (auto-generate, list, acknowledge)
All checks were successful
Deploy to Production / deploy (push) Successful in 1m17s

- Add Alarm model with tenant/part/machine relationships and 3 indexes
- Add alembic migration c5d6e7f8a9b0_add_alarms
- Add alarms API: list (filter by ack/severity), summary, acknowledge
- Auto-generate alarms on counter update (threshold warning, critical at 100%)
- Duplicate alarm prevention for same part+alarm_type
- Add alarms frontend page with active/acknowledged tabs, summary badges
- 9 new tests (67/67 total passing)

Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
This commit is contained in:
Johngreen
2026-02-10 14:39:03 +09:00
parent 035d62f0e0
commit 843f72e048
10 changed files with 889 additions and 1 deletions

View File

@@ -305,3 +305,33 @@ class InspectionRecord(Base):
),
Index("ix_records_session", "session_id"),
)
class Alarm(Base):
__tablename__ = "alarms"
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
tenant_id = Column(String(50), ForeignKey("tenants.id"), nullable=False)
equipment_part_id = Column(
UUID(as_uuid=True), ForeignKey("equipment_parts.id"), nullable=False
)
machine_id = Column(UUID(as_uuid=True), ForeignKey("machines.id"), nullable=False)
alarm_type = Column(String(30), nullable=False) # threshold | critical
severity = Column(String(20), nullable=False) # warning | critical
message = Column(String(500), nullable=False)
lifecycle_pct_at_trigger = Column(Float, nullable=False)
is_acknowledged = Column(Boolean, default=False)
acknowledged_by = Column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=True)
acknowledged_at = Column(TIMESTAMP(timezone=True), nullable=True)
created_at = Column(TIMESTAMP(timezone=True), default=utcnow)
tenant = relationship("Tenant")
equipment_part = relationship("EquipmentPart")
machine = relationship("Machine")
acknowledged_user = relationship("User")
__table_args__ = (
Index("ix_alarms_tenant_ack", "tenant_id", "is_acknowledged"),
Index("ix_alarms_tenant_severity", "tenant_id", "severity"),
Index("ix_alarms_tenant_part", "tenant_id", "equipment_part_id"),
)