- Fix transform_sql to update other_column for self-referential FKs
when the referenced column is being renamed
- Skip FK validation during transform when update_incoming_fks=True
since self-referential FKs temporarily reference non-existent columns
- Add tests for multiple tables referencing renamed column
- Add test for self-referential FK handling
When renaming columns that are referenced by foreign keys in other
tables, the transform() method now accepts update_incoming_fks=True
to automatically update those FK constraints.
Implementation:
- Added _get_incoming_fks_needing_update() helper to find tables
with FKs pointing to renamed columns
- Modified transform() to collect SQL for updating incoming FKs
- Execute main transform first (so new column exists), then update
incoming FKs, all within the same transaction
- Added _skip_fk_validation flag to allow generating SQL for FKs
that reference columns that don't exist yet (will exist after
main transform completes)
Includes test for basic column rename case with FK enforcement ON.
* 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()`.