immigrant 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f292e08081ae86893e11a0e4cb0c70cb253b46bd
4
- data.tar.gz: 74415d7b626aee186fe3acfebb670b0bbeb5bbea
3
+ metadata.gz: 7dc2d24a68bb12d527576e6b877f143f2c42bf63
4
+ data.tar.gz: 02333cc92bc40d48c3f7e043b842432ee5998e00
5
5
  SHA512:
6
- metadata.gz: 4b6a46ea2a145202be72d7226767fec83d897b31940d08482c9feda25b8b99b825cb687cfec036d67b3c2c41c5057175cf80624a69d4195bae2b1df904bec5ae
7
- data.tar.gz: ee83ceacad979ff909934a4c852184a4f4b945726f9f5d9447b39d24275fb6d818e8d20f015cfc07f404405e8878f207f1c49ccaca3f4a520396bd58e870d9a2
6
+ metadata.gz: 165a88a133f812b38899ea19b2d0fc079956d5fae1c4c2814c53569d8da37502c3c37d6052d7069c171c43a671426eecfaac49710cec5854c561d9c45e3abd03
7
+ data.tar.gz: be53c1539e0c349c76afd32136fdec1df908f15ca25357e5321f77d76d1b7768d414516dae27814339c0fc040fa387a4196944927d298364d66e18868e976819
data/README.md CHANGED
@@ -28,6 +28,13 @@ evaluating the associations in your models (e.g. `belongs_to`, `has_many`, etc.)
28
28
  Only missing keys will be added; existing ones will never be altered or
29
29
  removed.
30
30
 
31
+ ### Rake Task
32
+
33
+ To help you remember to add keys in the future, there's a handy rake
34
+ task you can add to your CI setup. Just run `rake immigrant:check_keys`,
35
+ and if anything is missing it will tell you about it and exit with a
36
+ non-zero status.
37
+
31
38
  ## Considerations
32
39
 
33
40
  If the data in your tables is bad, then the migration will fail to run
@@ -6,8 +6,13 @@ module Immigrant
6
6
  Immigrant.load
7
7
  end
8
8
  end
9
+
9
10
  generators do
10
- require "generators/immigration_generator"
11
+ require 'generators/immigration_generator'
12
+ end
13
+
14
+ rake_tasks do
15
+ require 'immigrant/task'
11
16
  end
12
17
  end
13
- end
18
+ end
@@ -0,0 +1,20 @@
1
+ namespace :immigrant do
2
+ desc 'Checks for missing foreign key relationships in the database'
3
+ task check_keys: :environment do
4
+ Rails.application.eager_load!
5
+
6
+ keys, warnings = Immigrant::KeyFinder.new.infer_keys
7
+ warnings.values.each { |warning| $stderr.puts "WARNING: #{warning}" }
8
+
9
+ keys.each do |key|
10
+ column = key.options[:column]
11
+ pk = key.options[:primary_key]
12
+ $stderr.puts "Missing foreign key relationship on '#{key.from_table}.#{column}' to '#{key.to_table}.#{pk}'"
13
+ end
14
+
15
+ if keys.any?
16
+ puts 'Found missing foreign keys, run `rails generate immigration MigrationName` to create a migration to add them.'
17
+ exit keys.count
18
+ end
19
+ end
20
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: immigrant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Jensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-08 00:00:00.000000000 Z
11
+ date: 2015-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -50,6 +50,7 @@ files:
50
50
  - lib/immigrant/foreign_key_extensions.rb
51
51
  - lib/immigrant/loader.rb
52
52
  - lib/immigrant/railtie.rb
53
+ - lib/immigrant/task.rb
53
54
  - test/compat.rb
54
55
  - test/helper.rb
55
56
  - test/immigrant_test.rb
@@ -77,3 +78,4 @@ signing_key:
77
78
  specification_version: 4
78
79
  summary: Foreign key migration generator for Rails
79
80
  test_files: []
81
+ has_rdoc: