mirror of
https://github.com/stijndcl/didier.git
synced 2026-04-07 23:55:46 +02:00
Fix mongo connection
This commit is contained in:
parent
9abe5dd519
commit
52b452c85a
16 changed files with 53 additions and 38 deletions
|
|
@ -1,5 +1,6 @@
|
|||
from urllib.parse import quote_plus
|
||||
|
||||
import motor.motor_asyncio
|
||||
from sqlalchemy.engine import URL
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
|
@ -8,7 +9,8 @@ import settings
|
|||
|
||||
encoded_password = quote_plus(settings.POSTGRES_PASS)
|
||||
|
||||
engine = create_async_engine(
|
||||
# PostgreSQL engine
|
||||
postgres_engine = create_async_engine(
|
||||
URL.create(
|
||||
drivername="postgresql+asyncpg",
|
||||
username=settings.POSTGRES_USER,
|
||||
|
|
@ -21,4 +23,9 @@ engine = create_async_engine(
|
|||
future=True,
|
||||
)
|
||||
|
||||
DBSession = sessionmaker(autocommit=False, autoflush=False, bind=engine, class_=AsyncSession, expire_on_commit=False)
|
||||
DBSession = sessionmaker(
|
||||
autocommit=False, autoflush=False, bind=postgres_engine, class_=AsyncSession, expire_on_commit=False
|
||||
)
|
||||
|
||||
# MongoDB client
|
||||
mongo_client = motor.motor_asyncio.AsyncIOMotorClient(settings.MONGO_HOST, settings.MONGO_PORT)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from sqlalchemy.orm import Session
|
|||
from alembic import command, script
|
||||
from alembic.config import Config
|
||||
from alembic.runtime import migration
|
||||
from database.engine import engine
|
||||
from database.engine import postgres_engine
|
||||
|
||||
__config_path__ = "alembic.ini"
|
||||
__migrations_path__ = "alembic/"
|
||||
|
|
@ -22,7 +22,7 @@ async def ensure_latest_migration():
|
|||
"""Make sure we are currently on the latest revision, otherwise raise an exception"""
|
||||
alembic_script = script.ScriptDirectory.from_config(cfg)
|
||||
|
||||
async with engine.begin() as connection:
|
||||
async with postgres_engine.begin() as connection:
|
||||
current_revision = await connection.run_sync(
|
||||
lambda sync_connection: migration.MigrationContext.configure(sync_connection).get_current_revision()
|
||||
)
|
||||
|
|
@ -49,5 +49,5 @@ def __execute_downgrade(connection: Session):
|
|||
|
||||
async def migrate(up: bool):
|
||||
"""Migrate the database upwards or downwards"""
|
||||
async with engine.begin() as connection:
|
||||
async with postgres_engine.begin() as connection:
|
||||
await connection.run_sync(__execute_upgrade if up else __execute_downgrade)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue