aboutsummaryrefslogtreecommitdiffstats
path: root/thallium-backend/src/orm/base.py
diff options
context:
space:
mode:
authorGravatar Chris Lovering <[email protected]>2024-08-24 23:37:14 +0100
committerGravatar Chris Lovering <[email protected]>2024-08-24 23:37:45 +0100
commit6adc7e46d064a2012059d600e7eff345d5cbcc67 (patch)
tree0ff5625ac8989b64204d47be6cf8329dfef8f334 /thallium-backend/src/orm/base.py
parentMount db migrations as a volume in dev (diff)
Move UUIDBase to its own mixin
Diffstat (limited to 'thallium-backend/src/orm/base.py')
-rw-r--r--thallium-backend/src/orm/base.py7
1 files changed, 6 insertions, 1 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),