11import asyncio
22from logging .config import fileConfig
33
4- from sqlalchemy import engine_from_config
54from sqlalchemy import pool
6- from sqlalchemy .ext .asyncio import AsyncEngine
7- from sqlmodel import SQLModel
5+ from sqlalchemy .engine import Connection
6+ from sqlalchemy .ext .asyncio import async_engine_from_config
7+ from sqlmodel import SQLModel # NEW
8+
89
910from alembic import context
1011
11- from app .models import Song
12+ from app .models import Song # NEW
1213
1314# this is the Alembic Config object, which provides
1415# access to the values within the .ini file in use.
1516config = context .config
1617
1718# Interpret the config file for Python logging.
1819# This line sets up loggers basically.
19- fileConfig (config .config_file_name )
20+ if config .config_file_name is not None :
21+ fileConfig (config .config_file_name )
2022
2123# add your model's MetaData object here
2224# for 'autogenerate' support
2325# from myapp import mymodel
2426# target_metadata = mymodel.Base.metadata
25- target_metadata = SQLModel .metadata
27+ target_metadata = SQLModel .metadata # UPDATED
2628
2729# other values from the config, defined by the needs of env.py,
2830# can be acquired:
2931# my_important_option = config.get_main_option("my_important_option")
3032# ... etc.
3133
3234
33- def run_migrations_offline ():
35+ def run_migrations_offline () -> None :
3436 """Run migrations in 'offline' mode.
3537
3638 This configures the context with just a URL
@@ -54,34 +56,38 @@ def run_migrations_offline():
5456 context .run_migrations ()
5557
5658
57- def do_run_migrations (connection ) :
59+ def do_run_migrations (connection : Connection ) -> None :
5860 context .configure (connection = connection , target_metadata = target_metadata )
5961
6062 with context .begin_transaction ():
6163 context .run_migrations ()
6264
6365
64- async def run_migrations_online ():
65- """Run migrations in 'online' mode.
66-
67- In this scenario we need to create an Engine
66+ async def run_async_migrations () -> None :
67+ """In this scenario we need to create an Engine
6868 and associate a connection with the context.
6969
7070 """
71- connectable = AsyncEngine (
72- engine_from_config (
73- config .get_section (config .config_ini_section ),
74- prefix = "sqlalchemy." ,
75- poolclass = pool .NullPool ,
76- future = True ,
77- )
71+
72+ connectable = async_engine_from_config (
73+ config .get_section (config .config_ini_section , {}),
74+ prefix = "sqlalchemy." ,
75+ poolclass = pool .NullPool ,
7876 )
7977
8078 async with connectable .connect () as connection :
8179 await connection .run_sync (do_run_migrations )
8280
81+ await connectable .dispose ()
82+
83+
84+ def run_migrations_online () -> None :
85+ """Run migrations in 'online' mode."""
86+
87+ asyncio .run (run_async_migrations ())
88+
8389
8490if context .is_offline_mode ():
8591 run_migrations_offline ()
8692else :
87- asyncio . run ( run_migrations_online () )
93+ run_migrations_online ()
0 commit comments