Files
auto-virtual-tryon/app/infra/db/base.py
2026-03-27 00:10:28 +08:00

34 lines
738 B
Python

"""Database base declarations."""
from datetime import datetime, timezone
from sqlalchemy import DateTime
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
def utc_now() -> datetime:
"""Return the current UTC timestamp."""
return datetime.now(timezone.utc)
class Base(DeclarativeBase):
"""Shared declarative base."""
class TimestampMixin:
"""Mixin that adds created and updated timestamps."""
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
default=utc_now,
nullable=False,
)
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
default=utc_now,
onupdate=utc_now,
nullable=False,
)