Fix .transform() raising TransformError on column-level UNIQUE constraints#786
Open
ikatyal2110 wants to merge 1 commit into
Open
Fix .transform() raising TransformError on column-level UNIQUE constraints#786ikatyal2110 wants to merge 1 commit into
ikatyal2110 wants to merge 1 commit into
Conversation
…aints SQLite backs a column-level UNIQUE constraint with an auto-index whose sql in sqlite_master is NULL. The index-rebuild step in transform_sql() treated any NULL-sql index as an error, causing TransformError on tables with UNIQUE columns. The fix adds a 'unique' parameter to create_table_sql so the constraint is reproduced as an inline UNIQUE column attribute in the new CREATE TABLE statement. In transform_sql(), auto-UNIQUE indices (origin='u') are collected before the CREATE TABLE call and passed via unique=; the index rebuild loop then skips them with a continue instead of raising. Column renames are applied to the constraint; dropping a UNIQUE column drops its constraint silently. Fixes simonw#762
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.
When a table has a column-level
UNIQUEconstraint (e.g.name TEXT UNIQUE), SQLite backs it with an auto-index whosesqlcolumn insqlite_masterisNULL. The index-rebuild step intransform_sql()treated anyNULL-sql index as unrecoverable, raisingTransformErrorand aborting the transform entirely. This adds auniqueparameter tocreate_table_sqlso the constraint is reproduced as an inlineUNIQUEcolumn attribute in the newCREATE TABLEstatement; the index loop now skips auto-UNIQUE indices (origin="u") instead of raising. Column renames are applied to the constraint, and dropping a UNIQUE column drops its constraint silently. Fixes #762Generated by Claude Code
📚 Documentation preview 📚: https://sqlite-utils--786.org.readthedocs.build/en/786/