Some checks failed
Build and Run VSTU Public TG bot / build_and_run (push) Failing after 6s
47 lines
2.3 KiB
Python
47 lines
2.3 KiB
Python
from datetime import datetime, timezone
|
|
import enum
|
|
from sqlalchemy import BigInteger, Column, DateTime, String, ForeignKey, Enum as SQLEnum
|
|
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
|
|
from sqlalchemy.ext.asyncio import AsyncAttrs
|
|
|
|
class SubType(enum.Enum):
|
|
GROUP = "group"
|
|
EXCEL = "excel"
|
|
|
|
class Base(AsyncAttrs, DeclarativeBase):
|
|
pass
|
|
|
|
class Chat(Base):
|
|
__tablename__ = "tg_public_bot_chats"
|
|
chat_id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
|
|
name: Mapped[str] = mapped_column(String(255), nullable=True)
|
|
username: Mapped[str] = mapped_column(String(255), nullable=True)
|
|
created_at = Column(DateTime(timezone=True), default=lambda: datetime.now(timezone.utc))
|
|
|
|
subscriptions: Mapped[list["Subscription"]] = relationship(back_populates="user", cascade="all, delete-orphan")
|
|
|
|
|
|
class SentStatus(Base):
|
|
__tablename__ = "tg_public_bot_sent_statuses"
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
sub_id: Mapped[int] = mapped_column(ForeignKey("tg_public_bot_subscriptions.id"))
|
|
guid: Mapped[str] = mapped_column(String(32), nullable=True)
|
|
end_state: Mapped[str] = mapped_column(String(64), nullable=True)
|
|
log: Mapped[str] = mapped_column(String, nullable=True)
|
|
timestamp = Column(DateTime(timezone=True), default=lambda: datetime.now(timezone.utc))
|
|
|
|
|
|
class Subscription(Base):
|
|
__tablename__ = "tg_public_bot_subscriptions"
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
chat_id: Mapped[int] = mapped_column(ForeignKey("tg_public_bot_chats.chat_id"))
|
|
created_by: Mapped[int] = mapped_column(BigInteger, nullable=True)
|
|
sub_type: Mapped[SubType] = mapped_column(SQLEnum(SubType))
|
|
value: Mapped[str] = mapped_column(String(255)) # Имя группы или имя файла?
|
|
human_name: Mapped[str] = mapped_column(String(255)) # Читаемое название (для вывода в /my)
|
|
is_pattern: Mapped[bool] = mapped_column(default=False)
|
|
deleted: Mapped[bool] = mapped_column(default=False)
|
|
message_thread_id: Mapped[int] = mapped_column(BigInteger, nullable=True)
|
|
created_at = Column(DateTime(timezone=True), default=lambda: datetime.now(timezone.utc))
|
|
|
|
user: Mapped["Chat"] = relationship(back_populates="subscriptions") |