database_consistency 3.0.3 → 3.0.4
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
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4830aa2e788dbbee5e54ce2748509ef5b8bfab2c76e4355edcefff9ce04775de
|
|
4
|
+
data.tar.gz: 26e284719ae0b7289164b34a6b0e9ccfaca84bbbd473451ec9114cd0fe57457b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8a6668676b8aca9c6e4dd55768c5c1c94b37c9de320ae38a535d8a69b49b164940a3ed7f5c2e12de24ccb208d7100863fa54cf715b879c99ca07850bb4565a46
|
|
7
|
+
data.tar.gz: be80eee01a075040572372ddcba789ac392003f0dc269a491a810b7acbe05bfafd05c60702f0d2f7aed7785547c97fe1f27dbff25d4679aaeaa0af0cc1a44141
|
data/bin/database_consistency
CHANGED
|
@@ -39,10 +39,17 @@ opt_parser = OptionParser.new do |opts|
|
|
|
39
39
|
options[:todo] = true
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
opts.on('-f', '--autofix',
|
|
42
|
+
opts.on('-f', '--autofix',
|
|
43
|
+
'Automatically fixes issues by adjusting the code or generating missing migrations.') do
|
|
43
44
|
options[:autofix] = true
|
|
44
45
|
end
|
|
45
46
|
|
|
47
|
+
opts.on('--only-checkers=LIST', Array,
|
|
48
|
+
'When used with --autofix, restricts the fix to offenses produced by the listed checker ' \
|
|
49
|
+
'class names (comma-separated, e.g. ColumnPresenceChecker,NullConstraintChecker).') do |checkers|
|
|
50
|
+
options[:only_checkers] = checkers
|
|
51
|
+
end
|
|
52
|
+
|
|
46
53
|
opts.on('-h', '--help', 'Prints this help.') do
|
|
47
54
|
puts opts
|
|
48
55
|
exit
|
|
@@ -51,6 +58,11 @@ end
|
|
|
51
58
|
|
|
52
59
|
opt_parser.parse!
|
|
53
60
|
|
|
61
|
+
if options[:only_checkers] && !options[:autofix]
|
|
62
|
+
warn '--only-checkers requires --autofix'
|
|
63
|
+
exit 1
|
|
64
|
+
end
|
|
65
|
+
|
|
54
66
|
base_dir = File.join(Dir.pwd, ARGV.first.to_s)
|
|
55
67
|
unless File.realpath(base_dir).start_with?(Dir.pwd)
|
|
56
68
|
puts "\nWarning! You are going out of current directory, ruby version may be wrong and some gems may be missing.\n"
|
|
@@ -75,5 +87,10 @@ $LOAD_PATH.unshift(File.expand_path('lib', __dir__))
|
|
|
75
87
|
require 'database_consistency'
|
|
76
88
|
|
|
77
89
|
# Process checks
|
|
78
|
-
|
|
90
|
+
begin
|
|
91
|
+
code = DatabaseConsistency.run(config, **options)
|
|
92
|
+
rescue DatabaseConsistency::Writers::AutofixWriter::UnknownCheckerError => e
|
|
93
|
+
warn e.message
|
|
94
|
+
exit 1
|
|
95
|
+
end
|
|
79
96
|
exit code
|
|
@@ -5,6 +5,8 @@ module DatabaseConsistency
|
|
|
5
5
|
module Writers
|
|
6
6
|
# The simplest formatter
|
|
7
7
|
class AutofixWriter < BaseWriter
|
|
8
|
+
UnknownCheckerError = Class.new(StandardError)
|
|
9
|
+
|
|
8
10
|
SLUG_TO_GENERATOR = {
|
|
9
11
|
association_missing_index: Autofix::AssociationMissingIndex,
|
|
10
12
|
association_missing_null_constraint: Autofix::NullConstraintMissing,
|
|
@@ -20,6 +22,29 @@ module DatabaseConsistency
|
|
|
20
22
|
three_state_boolean: Autofix::NullConstraintMissing
|
|
21
23
|
}.freeze
|
|
22
24
|
|
|
25
|
+
class << self
|
|
26
|
+
def validate_scope!(scope)
|
|
27
|
+
return if scope.nil?
|
|
28
|
+
|
|
29
|
+
known = concrete_checker_names
|
|
30
|
+
unknown = scope - known
|
|
31
|
+
return if unknown.empty?
|
|
32
|
+
|
|
33
|
+
raise UnknownCheckerError,
|
|
34
|
+
"unknown checker(s): #{unknown.join(', ')}. Known: #{known.join(', ')}"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def concrete_checker_names
|
|
40
|
+
Checkers::BaseChecker.descendants
|
|
41
|
+
.reject { |checker| checker.superclass == Checkers::BaseChecker }
|
|
42
|
+
.map(&:checker_name)
|
|
43
|
+
.uniq
|
|
44
|
+
.sort
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
23
48
|
def write
|
|
24
49
|
unique_generators.each(&:fix!)
|
|
25
50
|
end
|
|
@@ -35,7 +60,13 @@ module DatabaseConsistency
|
|
|
35
60
|
end
|
|
36
61
|
|
|
37
62
|
def fix?(report)
|
|
38
|
-
report.status == :fail
|
|
63
|
+
report.status == :fail && scoped?(report)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def scoped?(report)
|
|
67
|
+
return true if opts.nil?
|
|
68
|
+
|
|
69
|
+
opts.include?(report.checker_name)
|
|
39
70
|
end
|
|
40
71
|
|
|
41
72
|
def generator(report)
|
|
@@ -4,15 +4,16 @@ module DatabaseConsistency
|
|
|
4
4
|
module Writers
|
|
5
5
|
# The base class for writers
|
|
6
6
|
class BaseWriter
|
|
7
|
-
attr_reader :results, :config
|
|
7
|
+
attr_reader :results, :config, :opts
|
|
8
8
|
|
|
9
|
-
def initialize(results, config: Configuration.new)
|
|
9
|
+
def initialize(results, config: Configuration.new, opts: nil)
|
|
10
10
|
@results = results
|
|
11
11
|
@config = config
|
|
12
|
+
@opts = opts
|
|
12
13
|
end
|
|
13
14
|
|
|
14
|
-
def self.write(results, config: Configuration.new)
|
|
15
|
-
new(results, config: config).write
|
|
15
|
+
def self.write(results, config: Configuration.new, opts: nil)
|
|
16
|
+
new(results, config: config, opts: opts).write
|
|
16
17
|
end
|
|
17
18
|
end
|
|
18
19
|
end
|
data/lib/database_consistency.rb
CHANGED
|
@@ -116,12 +116,15 @@ require 'database_consistency/checkers/index_checkers/redundant_unique_index_che
|
|
|
116
116
|
# The root module
|
|
117
117
|
module DatabaseConsistency
|
|
118
118
|
class << self
|
|
119
|
-
def run(*args, **opts) # rubocop:disable Metrics/MethodLength
|
|
119
|
+
def run(*args, **opts) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
|
120
120
|
configuration = Configuration.new(*args)
|
|
121
|
+
|
|
122
|
+
Writers::AutofixWriter.validate_scope!(opts[:only_checkers]) if opts[:autofix]
|
|
123
|
+
|
|
121
124
|
reports = Processors.reports(configuration)
|
|
122
125
|
|
|
123
126
|
if opts[:autofix]
|
|
124
|
-
Writers::AutofixWriter.write(reports, config: configuration)
|
|
127
|
+
Writers::AutofixWriter.write(reports, config: configuration, opts: opts[:only_checkers])
|
|
125
128
|
|
|
126
129
|
0
|
|
127
130
|
elsif opts[:todo]
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: database_consistency
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.0.
|
|
4
|
+
version: 3.0.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Evgeniy Demin
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-04-
|
|
11
|
+
date: 2026-04-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|