Preserve CHECK constraints when transforming a table

.transform() rebuilds from PRAGMA metadata, which doesn't expose CHECK
constraints, so they were silently dropped. Pull them from the schema
and re-add them to the rebuilt table.
This commit is contained in:
Apoorva Verma 2026-07-02 03:19:13 +05:30
commit 265f85052b
3 changed files with 304 additions and 2 deletions

View file

@ -1505,6 +1505,8 @@ To keep the original table around instead of dropping it, pass the ``keep_table=
table.transform(types={"age": int}, keep_table="original_table")
``CHECK`` constraints are preserved across a transform. If a column referenced by a constraint is renamed the constraint is updated to match, and if such a column is dropped the constraint is dropped along with it.
This method raises a ``sqlite_utils.db.TransformError`` exception if the table cannot be transformed, usually because there are existing constraints or indexes that are incompatible with modifications to the columns.
.. _python_api_transform_alter_column_types: