27fe957074
Consolidate API gateway service into monorepo. Squashed from https://github.com/cartsnitch/api main (89bacb1). Co-Authored-By: Paperclip <noreply@paperclip.ing>
31 lines
862 B
Python
31 lines
862 B
Python
"""Base model and mixins for all CartSnitch ORM models."""
|
|
|
|
import uuid
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import DateTime, func
|
|
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
|
|
|
|
|
|
class Base(DeclarativeBase):
|
|
"""Base class for all CartSnitch models."""
|
|
|
|
|
|
class TimestampMixin:
|
|
"""Mixin providing created_at / updated_at columns."""
|
|
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), server_default=func.now(), nullable=False
|
|
)
|
|
updated_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False
|
|
)
|
|
|
|
|
|
class UUIDPrimaryKeyMixin:
|
|
"""Mixin providing a UUID primary key."""
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(
|
|
primary_key=True, default=uuid.uuid4, server_default=func.gen_random_uuid()
|
|
)
|