forked from HSE_team/BetterCallPraskovia
fix build
This commit is contained in:
parent
8bdacb4f7a
commit
5809ac5688
@ -24,7 +24,8 @@ steps:
|
|||||||
script:
|
script:
|
||||||
- cd BetterCallPraskovia
|
- cd BetterCallPraskovia
|
||||||
- git pull origin main
|
- git pull origin main
|
||||||
- docker-compose stop backend tg_bot
|
- docker-compose down backend tg_bot
|
||||||
- docker-compose up --build -d backend tg_bot
|
- docker-compose build backend tg_bot
|
||||||
|
- docker-compose up -d backend tg_bot
|
||||||
- docker system prune -f
|
- docker system prune -f
|
||||||
|
|
||||||
|
|||||||
@ -1,93 +0,0 @@
|
|||||||
import os
|
|
||||||
import sys
|
|
||||||
from sqlalchemy import create_engine, inspect
|
|
||||||
from sqlalchemy.orm import declarative_base, Session
|
|
||||||
from sqlalchemy import Column, String, DateTime, Boolean, Integer, Text
|
|
||||||
import uuid
|
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
DB_PATH = os.path.join(BASE_DIR, 'data', 'bot.db')
|
|
||||||
DATABASE_URL = f"sqlite:///{DB_PATH}"
|
|
||||||
|
|
||||||
os.makedirs(os.path.dirname(DB_PATH), exist_ok=True)
|
|
||||||
|
|
||||||
if os.path.exists(DB_PATH):
|
|
||||||
try:
|
|
||||||
temp_engine = create_engine(DATABASE_URL)
|
|
||||||
inspector = inspect(temp_engine)
|
|
||||||
tables = inspector.get_table_names()
|
|
||||||
if tables:
|
|
||||||
sys.exit(0)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
choice = input("Перезаписать БД? (y/N): ")
|
|
||||||
if choice.lower() != 'y':
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
engine = create_engine(DATABASE_URL, echo=False)
|
|
||||||
Base = declarative_base()
|
|
||||||
|
|
||||||
class UserModel(Base):
|
|
||||||
__tablename__ = "users"
|
|
||||||
|
|
||||||
user_id = Column("user_id", String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
|
||||||
telegram_id = Column("telegram_id", String(100), nullable=False, unique=True)
|
|
||||||
created_at = Column("created_at", DateTime, default=datetime.utcnow, nullable=False)
|
|
||||||
role = Column("role", String(20), default="user", nullable=False)
|
|
||||||
is_premium = Column(Boolean, default=False, nullable=False)
|
|
||||||
premium_until = Column(DateTime, nullable=True)
|
|
||||||
questions_used = Column(Integer, default=0, nullable=False)
|
|
||||||
username = Column(String(100), nullable=True)
|
|
||||||
first_name = Column(String(100), nullable=True)
|
|
||||||
last_name = Column(String(100), nullable=True)
|
|
||||||
|
|
||||||
class PaymentModel(Base):
|
|
||||||
__tablename__ = "payments"
|
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
||||||
payment_id = Column(String(36), default=lambda: str(uuid.uuid4()), nullable=False, unique=True)
|
|
||||||
user_id = Column(Integer, nullable=False)
|
|
||||||
amount = Column(String(20), nullable=False)
|
|
||||||
currency = Column(String(3), default="RUB", nullable=False)
|
|
||||||
status = Column(String(20), default="pending", nullable=False)
|
|
||||||
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
|
|
||||||
yookassa_payment_id = Column(String(100), unique=True, nullable=True)
|
|
||||||
description = Column(Text, nullable=True)
|
|
||||||
|
|
||||||
try:
|
|
||||||
Base.metadata.create_all(bind=engine)
|
|
||||||
|
|
||||||
session = Session(bind=engine)
|
|
||||||
|
|
||||||
existing = session.query(UserModel).filter_by(telegram_id="123456789").first()
|
|
||||||
if not existing:
|
|
||||||
test_user = UserModel(
|
|
||||||
telegram_id="123456789",
|
|
||||||
username="test_user",
|
|
||||||
first_name="Test",
|
|
||||||
last_name="User",
|
|
||||||
is_premium=True
|
|
||||||
)
|
|
||||||
session.add(test_user)
|
|
||||||
|
|
||||||
existing_payment = session.query(PaymentModel).filter_by(yookassa_payment_id="test_yoo_001").first()
|
|
||||||
if not existing_payment:
|
|
||||||
test_payment = PaymentModel(
|
|
||||||
user_id=123456789,
|
|
||||||
amount="500.00",
|
|
||||||
status="succeeded",
|
|
||||||
description="Test payment",
|
|
||||||
yookassa_payment_id="test_yoo_001"
|
|
||||||
)
|
|
||||||
session.add(test_payment)
|
|
||||||
|
|
||||||
session.commit()
|
|
||||||
session.close()
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Ошибка: {e}")
|
|
||||||
import traceback
|
|
||||||
traceback.print_exc()
|
|
||||||
|
|
||||||
@ -1,31 +0,0 @@
|
|||||||
import sys
|
|
||||||
import os
|
|
||||||
|
|
||||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
||||||
|
|
||||||
try:
|
|
||||||
from tg_bot.infrastructure.database.database import engine, Base
|
|
||||||
from tg_bot.infrastructure.database import models
|
|
||||||
|
|
||||||
print("СОЗДАНИЕ ТАБЛИЦ БАЗЫ ДАННЫХ")
|
|
||||||
Base.metadata.create_all(bind=engine)
|
|
||||||
|
|
||||||
print("Таблицы успешно созданы!")
|
|
||||||
print(" • users")
|
|
||||||
print(" • payments")
|
|
||||||
print()
|
|
||||||
print(f"База данных: {engine.url}")
|
|
||||||
|
|
||||||
db_path = "data/bot.db"
|
|
||||||
if os.path.exists(db_path):
|
|
||||||
size = os.path.getsize(db_path)
|
|
||||||
print(f"Размер файла: {size} байт")
|
|
||||||
else:
|
|
||||||
print("Файл БД не найден, но таблицы созданы")
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Ошибка: {e}")
|
|
||||||
import traceback
|
|
||||||
traceback.print_exc()
|
|
||||||
|
|
||||||
print("=" * 50)
|
|
||||||
@ -36,6 +36,7 @@ class User:
|
|||||||
self.questions_used = data.get("questions_used", 0)
|
self.questions_used = data.get("questions_used", 0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class UserService:
|
class UserService:
|
||||||
"""Сервис для работы с пользователями через API бэкенда"""
|
"""Сервис для работы с пользователями через API бэкенда"""
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user