- FastAPI REST API with JWT auth - aiogram 3 Telegram bot with admin middleware - APScheduler daily tasks (expiry, reminders, revoke, sync) - SQLAlchemy 2 async ORM with Alembic migrations - Jinja2 admin panel (Dashboard, Users, Payments, Servers, Tariffs) - VPN provider abstraction with MockProvider - Stats service with revenue/subscription analytics - Docker Compose (PostgreSQL + Redis + app) - Healthcheck endpoint
33 lines
1.3 KiB
Python
33 lines
1.3 KiB
Python
from datetime import datetime
|
|
|
|
from sqlalchemy import Boolean, DateTime, Integer, Numeric, String, func
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class Tariff(Base):
|
|
__tablename__ = "tariffs"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
name: Mapped[str] = mapped_column(String(64), nullable=False)
|
|
duration_days: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
price: Mapped[float] = mapped_column(Numeric(10, 2), nullable=False)
|
|
currency: Mapped[str] = mapped_column(String(3), default="RUB")
|
|
max_devices: Mapped[int] = mapped_column(Integer, default=1)
|
|
traffic_gb: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
|
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
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()
|
|
)
|
|
|
|
payments: Mapped[list["Payment"]] = relationship(
|
|
back_populates="tariff", cascade="all, delete-orphan"
|
|
)
|
|
|
|
def __repr__(self) -> str:
|
|
return f"<Tariff id={self.id} {self.name} {self.price}{self.currency}>"
|