diff options
| author | 2023-09-04 21:21:37 +0100 | |
|---|---|---|
| committer | 2023-09-04 21:21:37 +0100 | |
| commit | c6829ab8134adceb2ed0bdaf71f1abfeef63286c (patch) | |
| tree | 04848901819ede9c851bd07fea46bd709d91f7af /alembic/env.py | |
| parent | Use `thread.created_at` to determine thread creation (diff) | |
Subject Alembic files to the wrath of the linter
Diffstat (limited to 'alembic/env.py')
| -rw-r--r-- | alembic/env.py | 33 | 
1 files changed, 11 insertions, 22 deletions
| diff --git a/alembic/env.py b/alembic/env.py index 903d5ef..91aca63 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -1,15 +1,10 @@ +import asyncio  from logging.config import fileConfig +from sqlalchemy import Connection, pool  from sqlalchemy.ext.asyncio import async_engine_from_config -from sqlalchemy import pool - -import asyncio  from alembic import context - -import sys -sys.path.append(".") -  from metricity.database import build_db_uri  from metricity.models import Base @@ -23,29 +18,23 @@ fileConfig(config.config_file_name)  # add your model's MetaData object here  # for 'autogenerate' support -# from myapp import mymodel -# target_metadata = mymodel.Base.metadata  target_metadata = Base.metadata  # other values from the config, defined by the needs of env.py,  # can be acquired: -# my_important_option = config.get_main_option("my_important_option")  # ... etc. -config.set_main_option('sqlalchemy.url', build_db_uri()) +config.set_main_option("sqlalchemy.url", build_db_uri()) -def do_run_migrations(connection): +def do_run_migrations(connection: Connection) -> None: +    """Run migrations."""      context.configure(connection=connection, target_metadata=target_metadata)      with context.begin_transaction():          context.run_migrations() -async def run_async_migrations(): -    """In this scenario we need to create an Engine -    and associate a connection with the context. - -    """ - +async def run_async_migrations() -> None: +    """Run migrations asynchronously using the asyncpg driver."""      connectable = async_engine_from_config(          config.get_section(config.config_ini_section),          prefix="sqlalchemy.", @@ -57,8 +46,9 @@ async def run_async_migrations():      await connectable.dispose() -def run_migrations_offline(): -    """Run migrations in 'offline' mode. +def run_migrations_offline() -> None: +    """ +    Run migrations in 'offline' mode.      This configures the context with just a URL      and not an Engine, though an Engine is acceptable @@ -81,9 +71,8 @@ def run_migrations_offline():          context.run_migrations() -def run_migrations_online(): +def run_migrations_online() -> None:      """Run migrations in 'online' mode.""" -      asyncio.run(run_async_migrations()) | 
