SPB Git forge
3commits 1branches 0releases
417.0 KBsize
maindefault branch
10 days agolast push
TypeScript 66.5% Python 30.9% JavaScript 1.4% CSS 0.7%
1.3 KB · 46 lines python
Raw Blame History
1"""Alembic environment (async engine). Migrations are plain SQL executed through `op.execute`."""2from __future__ import annotations34import asyncio5from logging.config import fileConfig67from alembic import context8from sqlalchemy.ext.asyncio import create_async_engine910from satelliteindex.config import settings1112config = context.config13if config.config_file_name is not None:14    fileConfig(config.config_file_name)1516target_metadata = None171819def run_migrations_offline() -> None:20    context.configure(url=settings.sync_database_url, literal_binds=True, dialect_opts={"paramstyle": "named"})21    with context.begin_transaction():22        context.run_migrations()232425def do_run_migrations(connection) -> None:  # type: ignore[no-untyped-def]26    context.configure(connection=connection, target_metadata=target_metadata, transaction_per_migration=True)27    with context.begin_transaction():28        context.run_migrations()293031async def run_async_migrations() -> None:32    engine = create_async_engine(settings.database_url, poolclass=None)33    async with engine.connect() as connection:34        await connection.run_sync(do_run_migrations)35    await engine.dispose()363738def run_migrations_online() -> None:39    asyncio.run(run_async_migrations())404142if context.is_offline_mode():43    run_migrations_offline()44else:45    run_migrations_online()46