Fixes #587: Use actual FK target column in migration 0011#590
Conversation
The REFERENCES clause hardcoded "id" but multi-table-inheritance COTs use customobject_ptr_id as their PK. The information_schema query already joins constraint_column_usage which holds the real referenced column name; select it and use it instead of the literal. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@claude /review and limit response to areas of potential concern. |
|
Claude finished @bctiemann's task in 51s —— View job Review: Fixes #587 — Use actual FK target column in migration 0011
The fix is correct and minimal. Two areas worth flagging: 1. Multiple rows per constraint if composite FKs existThe query joins In practice this cannot occur today — all FKs on Risk level: Low (no composite FKs exist or are planned), but worth documenting or guarding with a 2. F-string SQL with DB-sourced identifiers
No other concerns. The core logic change — pulling |
Fixes: #587
Summary
Migration
0011_non_deferrable_fk_constraintsreconstructs DEFERRABLE FK constraints as non-DEFERRABLE. TheREFERENCESclause hardcoded"id"as the target column, but COTs created under multi-table inheritance usecustomobject_ptr_idas their primary key. PostgreSQL rejects the constraint because the columnidliterally does not exist on those tables.The fix: the query already joins
information_schema.constraint_column_usage, which records the actual referenced column name. Addingccu.column_name AS foreign_column_nameto the SELECT and using it in theREFERENCESclause makes the migration correct for both standard (id) and MTI (customobject_ptr_id) COTs.Local verification
Verified with a direct DB script that:
custom_objects_test_*table (PK=customobject_ptr_id) and a through table with a DEFERRABLE FK pointing at itProgrammingError: column "id" referenced in foreign key constraint does not existcustomobject_ptr_idTest plan
🤖 Generated with Claude Code