nullalign 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +7 -0
- data/lib/nullalign.rb +35 -3
- data/lib/nullalign/railtie.rb +9 -0
- data/lib/nullalign/version.rb +1 -1
- data/lib/tasks/nullalign.rake +6 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 657f6a975071d2ef7bfa17fb58ea80d6faa56a94
|
4
|
+
data.tar.gz: e67511b01e6a7a50d6efeecf44a7c3d882e8083d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 298ebc2eaeea4b157d574d9858c8ba40e6c308779490cae645bce7ba93e0d97c539527621e65b0e56421f3d68789c3bb240527f067b01a24bd614b8ece9eed8c
|
7
|
+
data.tar.gz: b89c85dc3acabd3f87aae7920909fc4bc1ee7ce6287f921c4e0b91b4343a943e543739253b43d9f72a1d1180dcf501c331d149d35b56cfef1b01f3898ebedded
|
data/CHANGELOG.md
CHANGED
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
|
data/lib/nullalign/version.rb
CHANGED
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.
|
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:
|
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
|