Доработка вебхука

This commit is contained in:
2025-11-20 23:16:09 +07:00
parent 8f5b984598
commit 1538f72c8f
5 changed files with 69 additions and 125 deletions

View File

@@ -1,22 +1,22 @@
import os
from sqlalchemy import create_engine
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from dotenv import load_dotenv
load_dotenv()
# Для Alembic используем синхронный движок с psycopg2
DATABASE_URL = os.getenv("DATABASE_URL", "postgresql+asyncpg://postgres:postgres@localhost:5432/ingest_db")
# Преобразуем asyncpg URL в psycopg2 для синхронного движка
SYNC_DATABASE_URL = DATABASE_URL.replace("postgresql+asyncpg://", "postgresql://")
engine = create_engine(SYNC_DATABASE_URL)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# Единый async движок для всего приложения
engine = create_async_engine(DATABASE_URL, echo=True)
AsyncSessionLocal = async_sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
Base = declarative_base()
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()
async def get_db():
"""Dependency для получения async сессии БД"""
async with AsyncSessionLocal() as session:
try:
yield session
finally:
await session.close()