Skip to content

Fix shopkeeper deletion FK violation on item_tags#38

Merged
dadachi merged 1 commit intomainfrom
fix/shopkeeper-deletion-foreign-key-violation
Apr 9, 2026
Merged

Fix shopkeeper deletion FK violation on item_tags#38
dadachi merged 1 commit intomainfrom
fix/shopkeeper-deletion-foreign-key-violation

Conversation

@dadachi
Copy link
Copy Markdown
Contributor

@dadachi dadachi commented Apr 9, 2026

Summary

  • Shopkeeper deletion (DELETE /shopkeeper_auth) failed with ActiveRecord::InvalidForeignKey because item_tags had RESTRICT foreign keys referencing shopkeepers via completed_by_id and created_by_id
  • Changed 2 FK constraints to ON DELETE SET NULL at both DB level (migration) and Rails level (dependent: :nullify) so item_tag records are preserved with nullified shopkeeper references
  • Added model and controller tests covering cross-account shopkeeper deletion with existing item_tags

Test plan

  • bin/ci passes
  • Verify shopkeeper deletion works in staging when the shopkeeper has item_tags in other accounts
  • Confirm item_tags retain their records with nullified completed_by_id/created_by_id after shopkeeper deletion

🤖 Generated with Claude Code

Shopkeeper deletion (DELETE /shopkeeper_auth) failed with
ActiveRecord::InvalidForeignKey because item_tags had RESTRICT foreign
keys on completed_by_id and created_by_id. Changed these 2 FK
constraints to ON DELETE SET NULL at both DB and model level so
item_tags are preserved with nullified shopkeeper references.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dadachi dadachi merged commit d7db191 into main Apr 9, 2026
3 checks passed
@dadachi dadachi deleted the fix/shopkeeper-deletion-foreign-key-violation branch April 9, 2026 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant