This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import enum
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import BigInteger, Boolean, DateTime, ForeignKey, Integer, JSON, String, Text
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from .base import Base
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .prize import Prize
|
||||
from .participant import Participant
|
||||
from .winner import Winner
|
||||
|
||||
|
||||
class LotteryStatus(str, enum.Enum):
|
||||
DRAFT = "draft"
|
||||
ACTIVE = "active"
|
||||
DRAWING = "drawing"
|
||||
FINISHED = "finished"
|
||||
CANCELLED = "cancelled"
|
||||
|
||||
|
||||
class Lottery(Base):
|
||||
__tablename__ = "lotteries"
|
||||
|
||||
id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
creator_id: Mapped[int] = mapped_column(BigInteger, ForeignKey("users.id"))
|
||||
title: Mapped[str] = mapped_column(String(255))
|
||||
description: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
status: Mapped[LotteryStatus] = mapped_column(String(20), default=LotteryStatus.DRAFT)
|
||||
target_chat_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
|
||||
target_chat_title: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
require_membership: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
required_chat_ids: Mapped[list | None] = mapped_column(JSON, nullable=True)
|
||||
required_chat_titles: Mapped[list | None] = mapped_column(JSON, nullable=True)
|
||||
required_chat_types: Mapped[list | None] = mapped_column(JSON, nullable=True)
|
||||
required_chat_usernames: Mapped[list | None] = mapped_column(JSON, nullable=True)
|
||||
announcement_targets: Mapped[list | None] = mapped_column(JSON, nullable=True)
|
||||
max_participants: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||||
announcement_message_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
|
||||
contact_info: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
draw_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
auto_draw_count: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||||
allow_multiple_wins: Mapped[bool] = mapped_column(Boolean, default=False, server_default="false")
|
||||
invite_link_chat_ids: Mapped[list] = mapped_column(JSON, default=list, server_default="'[]'")
|
||||
creator_timezone: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
drawn_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
draw_trigger: Mapped[str | None] = mapped_column(String(20), nullable=True)
|
||||
required_chat_passphrases: Mapped[list | None] = mapped_column(JSON, nullable=True)
|
||||
|
||||
prizes: Mapped[list["Prize"]] = relationship(
|
||||
"Prize", back_populates="lottery", order_by="Prize.sort_order", cascade="all, delete-orphan"
|
||||
)
|
||||
participants: Mapped[list["Participant"]] = relationship(
|
||||
"Participant", back_populates="lottery", cascade="all, delete-orphan"
|
||||
)
|
||||
winners: Mapped[list["Winner"]] = relationship(
|
||||
"Winner", back_populates="lottery", cascade="all, delete-orphan"
|
||||
)
|
||||
Reference in New Issue
Block a user