36 lines
1.6 KiB
Python
36 lines
1.6 KiB
Python
|
|
from datetime import datetime
|
||
|
|
|
||
|
|
|
||
|
|
from sqlalchemy import ForeignKey, Integer, JSON, String, UniqueConstraint
|
||
|
|
|
||
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
||
|
|
|
||
|
|
|
||
|
|
from app.models.base import Base, Timestamp, new_id, utcnow
|
||
|
|
|
||
|
|
|
||
|
|
class Submission(Base):
|
||
|
|
__tablename__ = "visual_submissions"
|
||
|
|
__table_args__ = (UniqueConstraint("owner_id", "operation", "key"),)
|
||
|
|
id: Mapped[str] = mapped_column(String(32), primary_key=True, default=new_id)
|
||
|
|
owner_id: Mapped[str] = mapped_column(String(32), ForeignKey("visual_users.id"), index=True)
|
||
|
|
operation: Mapped[str] = mapped_column(String(128))
|
||
|
|
key: Mapped[str] = mapped_column(String(128))
|
||
|
|
payload_schema: Mapped[int] = mapped_column(Integer, default=2)
|
||
|
|
body_hash: Mapped[str] = mapped_column(String(64))
|
||
|
|
request_json: Mapped[dict] = mapped_column(JSON, default=dict)
|
||
|
|
resource_json: Mapped[dict] = mapped_column(JSON, default=dict)
|
||
|
|
status: Mapped[str] = mapped_column(String(32), default="accepted")
|
||
|
|
created_at: Mapped[datetime] = mapped_column(Timestamp, default=utcnow)
|
||
|
|
|
||
|
|
|
||
|
|
class QuotaReservation(Base):
|
||
|
|
__tablename__ = "visual_quota_reservations"
|
||
|
|
id: Mapped[str] = mapped_column(String(32), primary_key=True, default=new_id)
|
||
|
|
owner_id: Mapped[str] = mapped_column(String(32), ForeignKey("visual_users.id"), index=True)
|
||
|
|
operation: Mapped[str] = mapped_column(String(128))
|
||
|
|
units: Mapped[int] = mapped_column(Integer, default=1)
|
||
|
|
bytes_reserved: Mapped[int] = mapped_column(Integer, default=0)
|
||
|
|
released_at: Mapped[datetime | None] = mapped_column(Timestamp, nullable=True)
|
||
|
|
created_at: Mapped[datetime] = mapped_column(Timestamp, default=utcnow)
|