mirror of https://github.com/stijndcl/didier
Small cleanup
parent
9401111bee
commit
8bd4495016
|
@ -7,17 +7,16 @@ from sqlalchemy.orm import sessionmaker
|
||||||
import settings
|
import settings
|
||||||
|
|
||||||
encoded_password = quote_plus(settings.DB_PASSWORD)
|
encoded_password = quote_plus(settings.DB_PASSWORD)
|
||||||
url = URL.create(
|
|
||||||
drivername="postgresql+asyncpg",
|
|
||||||
username=settings.DB_USERNAME,
|
|
||||||
password=encoded_password,
|
|
||||||
host=settings.DB_HOST,
|
|
||||||
port=settings.DB_PORT,
|
|
||||||
database=settings.DB_NAME,
|
|
||||||
)
|
|
||||||
|
|
||||||
engine = create_async_engine(
|
engine = create_async_engine(
|
||||||
url,
|
URL.create(
|
||||||
|
drivername="postgresql+asyncpg",
|
||||||
|
username=settings.DB_USERNAME,
|
||||||
|
password=encoded_password,
|
||||||
|
host=settings.DB_HOST,
|
||||||
|
port=settings.DB_PORT,
|
||||||
|
database=settings.DB_NAME,
|
||||||
|
),
|
||||||
pool_pre_ping=True,
|
pool_pre_ping=True,
|
||||||
future=True,
|
future=True,
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from sqlalchemy.ext.asyncio import create_async_engine
|
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from alembic import command, config, script
|
from alembic import command, script
|
||||||
from alembic.config import Config
|
from alembic.config import Config
|
||||||
from alembic.runtime import migration
|
from alembic.runtime import migration
|
||||||
from database.engine import engine, url
|
from database.engine import engine
|
||||||
|
|
||||||
__config_path__ = "alembic.ini"
|
__config_path__ = "alembic.ini"
|
||||||
__migrations_path__ = "alembic/"
|
__migrations_path__ = "alembic/"
|
||||||
|
@ -50,6 +49,5 @@ def __execute_downgrade(connection: Session):
|
||||||
|
|
||||||
async def migrate(up: bool):
|
async def migrate(up: bool):
|
||||||
"""Migrate the database upwards or downwards"""
|
"""Migrate the database upwards or downwards"""
|
||||||
async_engine = create_async_engine(url, echo=True)
|
async with engine.begin() as connection:
|
||||||
async with async_engine.begin() as connection:
|
|
||||||
await connection.run_sync(__execute_upgrade if up else __execute_downgrade)
|
await connection.run_sync(__execute_upgrade if up else __execute_downgrade)
|
||||||
|
|
Loading…
Reference in New Issue