92 lines
4.7 KiB
Python
92 lines
4.7 KiB
Python
|
|
from datetime import datetime
|
||
|
|
|
||
|
|
from sqlalchemy import DateTime, ForeignKey, Integer, String, Text, UniqueConstraint, func
|
||
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||
|
|
|
||
|
|
from app.database import Base
|
||
|
|
|
||
|
|
|
||
|
|
class VkEvent(Base):
|
||
|
|
__tablename__ = "vk_events"
|
||
|
|
|
||
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||
|
|
event_id: Mapped[str | None] = mapped_column(String(128), index=True)
|
||
|
|
event_type: Mapped[str] = mapped_column(String(64), index=True)
|
||
|
|
group_id: Mapped[str] = mapped_column(String(64), index=True)
|
||
|
|
raw_payload_json: Mapped[str] = mapped_column(Text)
|
||
|
|
status: Mapped[str] = mapped_column(String(32), default="queued", index=True)
|
||
|
|
error_message: Mapped[str | None] = mapped_column(Text)
|
||
|
|
received_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||
|
|
processed_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
|
||
|
|
|
||
|
|
|
||
|
|
class Post(Base):
|
||
|
|
__tablename__ = "posts"
|
||
|
|
__table_args__ = (UniqueConstraint("vk_group_id", "vk_post_id", name="uq_posts_vk_group_post"),)
|
||
|
|
|
||
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||
|
|
vk_group_id: Mapped[str] = mapped_column(String(64), index=True)
|
||
|
|
vk_post_id: Mapped[str] = mapped_column(String(64), index=True)
|
||
|
|
vk_post_url: Mapped[str | None] = mapped_column(Text)
|
||
|
|
text: Mapped[str] = mapped_column(Text, default="")
|
||
|
|
content_key: Mapped[str | None] = mapped_column(String(128), index=True)
|
||
|
|
status: Mapped[str] = mapped_column(String(32), default="pending", index=True)
|
||
|
|
ok_topic_id: Mapped[str | None] = mapped_column(String(128), index=True)
|
||
|
|
publish_lock: Mapped[str | None] = mapped_column(String(128), index=True)
|
||
|
|
error_message: Mapped[str | None] = mapped_column(Text)
|
||
|
|
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||
|
|
published_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
|
||
|
|
|
||
|
|
media: Mapped[list["PostMedia"]] = relationship(back_populates="post", cascade="all, delete-orphan")
|
||
|
|
|
||
|
|
|
||
|
|
class PostMedia(Base):
|
||
|
|
__tablename__ = "post_media"
|
||
|
|
|
||
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||
|
|
post_id: Mapped[int] = mapped_column(ForeignKey("posts.id", ondelete="CASCADE"), index=True)
|
||
|
|
media_type: Mapped[str] = mapped_column(String(32), index=True)
|
||
|
|
vk_attachment_id: Mapped[str | None] = mapped_column(String(128), index=True)
|
||
|
|
source_url: Mapped[str | None] = mapped_column(Text)
|
||
|
|
local_path: Mapped[str | None] = mapped_column(Text)
|
||
|
|
local_cover_path: Mapped[str | None] = mapped_column(Text)
|
||
|
|
ok_media_id: Mapped[str | None] = mapped_column(String(128), index=True)
|
||
|
|
duration_seconds: Mapped[int | None] = mapped_column(Integer)
|
||
|
|
playlist_title: Mapped[str | None] = mapped_column(Text)
|
||
|
|
sort_order: Mapped[int] = mapped_column(Integer, default=0)
|
||
|
|
status: Mapped[str] = mapped_column(String(32), default="pending", index=True)
|
||
|
|
error_message: Mapped[str | None] = mapped_column(Text)
|
||
|
|
|
||
|
|
post: Mapped[Post] = relationship(back_populates="media")
|
||
|
|
|
||
|
|
|
||
|
|
class Video(Base):
|
||
|
|
__tablename__ = "videos"
|
||
|
|
|
||
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||
|
|
vk_video_id: Mapped[str | None] = mapped_column(String(128), index=True)
|
||
|
|
vk_video_url: Mapped[str] = mapped_column(Text)
|
||
|
|
title: Mapped[str | None] = mapped_column(Text)
|
||
|
|
description: Mapped[str | None] = mapped_column(Text)
|
||
|
|
local_video_path: Mapped[str | None] = mapped_column(Text)
|
||
|
|
local_cover_path: Mapped[str | None] = mapped_column(Text)
|
||
|
|
ok_video_id: Mapped[str | None] = mapped_column(String(128), index=True)
|
||
|
|
upload_lock: Mapped[str | None] = mapped_column(String(128), index=True)
|
||
|
|
status: Mapped[str] = mapped_column(String(32), default="pending", index=True)
|
||
|
|
error_message: Mapped[str | None] = mapped_column(Text)
|
||
|
|
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||
|
|
|
||
|
|
|
||
|
|
class PublishJob(Base):
|
||
|
|
__tablename__ = "publish_jobs"
|
||
|
|
|
||
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||
|
|
post_id: Mapped[int] = mapped_column(ForeignKey("posts.id", ondelete="CASCADE"), index=True)
|
||
|
|
celery_task_id: Mapped[str | None] = mapped_column(String(128), index=True)
|
||
|
|
status: Mapped[str] = mapped_column(String(32), default="queued", index=True)
|
||
|
|
attempts: Mapped[int] = mapped_column(Integer, default=0)
|
||
|
|
last_error: Mapped[str | None] = mapped_column(Text)
|
||
|
|
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|