cloud-api/src/models.py

38 lines
850 B
Python
Raw Normal View History

2026-04-06 12:41:49 +01:00
"""
Global database models
"""
2026-06-20 18:42:36 +01:00
from datetime import datetime
from typing import Any
2026-06-22 13:23:06 +01:00
from sqlalchemy import DateTime, JSON, func
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
2026-06-20 18:42:36 +01:00
class CustomBase(DeclarativeBase):
2026-06-22 15:04:11 +01:00
type_annotation_map = {
datetime: DateTime(timezone=True),
dict[str, Any]: JSON,
}
2026-06-22 13:23:06 +01:00
class ActivatedMixin:
2026-06-22 15:04:11 +01:00
active: Mapped[bool] = mapped_column(default=True)
2026-06-22 13:23:06 +01:00
class DeletedTimestampMixin:
2026-06-22 15:04:11 +01:00
deleted_at: Mapped[datetime | None] = mapped_column(nullable=True)
2026-06-22 13:23:06 +01:00
class DescriptionMixin:
2026-06-22 15:04:11 +01:00
description: Mapped[str]
2026-06-22 13:23:06 +01:00
class IdMixin:
2026-06-22 15:04:11 +01:00
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
2026-06-22 13:23:06 +01:00
class TimestampMixin:
2026-06-22 15:04:11 +01:00
created_at: Mapped[datetime] = mapped_column(default=func.now())
updated_at: Mapped[datetime] = mapped_column(default=func.now(), onupdate=func.now())