Closed reconbot closed 9 years ago
that's not a bad idea. personally i usually create a spec/test that does this, e.g.
describe "Foreign keys" do
it "exist for all associations" do
Rails.application.eager_load!
missing_keys, = Immigrant::KeyFinder.new.infer_keys
missing_key_columns = missing_keys.map { |key| "#{key.from_table}.#{key.options[:column]}" }
expect(missing_key_columns).to be_empty, -> {
author = `git --no-pager show -s --format='%an'`.gsub(/\s/, "").camelize
<<-TEXT.strip_heredoc
expected all foreign keys to exist, no key(s) found for:
* #{missing_key_columns.join("\n * ")}
Hint: run `rails g immigration #{author}TotesForgotAboutReferentialIntegrity`
to automatically add all missing keys
You can change the migration name if you really want to :P
TEXT
}
end
end
though adding a single rake task to your CI is a little easier than copy/pasting an entire spec like that
i'd happily accept a PR along these lines, just a couple suggestions:
Immigrant::KeyFinder#infer_keys
(or wherever). that way it doesn't need to be done in the rake task, and you'd get consistent behavior both in the generator and the rake taskignore:
key ... that way other settings/overrides could be added down the road (e.g. if we make #19 configurable)v0.3.2 has been released with the new rake task. sorry about the delay :( ... thought i had already done it
Lets keep this ticket open until I or someone else builds ignore support!
<3
I added immigrant to my CI. I don't know if you'd like immigrant to include this functionality but I thought others might find it useful.
I made a rake task that checked for any missing foreign key relationships and exits with an error if it finds any.
The
.immigrant.yml
looks like thisI welcome feedback and I'm happy to make a PR if you want to add the feature.