feat(db): all domain models, initial Alembic migration (32 tables), seed script (8 districts, 89 regions, roles)
This commit is contained in:
1 parent
71460ab56a
commit
4a610ba94a
19 files changed
+1290
-2
No files matched your search
@@ -0,0 +1,65 @@
|
||||
"""Модели рассылок."""
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import (
|
||||
DateTime,
|
||||
ForeignKey,
|
||||
JSON,
|
||||
String,
|
||||
Text,
|
||||
UniqueConstraint,
|
||||
func,
|
||||
)
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.db.session import Base
|
||||
from app.models.enums import BroadcastStatus, BroadcastType, RecipientStatus
|
||||
from app.models.types import enum_col
|
||||
|
||||
|
||||
class BroadcastTemplate(Base):
|
||||
__tablename__ = "broadcast_templates"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
code: Mapped[str] = mapped_column(String(64), unique=True)
|
||||
name: Mapped[str] = mapped_column(String(200))
|
||||
type: Mapped[BroadcastType] = mapped_column(enum_col(BroadcastType))
|
||||
body_template: Mapped[str] = 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 Broadcast(Base):
|
||||
__tablename__ = "broadcasts"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
template_id: Mapped[int | None] = mapped_column(ForeignKey("broadcast_templates.id"))
|
||||
type: Mapped[BroadcastType] = mapped_column(enum_col(BroadcastType))
|
||||
subject: Mapped[str | None] = mapped_column(String(300))
|
||||
body: Mapped[str | None] = mapped_column(Text)
|
||||
audience_filter: Mapped[dict | None] = mapped_column(JSON)
|
||||
status: Mapped[BroadcastStatus] = mapped_column(
|
||||
enum_col(BroadcastStatus), default=BroadcastStatus.DRAFT
|
||||
)
|
||||
scheduled_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
|
||||
started_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
|
||||
finished_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
|
||||
created_by: Mapped[int | None] = mapped_column(ForeignKey("users.id"))
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
|
||||
class BroadcastRecipient(Base):
|
||||
__tablename__ = "broadcast_recipients"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
broadcast_id: Mapped[int] = mapped_column(ForeignKey("broadcasts.id", ondelete="CASCADE"))
|
||||
user_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"))
|
||||
status: Mapped[RecipientStatus] = mapped_column(
|
||||
enum_col(RecipientStatus), default=RecipientStatus.PENDING
|
||||
)
|
||||
sent_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
|
||||
error: Mapped[str | None] = mapped_column(Text)
|
||||
|
||||
__table_args__ = (UniqueConstraint("broadcast_id", "user_id", name="uq_broadcast_user"),)
|
||||
Reference in new issue
Block a user