@@ -48,8 +48,9 @@ class FixtureMigration(declarative_base):
4848 __tablename__ = "alembic_fixtures"
4949
5050 bind : Mapped [str ] = mapped_column (String (), primary_key = True )
51- filename : Mapped [str ] = mapped_column (String (), primary_key = True )
51+ module_name : Mapped [str ] = mapped_column (String (), primary_key = True )
5252 signature : Mapped [str ] = mapped_column (String (), nullable = False )
53+
5354 processed_at : Mapped [datetime ] = mapped_column (
5455 DateTime (), nullable = False , default = datetime .now
5556 )
@@ -162,13 +163,13 @@ def _fixture_already_migrated(cls, fixture_migration, signature) -> bool:
162163 if fixture_migration :
163164 if signature != fixture_migration .signature :
164165 cls .logger .warning (
165- f"Signature mismatch for `{ fixture_migration .filename } ` fixture."
166+ f"Signature mismatch for `{ fixture_migration .module_name } ` fixture."
166167 f" The file has been already processed but has been modified"
167168 f" since then. It will not be processed again."
168169 )
169170 else :
170171 cls .logger .debug (
171- f"`{ fixture_migration .filename } ` fixtures already processed for `{ fixture_migration .bind } ` bind"
172+ f"`{ fixture_migration .module_name } ` fixtures already processed for `{ fixture_migration .bind } ` bind"
172173 )
173174 return True
174175 return False
@@ -207,7 +208,7 @@ def _add_fixture_data_to_session(
207208 session .add (
208209 fixture_migration_models [bind_name ](
209210 bind = bind_name ,
210- filename = f"{ fixture_module .__name__ } " ,
211+ module_name = f"{ fixture_module .__name__ } " ,
211212 signature = signature ,
212213 )
213214 )
@@ -395,20 +396,11 @@ async def run_migrations_online() -> None:
395396 for name , rec in engines .items ():
396397 logger .info (f"Migrating database { name } " )
397398 if isinstance (rec ["engine" ], AsyncEngine ):
398-
399399 def migration_callable (* args , ** kwargs ):
400400 return do_run_migration (* args , name = name , ** kwargs )
401-
402401 await rec ["connection" ].run_sync (migration_callable )
403- await FixtureHandler .a_migrate_fixtures (
404- bind_name = name , session = async_sessionmaker (bind = rec ["connection" ])
405- )
406-
407402 else :
408403 do_run_migration (rec ["connection" ], name )
409- FixtureHandler .migrate_fixtures (
410- bind_name = name , session = sessionmaker (bind = rec ["connection" ])
411- )
412404
413405 if USE_TWOPHASE :
414406 for rec in engines .values ():
@@ -422,6 +414,17 @@ def migration_callable(*args, **kwargs):
422414 await rec ["transaction" ].commit ()
423415 else :
424416 rec ["transaction" ].commit ()
417+
418+ if context .config .cmd_opts .cmd [0 ].__name__ == "upgrade" :
419+ for name , rec in engines .items ():
420+ if isinstance (rec ["engine" ], AsyncEngine ):
421+ await FixtureHandler .a_migrate_fixtures (
422+ bind_name = name , session = async_sessionmaker (bind = rec ["connection" ])
423+ )
424+ else :
425+ FixtureHandler .migrate_fixtures (
426+ bind_name = name , session = sessionmaker (bind = rec ["connection" ])
427+ )
425428 except :
426429 for rec in engines .values ():
427430 if isinstance (rec ["engine" ], AsyncEngine ):
0 commit comments