Some checks failed
Aegis CI / lint-and-test (push) Has been cancelled
- Declare __table_args__ on Test with 5 indexes: technique_id, state, created_at, (technique_id,state), (state,created_at) - Declare __table_args__ on AuditLog with 3 indexes: (entity_type,entity_id), timestamp, (entity_type,entity_id,action) - Alembic b024: create only the 2 new indexes (ix_tests_created_at, ix_tests_state_created_at); existing indexes from b005/b018/b019 are preserved - Model index names aligned with existing migration names to prevent duplicates
34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
import uuid
|
|
from sqlalchemy import Column, String, DateTime, ForeignKey, Index, func
|
|
from sqlalchemy.dialects.postgresql import UUID, JSONB
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class AuditLog(Base):
|
|
"""
|
|
Audit log model for tracking all system actions.
|
|
|
|
Records user actions, entity changes, and system events
|
|
for security auditing and compliance purposes.
|
|
"""
|
|
__tablename__ = "audit_logs"
|
|
|
|
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
user_id = Column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=True)
|
|
action = Column(String, nullable=False)
|
|
entity_type = Column(String, nullable=True)
|
|
entity_id = Column(String, nullable=True)
|
|
timestamp = Column(DateTime(timezone=True), server_default=func.now())
|
|
details = Column(JSONB, nullable=True)
|
|
|
|
# Relationships
|
|
user = relationship("User")
|
|
|
|
__table_args__ = (
|
|
Index("ix_audit_logs_entity", "entity_type", "entity_id"),
|
|
Index("ix_audit_logs_timestamp", "timestamp"),
|
|
Index("ix_audit_logs_entity_type_entity_id_action", "entity_type", "entity_id", "action"),
|
|
)
|