from datetime import UTC, datetime from sqlalchemy import Column, DateTime, ForeignKey, Integer from app.core.database import Base class TimestampMixin: """Mixin to add created_at and updated_at timestamps to models""" created_at = Column(DateTime, default=datetime.now(UTC), nullable=False) updated_at = Column( DateTime, default=datetime.now(UTC), onupdate=datetime.now(UTC), nullable=False, ) class SoftDeleteMixin: """Mixin for soft-deletable models. Adds deleted_at and deleted_by_id columns. Records with deleted_at set are automatically excluded from queries via the do_orm_execute event in app.core.database. Use execution_options={"include_deleted": True} to bypass the filter. """ deleted_at = Column(DateTime, nullable=True, index=True) deleted_by_id = Column( Integer, ForeignKey("users.id", ondelete="SET NULL"), nullable=True, )