M34: enforce domain integrity in PostgreSQL
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import DateTime, String
|
||||
from sqlalchemy import CheckConstraint, DateTime, Index, String
|
||||
from sqlalchemy.dialects.postgresql import JSONB, UUID
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
@@ -13,6 +13,11 @@ ACTOR_TYPES = ("user", "service", "system")
|
||||
|
||||
class AuditEvent(UUIDPrimaryKeyMixin, Base):
|
||||
__tablename__ = "audit_events"
|
||||
__table_args__ = (
|
||||
CheckConstraint("actor_type IN ('user','service','system')", name="ck_audit_actor_type"),
|
||||
Index("ix_audit_action_occurred", "action", "occurred_at"),
|
||||
Index("ix_audit_entity", "entity_type", "entity_id"),
|
||||
)
|
||||
|
||||
actor_type: Mapped[str] = mapped_column(String(20), nullable=False)
|
||||
actor_id: Mapped[uuid.UUID | None] = mapped_column(UUID(as_uuid=True))
|
||||
|
||||
Reference in New Issue
Block a user