@@ -48,8 +48,9 @@ class FixtureMigration(declarative_base):
48
48
__tablename__ = "alembic_fixtures"
49
49
50
50
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 )
52
52
signature : Mapped [str ] = mapped_column (String (), nullable = False )
53
+
53
54
processed_at : Mapped [datetime ] = mapped_column (
54
55
DateTime (), nullable = False , default = datetime .now
55
56
)
@@ -162,13 +163,13 @@ def _fixture_already_migrated(cls, fixture_migration, signature) -> bool:
162
163
if fixture_migration :
163
164
if signature != fixture_migration .signature :
164
165
cls .logger .warning (
165
- f"Signature mismatch for `{ fixture_migration .filename } ` fixture."
166
+ f"Signature mismatch for `{ fixture_migration .module_name } ` fixture."
166
167
f" The file has been already processed but has been modified"
167
168
f" since then. It will not be processed again."
168
169
)
169
170
else :
170
171
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"
172
173
)
173
174
return True
174
175
return False
@@ -207,7 +208,7 @@ def _add_fixture_data_to_session(
207
208
session .add (
208
209
fixture_migration_models [bind_name ](
209
210
bind = bind_name ,
210
- filename = f"{ fixture_module .__name__ } " ,
211
+ module_name = f"{ fixture_module .__name__ } " ,
211
212
signature = signature ,
212
213
)
213
214
)
@@ -395,20 +396,11 @@ async def run_migrations_online() -> None:
395
396
for name , rec in engines .items ():
396
397
logger .info (f"Migrating database { name } " )
397
398
if isinstance (rec ["engine" ], AsyncEngine ):
398
-
399
399
def migration_callable (* args , ** kwargs ):
400
400
return do_run_migration (* args , name = name , ** kwargs )
401
-
402
401
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
-
407
402
else :
408
403
do_run_migration (rec ["connection" ], name )
409
- FixtureHandler .migrate_fixtures (
410
- bind_name = name , session = sessionmaker (bind = rec ["connection" ])
411
- )
412
404
413
405
if USE_TWOPHASE :
414
406
for rec in engines .values ():
@@ -422,6 +414,17 @@ def migration_callable(*args, **kwargs):
422
414
await rec ["transaction" ].commit ()
423
415
else :
424
416
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
+ )
425
428
except :
426
429
for rec in engines .values ():
427
430
if isinstance (rec ["engine" ], AsyncEngine ):
0 commit comments