feat: auth & admin
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
"""Reusable mapped-column mixins for ORM models."""
|
||||
|
||||
import datetime as dt
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import DateTime, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
|
||||
class UUIDPrimaryKeyMixin:
|
||||
"""``id`` UUID primary key, generated application-side.
|
||||
|
||||
Generating in Python (not a DB default) keeps ids available before flush —
|
||||
important because ``track.id`` is the client-facing ``content_id``.
|
||||
"""
|
||||
|
||||
id: Mapped[uuid.UUID] = mapped_column(primary_key=True, default=uuid.uuid4)
|
||||
|
||||
|
||||
class TimestampMixin:
|
||||
"""``created_at`` / ``updated_at``, server-managed.
|
||||
|
||||
Present on every user-mutable entity for future delta-sync (plan §4).
|
||||
"""
|
||||
|
||||
created_at: Mapped[dt.datetime] = mapped_column(
|
||||
DateTime(timezone=True),
|
||||
server_default=func.now(),
|
||||
nullable=False,
|
||||
)
|
||||
updated_at: Mapped[dt.datetime] = mapped_column(
|
||||
DateTime(timezone=True),
|
||||
server_default=func.now(),
|
||||
onupdate=func.now(),
|
||||
nullable=False,
|
||||
)
|
||||
Reference in New Issue
Block a user