Skip to content

Commit b310c55

Browse files
committed
Rename filename to module_name
1 parent 88216a4 commit b310c55

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

src/migrations/env.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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):

src/migrations/versions/2025-01-26-212326-52b1246eda46_initialize_fixture_tables.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ def upgrade_default() -> None:
2828
op.create_table(
2929
"alembic_fixtures",
3030
sa.Column("bind", sa.String(), nullable=False),
31-
sa.Column("filename", sa.String(), nullable=False),
31+
sa.Column("module_name", sa.String(), nullable=False),
3232
sa.Column("signature", sa.String(), nullable=False),
3333
sa.Column("processed_at", sa.DateTime(timezone=True), nullable=False),
34-
sa.PrimaryKeyConstraint("bind", "filename"),
34+
sa.PrimaryKeyConstraint("bind", "module_name"),
3535
)
3636

3737

0 commit comments

Comments
 (0)