Skip to content

Fix .transform() raising TransformError on column-level UNIQUE constraints#786

Open
ikatyal2110 wants to merge 1 commit into
simonw:mainfrom
ikatyal2110:claude/pensive-fermi-eyz071
Open

Fix .transform() raising TransformError on column-level UNIQUE constraints#786
ikatyal2110 wants to merge 1 commit into
simonw:mainfrom
ikatyal2110:claude/pensive-fermi-eyz071

Conversation

@ikatyal2110

@ikatyal2110 ikatyal2110 commented Jul 9, 2026

Copy link
Copy Markdown

When a table has a column-level UNIQUE constraint (e.g. name TEXT UNIQUE), SQLite backs it with an auto-index whose sql column in sqlite_master is NULL. The index-rebuild step in transform_sql() treated any NULL-sql index as unrecoverable, raising TransformError and aborting the transform entirely. This 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; 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 #762


Generated by Claude Code


📚 Documentation preview 📚: https://sqlite-utils--786.org.readthedocs.build/en/786/

…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
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.

.transform() drops check constraints and comments

2 participants