mirror of
https://github.com/open-webui/open-webui.git
synced 2026-07-16 23:21:44 -05:00
[PR #24692] [CLOSED] fix: don't break fresh-DB installs in oauth_session / user-update migrations #98823
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/24692
Author: @Classic298
Created: 5/13/2026
Status: ❌ Closed
Base:
dev← Head:fix/fresh-db-migrations📝 Commits (2)
614c1cffix: don't break fresh-DB installs in user-related migrationsc8a6f05fix: make alembic downgrade chain reversible on fresh DBs📊 Changes
5 files changed (+60 additions, -48 deletions)
View changed files
📝
backend/open_webui/migrations/versions/38d63c18f30f_add_oauth_session_table.py(+8 -12)📝
backend/open_webui/migrations/versions/4ace53fd72c8_update_folder_table_datetime.py(+8 -4)📝
backend/open_webui/migrations/versions/56359461a091_add_calendar_tables.py(+23 -13)📝
backend/open_webui/migrations/versions/b10670c03dd5_update_user_table.py(+9 -7)📝
backend/open_webui/migrations/versions/d4e5f6a7b8c9_add_automation_tables.py(+12 -12)📄 Description
After
2c2d06c31("refac: deprecate peewee migration layer") removed the peewee bootstrap, fresh databases now enter alembic with the schema as declared by the init migration (7e5b5dc7342b). Two later migrations were written under the old assumption that the schema came from peewee and silently break the fresh-install path:38d63c18f30f (Add oauth_session table) — gated its user-PK fixup on
not id_column.get('unique', False). Postgres reports PK columns as not-separately-unique, so the gate is True on fresh DBs and the block unconditionally callscreate_primary_key('pk_user_id', ['id'])on a table that already has a PK onid. Postgres rejects with:That rolls the entire alembic transaction back (DDL is transactional on Postgres), so on startup the config table doesn't exist either, and STATE.load() crashes with:
SQLite tolerated this because batch_alter_table rebuilds the table from scratch — the duplicate PK was lost in the copy. Reported by urbenlegend on open-webui#24560 (last reply on dev).
Fix: gate on "PK isn't already on
id", so the block only runs on legacy peewee-shaped schemas.b10670c03dd5 (Update user table) —
_drop_sqlite_indexes_for_columnissued DROP INDEX on every index referencing the target column, including the auto-created indexes that back UNIQUE constraints (e.g.sqlite_autoindex_user_2foroauth_sub). SQLite refuses:This is invisible on Postgres (the dialect branch is gated to
if conn.dialect.name == 'sqlite'), but stops the migration chain partway through on every fresh SQLite install.Fix: skip
sqlite_autoindex_*indexes —batch_alter_table.drop_columnlater handles them through its table-rebuild path.Verified both fixes with embedded postgres (via pgserver) and SQLite — all 44 migrations run cleanly to head on both, and
STATE.load()no longer raises.Contributor License Agreement
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.