diff options
Diffstat (limited to 'thallium-backend/src')
| -rw-r--r-- | thallium-backend/src/orm/base.py | 7 | ||||
| -rw-r--r-- | thallium-backend/src/orm/users.py | 4 | ||||
| -rw-r--r-- | thallium-backend/src/orm/vouchers.py | 4 |
3 files changed, 10 insertions, 5 deletions
diff --git a/thallium-backend/src/orm/base.py b/thallium-backend/src/orm/base.py index ec79d99..5fd70d6 100644 --- a/thallium-backend/src/orm/base.py +++ b/thallium-backend/src/orm/base.py @@ -32,10 +32,15 @@ class Base(AsyncAttrs, DeclarativeBase): setattr(self, key, value) +class UUIDBase: + """Adds a pre-populated UUID as the tables PK.""" + + id: Mapped[UUID] = mapped_column(server_default=text("gen_random_uuid()"), primary_key=True) + + class AuditBase: """Common columns for a table with UUID PK and datetime audit columns.""" - id: Mapped[UUID] = mapped_column(server_default=text("gen_random_uuid()"), primary_key=True) created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now()) updated_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), diff --git a/thallium-backend/src/orm/users.py b/thallium-backend/src/orm/users.py index 8f78387..82c46c0 100644 --- a/thallium-backend/src/orm/users.py +++ b/thallium-backend/src/orm/users.py @@ -1,9 +1,9 @@ from sqlalchemy.orm import Mapped -from .base import AuditBase, Base +from .base import AuditBase, Base, UUIDBase -class User(AuditBase, Base): +class User(UUIDBase, AuditBase, Base): """An authenticated user of the service.""" __tablename__ = "users" diff --git a/thallium-backend/src/orm/vouchers.py b/thallium-backend/src/orm/vouchers.py index 2b3af77..ec0f0df 100644 --- a/thallium-backend/src/orm/vouchers.py +++ b/thallium-backend/src/orm/vouchers.py @@ -3,10 +3,10 @@ from decimal import Decimal from sqlalchemy import Index, text from sqlalchemy.orm import Mapped, mapped_column -from .base import AuditBase, Base +from .base import AuditBase, Base, UUIDBase -class Voucher(AuditBase, Base): +class Voucher(UUIDBase, AuditBase, Base): """A valid voucher in the database.""" __tablename__ = "vouchers" |