forked from jasima/pali-lili
feat: initial commit
This commit is contained in:
commit
075939142f
63 changed files with 9494 additions and 0 deletions
50
src/models.py
Normal file
50
src/models.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
from sqlalchemy import JSON, DateTime, func, ForeignKey
|
||||
from sqlalchemy.orm import (
|
||||
DeclarativeBase,
|
||||
Mapped,
|
||||
mapped_column,
|
||||
relationship,
|
||||
declared_attr,
|
||||
)
|
||||
|
||||
from src.database import metadata
|
||||
|
||||
|
||||
class CustomBase(DeclarativeBase):
|
||||
type_annotation_map = {
|
||||
datetime: DateTime(timezone=True),
|
||||
dict[str, Any]: JSON,
|
||||
}
|
||||
metadata = metadata
|
||||
|
||||
|
||||
class ActivatedMixin:
|
||||
active: Mapped[bool] = mapped_column(default=True)
|
||||
|
||||
|
||||
class DeletedTimestampMixin:
|
||||
deleted_at: Mapped[datetime | None] = mapped_column(nullable=True)
|
||||
|
||||
|
||||
class DescriptionMixin:
|
||||
description: Mapped[str]
|
||||
|
||||
|
||||
class IdMixin:
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
|
||||
|
||||
class TimestampMixin:
|
||||
created_at: Mapped[datetime] = mapped_column(default=func.now())
|
||||
updated_at: Mapped[datetime] = mapped_column(default=func.now(), onupdate=func.now())
|
||||
|
||||
|
||||
class TofuInstanceMixin:
|
||||
tofu_instance_id: Mapped[int] = mapped_column(ForeignKey("tofu_instance.id"))
|
||||
|
||||
@declared_attr
|
||||
def tofu_instance(cls):
|
||||
return relationship("TofuInstance")
|
||||
Loading…
Add table
Add a link
Reference in a new issue