Skip to content

FIX revert alembic version#1726

Merged
hannahwestra25 merged 3 commits into
microsoft:mainfrom
hannahwestra25:hawestra/fix-migration-chain
May 13, 2026
Merged

FIX revert alembic version#1726
hannahwestra25 merged 3 commits into
microsoft:mainfrom
hannahwestra25:hawestra/fix-migration-chain

Conversation

@hannahwestra25
Copy link
Copy Markdown
Contributor

@hannahwestra25 hannahwestra25 commented May 13, 2026

Problem

alembic migration chain broken for any existing database because the migration 108a72344872 (add_labels_to_attack_results) was deleted and it's columns squashed— plus new error/retry columns — directly into the initial schema (e373726d391b)

Any database that had already run migrations is stamped at revision 108a72344872 in the alembic_version table. Since that revision file no longer exists, alembic throws:
Can't locate revision identified by '108a72344872'

This breaks all integration tests and any existing user or CI database.

Why this approach

Restore the deleted migration + create a new one (this PR)

  • It preserves the published revision chain. Migrations that have been applied to any database must never be deleted or modified — this is a fundamental rule of schema migration systems. Restoring 108a72344872 makes existing databases immediately functional again.
  • It works for both existing and new databases. Existing DBs (stamped at 108a72344872) simply run the new migration to get error columns. Fresh DBs run all three migrations in order. Option 2 would require existing DBs to first recognize a revision they've never seen, adding fragile re-stamping logic.
  • It avoids duplication. Squashing columns into the initial schema while also having them in a later migration would cause "column already exists" errors on fresh databases. Reverting the initial schema to its original form keeps each column defined in exactly one place.

Changes

File Change
e373726d391b_initial_schema.py Reverted to original — removed 9 columns that were incorrectly squashed in
108a72344872_add_labels_to_attack_results.py Restored deleted migration (adds labels to AttackResultEntries)
7a1b2c3d4e5f_add_error_retry_fields.py New migration — adds error/retry columns to AttackResultEntries and ScenarioResultEntries

Final migration chain: e373726d391b108a723448727a1b2c3d4e5f

Testing

  • test_migration.py — 16/16 passed
  • test_sqlite_memory.py + test_azure_sql_memory.py — 73 passed, 1 skipped
  • enforce_alembic_revision_immutability.py — passed

@hannahwestra25 hannahwestra25 marked this pull request as ready for review May 13, 2026 16:56
@hannahwestra25 hannahwestra25 enabled auto-merge May 13, 2026 18:07
@hannahwestra25 hannahwestra25 force-pushed the hawestra/fix-migration-chain branch from fb023cd to b534c59 Compare May 13, 2026 19:13
@hannahwestra25 hannahwestra25 added this pull request to the merge queue May 13, 2026
Merged via the queue into microsoft:main with commit 361c2a4 May 13, 2026
47 checks passed
@hannahwestra25 hannahwestra25 deleted the hawestra/fix-migration-chain branch May 13, 2026 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants