feat: add tariff config and database schema
This commit is contained in:
+60
-1
@@ -1,4 +1,4 @@
|
||||
from sqlalchemy import create_engine, Column, Integer, String, Boolean, DateTime, Float, ForeignKey, UniqueConstraint, Text, BigInteger, Index
|
||||
from sqlalchemy import create_engine, Column, Integer, String, Boolean, DateTime, Float, ForeignKey, UniqueConstraint, Text, BigInteger, Index, Numeric
|
||||
from sqlalchemy.orm import relationship, DeclarativeBase
|
||||
from sqlalchemy.ext.asyncio import AsyncAttrs
|
||||
from sqlalchemy.sql import func
|
||||
@@ -87,6 +87,12 @@ class Subscription(Base):
|
||||
provider = Column(String, nullable=True)
|
||||
skip_notifications = Column(Boolean, default=False)
|
||||
auto_renew_enabled = Column(Boolean, default=True, index=True)
|
||||
tariff_key = Column(String, nullable=True, index=True)
|
||||
tier_baseline_bytes = Column(BigInteger, nullable=True)
|
||||
topup_balance_bytes = Column(BigInteger, nullable=False, default=0)
|
||||
period_start_at = Column(DateTime(timezone=True), nullable=True)
|
||||
is_throttled = Column(Boolean, nullable=False, default=False, index=True)
|
||||
effective_monthly_price_rub = Column(Numeric, nullable=True)
|
||||
|
||||
user = relationship("User", back_populates="subscriptions")
|
||||
|
||||
@@ -158,6 +164,9 @@ class Payment(Base):
|
||||
status = Column(String, nullable=False, index=True)
|
||||
description = Column(String, nullable=True)
|
||||
subscription_duration_months = Column(Integer, nullable=True)
|
||||
sale_mode = Column(String, nullable=True, index=True)
|
||||
tariff_key = Column(String, nullable=True, index=True)
|
||||
purchased_gb = Column(Float, nullable=True)
|
||||
promo_code_id = Column(Integer,
|
||||
ForeignKey("promo_codes.promo_code_id"),
|
||||
nullable=True)
|
||||
@@ -171,6 +180,56 @@ class Payment(Base):
|
||||
back_populates="payments_where_used")
|
||||
|
||||
|
||||
class TrafficTopup(Base):
|
||||
__tablename__ = "traffic_topups"
|
||||
|
||||
topup_id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
subscription_id = Column(Integer, ForeignKey("subscriptions.subscription_id"), nullable=False, index=True)
|
||||
payment_id = Column(Integer, ForeignKey("payments.payment_id"), nullable=True, index=True)
|
||||
purchased_bytes = Column(BigInteger, nullable=False)
|
||||
kind = Column(String, nullable=False, index=True)
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
subscription = relationship("Subscription")
|
||||
payment = relationship("Payment")
|
||||
|
||||
|
||||
class TrafficWarning(Base):
|
||||
__tablename__ = "traffic_warnings"
|
||||
__table_args__ = (
|
||||
UniqueConstraint("subscription_id", "period_start_at", "level", name="uq_traffic_warning_period_level"),
|
||||
)
|
||||
|
||||
warning_id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
subscription_id = Column(Integer, ForeignKey("subscriptions.subscription_id"), nullable=False, index=True)
|
||||
period_start_at = Column(DateTime(timezone=True), nullable=True)
|
||||
level = Column(Integer, nullable=False)
|
||||
traffic_limit_bytes = Column(BigInteger, nullable=True)
|
||||
sent_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
subscription = relationship("Subscription")
|
||||
|
||||
|
||||
class TariffChange(Base):
|
||||
__tablename__ = "tariff_changes"
|
||||
|
||||
change_id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
subscription_id = Column(Integer, ForeignKey("subscriptions.subscription_id"), nullable=False, index=True)
|
||||
from_tariff_key = Column(String, nullable=True)
|
||||
to_tariff_key = Column(String, nullable=False)
|
||||
mode = Column(String, nullable=False, index=True)
|
||||
payment_id = Column(Integer, ForeignKey("payments.payment_id"), nullable=True, index=True)
|
||||
days_before = Column(Integer, nullable=True)
|
||||
days_after = Column(Integer, nullable=True)
|
||||
converted_bytes = Column(BigInteger, nullable=True)
|
||||
eff_price_before = Column(Numeric, nullable=True)
|
||||
eff_price_after = Column(Numeric, nullable=True)
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
subscription = relationship("Subscription")
|
||||
payment = relationship("Payment")
|
||||
|
||||
|
||||
class UserBilling(Base):
|
||||
__tablename__ = "user_billing"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user