Additional findings:
- Third case that breaks FKs: changing PK away from referenced column
(SQLite requires FK targets to be PRIMARY KEY or UNIQUE)
- Detection is easy: iterate tables, find incoming FKs, check if
referenced columns are being renamed/dropped/losing uniqueness
- Automatic fixing for renames is moderate complexity: transform
referencing tables first to update their FK constraints
- Challenges include circular references and transaction safety
- Proposed API: update_incoming_fks=True flag or better error messages
Document findings from investigation into how the transform() method
handles foreign key constraints that REFERENCE the table being transformed
(incoming FKs from other tables).
Key findings:
- Incoming FKs survive transform because SQLite's ALTER TABLE RENAME
automatically updates FK references in the schema
- Renaming a referenced COLUMN breaks incoming FKs because SQLite
cannot update column references
- With FK enforcement ON, transform() correctly detects and rolls back
operations that would break FK constraints
- With FK enforcement OFF, transforms that break FKs succeed but leave
the database in an inconsistent state
Also documents a minor issue: leftover temp tables when transform fails.