File size: 1,195 Bytes
2756f0f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e980186
2756f0f
 
 
 
 
 
fe40b87
2756f0f
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import uuid
from datetime import datetime

from sqlalchemy import BigInteger, CheckConstraint, DateTime, ForeignKey, Index, String, Text, text
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import Mapped, mapped_column

from app.common.base_model import Base, CreatedAtMixin, IdMixin


class Upload(IdMixin, CreatedAtMixin, Base):
    """An object in the bucket. attached_at is set when a session references it; unattached rows are cleaned up."""

    __tablename__ = "uploads"
    __table_args__ = (
        CheckConstraint("kind IN ('video', 'thumbnail', 'audio', 'drill_video', 'image')", name="kind"),
        Index("ix_uploads_unattached_created_at", "created_at", postgresql_where=text("attached_at IS NULL")),
    )

    owner_id: Mapped[uuid.UUID] = mapped_column(
        UUID(as_uuid=True), ForeignKey("accounts.id", ondelete="CASCADE"), index=True
    )
    kind: Mapped[str] = mapped_column(String(12))
    object_key: Mapped[str] = mapped_column(Text, unique=True)
    content_type: Mapped[str] = mapped_column(String(40))
    size_bytes: Mapped[int] = mapped_column(BigInteger)
    attached_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))