| import uuid |
| from datetime import datetime, timezone |
| from sqlalchemy import DateTime, String |
| from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column |
|
|
| class Base(DeclarativeBase): |
| """ |
| Standard SQLAlchemy 2.0 Declarative Base. |
| All models in the application must inherit from this [cite: 1, 166-167, 211]. |
| """ |
| pass |
|
|
| class UUIDMixin: |
| """Provides a standard UUID primary key for models[cite: 1, 211].""" |
| id: Mapped[str] = mapped_column( |
| String(64), |
| primary_key=True, |
| default=lambda: uuid.uuid4().hex |
| ) |
|
|
| class TimestampMixin: |
| """Provides standard created_at and updated_at timestamps[cite: 1, 211].""" |
| created_at: Mapped[datetime] = mapped_column( |
| DateTime(timezone=True), |
| default=lambda: datetime.now(timezone.utc) |
| ) |
| updated_at: Mapped[datetime] = mapped_column( |
| DateTime(timezone=True), |
| default=lambda: datetime.now(timezone.utc), |
| onupdate=lambda: datetime.now(timezone.utc) |
| ) |
|
|