nullalign 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1af15eca93e06667b2a429e1c853c03c101a9425
4
- data.tar.gz: 3ba414cae84fceaf9ff1e66f65322eb3e6b153bc
3
+ metadata.gz: 657f6a975071d2ef7bfa17fb58ea80d6faa56a94
4
+ data.tar.gz: e67511b01e6a7a50d6efeecf44a7c3d882e8083d
5
5
  SHA512:
6
- metadata.gz: cb64c015c7b25c0c070d97157df4b5d027b77170884bafe5d15bfb2cbdae3f5a144be744ed4a7a750e0106da661e303a1c32f4a0c8f0f224cb08fe2cb9f91034
7
- data.tar.gz: 46e03a6c9c628434afbbdf27f2be293eaa4ed7b68ceb146f14fa97f7b94b9e98ccbde3fff140ba73c35f7bc319064e6e6641937746d61e11d74aa2faaebb9ce6
6
+ metadata.gz: 298ebc2eaeea4b157d574d9858c8ba40e6c308779490cae645bce7ba93e0d97c539527621e65b0e56421f3d68789c3bb240527f067b01a24bd614b8ece9eed8c
7
+ data.tar.gz: b89c85dc3acabd3f87aae7920909fc4bc1ee7ce6287f921c4e0b91b4343a943e543739253b43d9f72a1d1180dcf501c331d149d35b56cfef1b01f3898ebedded
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.0.3 Feb 14 2018
4
+ * Add nullalign:fix Rake task
5
+
3
6
  ## v0.0.2 Oct 23 2017
4
7
  * Skip conditional validations
5
8
 
data/README.md CHANGED
@@ -35,6 +35,12 @@ Run it like this:
35
35
  CheckinLabel checkin_labels: name, xml
36
36
  CheckinTime checkin_times: campus
37
37
 
38
+ ## Generating a migration
39
+
40
+ You can also run a Rake task which will generate a migration which will add indexes as needed:
41
+
42
+ bundle exec rake nullalign:fix
43
+
38
44
  ## Limitations
39
45
 
40
46
  nullalign depends on being able to find all your `ActiveRecord::Base`
@@ -51,6 +57,7 @@ like 'nonullalign' if people think that would be useful. Just let me know.
51
57
 
52
58
  * [Tom Copeland](https://thomasleecopeland.com) - author
53
59
  * [Woongcheol Yang](https://github.com/woongy) - support for conditional validations
60
+ * [Paweł Dąbrowski](https://twitter.com/pdabrowski_k1) - Rake task suggestion
54
61
 
55
62
  ## Tests
56
63
 
data/lib/nullalign.rb CHANGED
@@ -2,6 +2,7 @@ require 'nullalign/models'
2
2
  require 'nullalign/introspectors/table_data'
3
3
  require 'nullalign/introspectors/validates_presence_of'
4
4
  require 'nullalign/reporter'
5
+ require 'nullalign/railtie'
5
6
 
6
7
  module Nullalign
7
8
  def self.run
@@ -15,9 +16,40 @@ module Nullalign
15
16
  reporter.report_validates_presence_problems(problems)
16
17
  problems.empty?
17
18
  end
18
-
19
+
20
+ def self.generate_migration
21
+ models = Nullalign::Models.new($LOAD_PATH)
22
+ models.preload_all
23
+
24
+ reporter = Nullalign::Reporter.new
25
+
26
+ introspector = Nullalign::Introspectors::ValidatesPresenceOf.new
27
+ problems = problems(models.all, introspector)
28
+ if problems.empty?
29
+ puts "Hooray! All presence validators are backed by a non-null constraint."
30
+ else
31
+ str = "class AddMissingNonnullConstraints < ActiveRecord::Migration[5.1]\n"
32
+ str << " def change\n"
33
+ null_constraints_by_table_name = problems.map do |model, columns|
34
+ [model.name, model, columns]
35
+ end.sort_by(&:first)
36
+ counter = 0
37
+ null_constraints_by_table_name.each do |table_name, model, columns|
38
+ columns.each do |constraint|
39
+ counter += 1
40
+ str << " change_column_null :#{model.table_name}, :#{constraint.column}, false\n"
41
+ end
42
+ end
43
+ str << " end\n"
44
+ str << "end\n"
45
+ filename = "db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_add_missing_nonnull_constraints.rb"
46
+ puts "Adding migration #{File.basename(filename)} containing #{counter} change_column_null entries"
47
+ File.open(filename, "w") {|f| f.syswrite(str)}
48
+ end
49
+ end
50
+
19
51
  private
20
-
52
+
21
53
  def self.problems(models, introspector)
22
54
  models.map do |m|
23
55
  [m, introspector.missing_nonnull_constraints(m)]
@@ -25,4 +57,4 @@ module Nullalign
25
57
  columns.empty?
26
58
  end
27
59
  end
28
- end
60
+ end
@@ -0,0 +1,9 @@
1
+ if defined?(Rails)
2
+ module Nullalign
3
+ class Railtie < Rails::Railtie
4
+ rake_tasks do
5
+ load 'tasks/nullalign.rake'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Nullalign
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,6 @@
1
+ namespace :nullalign do
2
+ desc "Generate a migration to fix issues nullalign found"
3
+ task fix: :environment do
4
+ Nullalign.generate_migration
5
+ end
6
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nullalign
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Copeland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-23 00:00:00.000000000 Z
11
+ date: 2018-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -75,10 +75,12 @@ files:
75
75
  - lib/nullalign/introspectors/validates_presence_of.rb
76
76
  - lib/nullalign/models.rb
77
77
  - lib/nullalign/nonnull_constraint.rb
78
+ - lib/nullalign/railtie.rb
78
79
  - lib/nullalign/reporter.rb
79
80
  - lib/nullalign/reporters/base.rb
80
81
  - lib/nullalign/reporters/validates_presence_of.rb
81
82
  - lib/nullalign/version.rb
83
+ - lib/tasks/nullalign.rake
82
84
  - nullalign.gemspec
83
85
  - spec/introspectors/table_data_spec.rb
84
86
  - spec/introspectors/validates_presence_of_spec.rb