Skip to content

fix: resolve duplicate Alembic revision IDs causing missing oidc_subject column#72

Merged
boludo00 merged 1 commit intodevelopfrom
fix/duplicate-migration-ids
Mar 3, 2026
Merged

fix: resolve duplicate Alembic revision IDs causing missing oidc_subject column#72
boludo00 merged 1 commit intodevelopfrom
fix/duplicate-migration-ids

Conversation

@boludo00
Copy link
Copy Markdown
Owner

@boludo00 boludo00 commented Mar 3, 2026

Root cause

Two pairs of migration files had duplicate revision IDs:

File Old revision New revision
031_add_direct_download_settings.py 031 031b
032_add_library_mapping_to_booklore_servers.py 032 032b

When Alembic loads the versions/ directory it errors on duplicate revision IDs. The entrypoint.sh caught this with || echo "WARNING: Alembic migrations had issues" and continued, so migration 035 (which adds users.oidc_subject) never ran, producing:

sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedColumn) column users.oidc_subject does not exist

Changes

  • 031_add_direct_download_settings.py — revision 031031b
  • 032_add_flaresolverr_url.pydown_revision 031031b (keeps the direct-download chain intact)
  • 032_add_library_mapping_to_booklore_servers.py — revision 032032b
  • 034_merge_heads.py — updated down_revision to ('031', '031b', '032b', '033') so all four branch heads are merged
  • 035_add_oidc_fields.py — made idempotent (skips add_column/create_index if they already exist), defensive against databases bootstrapped with create_all
  • entrypoint.sh — two improvements:
    1. Detects legacy databases that have schema but no alembic_version table and stamps them at the correct revision (034 if oidc_subject is missing, heads if fully current) before running upgrade heads
    2. Fails loudly (exit 1) on migration errors instead of masking them

Test plan

  • Fresh container start against a new PostgreSQL database — all 36 migrations apply cleanly, app boots
  • Container start against a database stamped at 034 (missing oidc_subject) — migration 035 runs and adds the column
  • Container start against a database with tables but no alembic_version and no oidc_subject — entrypoint stamps at 034, then 035+036 run
  • Container start against a fully current database — no migrations run, app boots normally

… migration

Two pairs of migration files shared the same revision ID ('031' and '032').
Alembic fails with a duplicate-revision error when it loads the versions
directory, causing `alembic upgrade heads` to exit early. The entrypoint's
`|| echo WARNING` catch silently swallowed this failure, so migration 035
(which adds the `users.oidc_subject` column) never ran — producing the
`UndefinedColumn: users.oidc_subject` crash in production.

Fixes:
- 031_add_direct_download_settings: revision '031' → '031b'
- 032_add_library_mapping_to_booklore_servers: revision '032' → '032b'
- 032_add_flaresolverr_url: down_revision '031' → '031b'
- 034_merge_heads: down_revision includes all four branch heads
  ('031', '031b', '032b', '033')
- 035_add_oidc_fields: made idempotent (checks column/index existence)
- entrypoint.sh: detect legacy untracked databases and stamp at the
  correct revision; fail loudly on migration errors instead of masking them
@boludo00 boludo00 merged commit 9e85395 into develop Mar 3, 2026
2 checks passed
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.

1 participant