Conversation
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.
Fixes #1131
SQLite only hands out ids automatically for a column declared exactly as a single-column
INTEGER PRIMARY KEY(a rowid alias). Our migrations createvendor.idthat way, but a database that has been through an export/convert round trip (aBIGINTid, or a primary key that got dropped on the way) comes back without the alias, and from then on everyINSERT INTO vendorthat doesn't carry an explicit id fails withNOT NULL constraint failed: vendor.id, which is the traceback in the issue. Reads and updates keep working, matching what was reported.This adds a migration that, on SQLite only, checks
PRAGMA table_info('vendor')and, if the id isn't a single-column INTEGER primary key, rebuilds the table through alembic's batch mode with the schema the initial migration always intended, keeping every row, the filament/vendor_field references andix_vendor_id. Healthy databases are left untouched (it's a single PRAGMA read), other database types return immediately. I couldn't see the reporter's actual schema, but a non-alias id is the only way SQLite produces this error on an insert without an id, so the check covers the shapes a conversion can leave behind. Only vendor is touched since that's what was reported; if a converted db turns out to have the same problem on filament/spool the same check can be generalised.How I've tested it: a new unit test upgrades a temp sqlite db to the previous revision, rewrites the vendor table with a
BIGINTid (which reproduces the exact IntegrityError), then upgrades to head and checks that inserts auto-increment again continuing after the existing ids, that the existing vendors plus a filament and a vendor_field pointing at them survive, thatPRAGMA foreign_key_checkis clean and the index is back. A second test checks a healthy db'svendorschema is byte-identical before and after.pytest testspasses (275 tests), ruff check and format are clean on the new files.