fix(db): skip SQLite-only migrations on Postgres - #5967
Open
ataliba wants to merge 1 commit into
Open
Conversation
All _migrate_* helpers used PRAGMA table_info / sqlite3.connect against the file path, which breaks once the engine is Postgres. Add _is_sqlite() and short-circuit every migration when the configured dialect isn't sqlite; Postgres already gets the full current schema from Base.metadata.create_all().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
All
_migrate_*helpers incore/database.pyassume SQLite unconditionally — they runPRAGMA table_info(...)/sqlite3.connect(db_path)straight against whateverDATABASE_URLis configured. On Postgres these either raise a caught-and-logged syntax error (PRAGMAisn't valid Postgres SQL) or silently no-op (thesqlite3.connectpath treats a Postgres URL as a nonexistent file path and returns early) — either way the intended column/table changes never happen. Adds_is_sqlite()and an early-return guard at the top of every migration so they only run against a SQLite backend; Postgres installs already get the current schema fromBase.metadata.create_all()at first boot, so these migrations are meaningless there and were only ever silently failing, never actually needed.Verified against a real Postgres 17 deployment (192.168.68.22) that was hitting exactly the
PRAGMAsyntax errors described in the issue on every boot.Target branch
dev, notmain.Linked Issue
Fixes #5941
Type of Change
Checklist
devPRAGMA ... syntax errorlog spam on boot is gone and the app starts clean.How to Test
DATABASE_URLat a Postgres instance with an existing (older) schema.psycopg2.errors.SyntaxError: syntax error at or near "PRAGMA"on every migration call. After: none of those — each migration short-circuits via_is_sqlite()instead.Visual / UI changes