Skip to content

Commit ff57007

Browse files
committed
Add alembic_revision column to fixture tables
This update introduces a new `alembic_revision` column to fixture tables for tracking the Alembic migration state. Additionally, error logging in fixture creation now includes exception details, and rollback is moved to ensure consistency in failure scenarios.
1 parent b310c55 commit ff57007

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/migrations/env.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class FixtureMigration(declarative_base):
5050
bind: Mapped[str] = mapped_column(String(), primary_key=True)
5151
module_name: Mapped[str] = mapped_column(String(), primary_key=True)
5252
signature: Mapped[str] = mapped_column(String(), nullable=False)
53+
alembic_revision: Mapped[str] = mapped_column(String(), nullable=True, default=str(context.get_head_revision()))
5354

5455
processed_at: Mapped[datetime] = mapped_column(
5556
DateTime(), nullable=False, default=datetime.now
@@ -259,11 +260,11 @@ async def a_migrate_fixtures(
259260
cls.logger.info(
260261
f"`{fixture_module.__name__}` fixtures correctly created for `{bind_name}` bind"
261262
)
262-
except Exception:
263-
await session.rollback()
263+
except Exception as e:
264264
cls.logger.error(
265-
f"`{fixture_module.__name__}` fixtures failed to apply to `{bind_name}` bind"
265+
f"`{fixture_module.__name__}` fixtures failed to apply to `{bind_name}` bind", exc_info=True
266266
)
267+
await session.rollback()
267268

268269
@classmethod
269270
def migrate_fixtures(cls, bind_name: str, session: sessionmaker[Session]):

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def upgrade_default() -> None:
3030
sa.Column("bind", sa.String(), nullable=False),
3131
sa.Column("module_name", sa.String(), nullable=False),
3232
sa.Column("signature", sa.String(), nullable=False),
33+
sa.Column("alembic_revision", sa.String(), nullable=False),
3334
sa.Column("processed_at", sa.DateTime(timezone=True), nullable=False),
3435
sa.PrimaryKeyConstraint("bind", "module_name"),
3536
)

0 commit comments

Comments
 (0)