Verify foreign keys after mount when configured#56
Merged
Conversation
This was referenced May 6, 2026
Mirror Rails' fixture-loading FK check: when ActiveRecord.verify_foreign_keys_for_fixtures is true (default since Rails 8.0 load_defaults), call connection.check_all_foreign_keys_valid! after the batch executes. PG and SQLite raise on violations; MySQL is a no-op. Wrap any StatementInvalid in a FixtureKit::Error with a hint that the cache may be stale relative to the schema or fixture definitions — most likely trigger is a developer regenerating fixtures against a different schema than the one currently loaded. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
5ce3547 to
c27556a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Mirror Rails' fixture-loading FK check: when
ActiveRecord.verify_foreign_keys_for_fixturesis true, callconnection.check_all_foreign_keys_valid!after the batch executes. Wrap any violation in aFixtureKit::Errorwith a hint that the cache may be stale.Behavior
load_defaultsis true, so this turns on automatically for new apps.Why
The most likely trigger is regenerating fixtures against a different schema than the one currently loaded — e.g. someone changed an FK column in a migration but the cached fixture still references the old shape. Surface that as a fixture_kit error rather than a raw
ActiveRecord::StatementInvalidthat's hard to interpret.Stack
Stacked on #55.
Test plan
🤖 Generated with Claude Code