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#762
* Fix transform() corrupting TRUE/FALSE/NULL column defaults
quote_default_value() passed keyword-literal defaults (TRUE, FALSE, NULL)
through self.quote(), wrapping them in quotes. So transform() rebuilt a
column declared "INTEGER DEFAULT TRUE" as "INTEGER DEFAULT 'TRUE'", and a
later default insert stored the text 'TRUE' instead of the integer 1
(likewise 'FALSE' for 0 and 'NULL' for null) - silent value corruption.
Return these keyword literals unquoted, as already done for the
CURRENT_TIME/DATE/TIMESTAMP literals.
PR #764
* Recreate indexes when calling transform when possible and raise an error when they cannot be retained automatically
* Docs for sqlite_utils.db.TransformError
Co-authored-by: Simon Willison <swillison@gmail.com>
Closes#577
This should solve all sorts of problems seen by users of platforms that throw errors on writable_schema.
Also added `add_foreign_keys=` and `foreign_keys=` parameters to `table.transform()`.