Проект разделен на два репозитория
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from alembic import context
|
||||
from app.postgres import create_postgres_engine
|
||||
|
||||
config = context.config
|
||||
database_url = os.environ["BITRIX_SYNC_DATABASE_URL"]
|
||||
config.set_main_option(
|
||||
"sqlalchemy.url",
|
||||
database_url.replace("%", "%%"),
|
||||
)
|
||||
target_metadata = None
|
||||
|
||||
|
||||
def run_offline() -> None:
|
||||
context.configure(url=config.get_main_option("sqlalchemy.url"), literal_binds=True)
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
async def run_online() -> None:
|
||||
engine = create_postgres_engine(database_url)
|
||||
async with engine.connect() as connection:
|
||||
await connection.run_sync(do_run)
|
||||
await engine.dispose()
|
||||
|
||||
|
||||
def do_run(connection) -> None:
|
||||
context.configure(connection=connection)
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
if context.is_offline_mode():
|
||||
run_offline()
|
||||
else:
|
||||
asyncio.run(run_online())
|
||||
Reference in New Issue
Block a user