database_consistency 1.1.15 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/database_consistency +8 -3
- data/lib/database_consistency/configuration.rb +11 -3
- data/lib/database_consistency/databases/types/base.rb +1 -1
- data/lib/database_consistency/processors/base_processor.rb +6 -1
- data/lib/database_consistency/processors/indexes_processor.rb +1 -1
- data/lib/database_consistency/version.rb +1 -1
- data/lib/database_consistency/writers/todo_writer.rb +43 -0
- data/lib/database_consistency.rb +10 -6
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f2d13b99e730f1045b98f63239a77820a81908d2ec05232461bf12275489d5d
|
4
|
+
data.tar.gz: 7f92339d4b0241a15f422f64fdd80eab8db3f64c7cd8c405f91d787851fa3400
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4970958fca4670dda454bdaf699e96c013fc443d9bfeea4e11638ed2ad38f567f1f07ddec0785310bfac9e7afc58dd014df94872519c6ed4b7bfb3a405cc5a75
|
7
|
+
data.tar.gz: b3656fa0f395f2e87914b4d217eeea445b9fca195d5db0a4ca9ac596bdf5a81a5662c18dc714a1191a9f61fe714814706428cff6c0816e295ffa15650ffd7917
|
data/bin/database_consistency
CHANGED
@@ -24,17 +24,22 @@ end
|
|
24
24
|
require 'optparse'
|
25
25
|
|
26
26
|
config = [default_config]
|
27
|
+
options = {}
|
27
28
|
opt_parser = OptionParser.new do |opts|
|
28
29
|
opts.banner = <<-DESC
|
29
30
|
Usage: database_consistency install - run installation
|
30
31
|
database_consistency [options]
|
31
32
|
DESC
|
32
33
|
|
33
|
-
opts.on('-cFILE', '--config=FILE', 'Use additional configuration file') do |f|
|
34
|
+
opts.on('-cFILE', '--config=FILE', 'Use additional configuration file.') do |f|
|
34
35
|
config << f
|
35
36
|
end
|
36
37
|
|
37
|
-
opts.on('-
|
38
|
+
opts.on('-g', '--generate-todo', 'Generate TODO file with every failing check disabled. You can pass existing configurations so the generated file will have only new failures.') do |f|
|
39
|
+
options[:todo] = true
|
40
|
+
end
|
41
|
+
|
42
|
+
opts.on('-h', '--help', 'Prints this help.') do
|
38
43
|
puts opts
|
39
44
|
exit
|
40
45
|
end
|
@@ -66,5 +71,5 @@ $LOAD_PATH.unshift(File.expand_path('lib', __dir__))
|
|
66
71
|
require 'database_consistency'
|
67
72
|
|
68
73
|
# Process checks
|
69
|
-
code = DatabaseConsistency.run(config)
|
74
|
+
code = DatabaseConsistency.run(config, **options)
|
70
75
|
exit code
|
@@ -37,22 +37,30 @@ module DatabaseConsistency
|
|
37
37
|
def enabled?(*path)
|
38
38
|
current = configuration
|
39
39
|
|
40
|
+
value = global_enabling
|
41
|
+
|
40
42
|
path.each do |key|
|
41
43
|
current = current[key.to_s]
|
42
|
-
return
|
44
|
+
return value unless current.is_a?(Hash)
|
43
45
|
|
44
46
|
next if current['enabled'].nil?
|
45
47
|
|
46
|
-
|
48
|
+
value = current['enabled']
|
47
49
|
end
|
48
50
|
|
49
|
-
|
51
|
+
value
|
50
52
|
end
|
51
53
|
|
52
54
|
private
|
53
55
|
|
54
56
|
attr_reader :configuration
|
55
57
|
|
58
|
+
def global_enabling
|
59
|
+
value = configuration.dig('DatabaseConsistencyCheckers', 'All', 'enabled')
|
60
|
+
|
61
|
+
value.nil? ? true : value
|
62
|
+
end
|
63
|
+
|
56
64
|
def load_yaml_config_file(filepath)
|
57
65
|
if YAML.respond_to?(:safe_load_file)
|
58
66
|
YAML.safe_load_file(filepath, aliases: true)
|
@@ -25,8 +25,13 @@ module DatabaseConsistency
|
|
25
25
|
end
|
26
26
|
|
27
27
|
# @return [Array<Hash>]
|
28
|
-
def reports
|
28
|
+
def reports(catch_errors: true)
|
29
29
|
@reports ||= check
|
30
|
+
rescue StandardError => e
|
31
|
+
raise e unless catch_errors
|
32
|
+
|
33
|
+
RescueError.call(e)
|
34
|
+
[]
|
30
35
|
end
|
31
36
|
|
32
37
|
# @return [Array<Class>]
|
@@ -16,7 +16,7 @@ module DatabaseConsistency
|
|
16
16
|
Helper.parent_models.flat_map do |model|
|
17
17
|
next unless configuration.enabled?(model.name.to_s)
|
18
18
|
|
19
|
-
indexes =
|
19
|
+
indexes = model.connection.indexes(model.table_name)
|
20
20
|
|
21
21
|
indexes.flat_map do |index|
|
22
22
|
enabled_checkers.map do |checker_class|
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseConsistency
|
4
|
+
# The module contains formatters
|
5
|
+
module Writers
|
6
|
+
# The writer that generates to-do file
|
7
|
+
class TodoWriter < BaseWriter
|
8
|
+
def write
|
9
|
+
hash = results.each_with_object({}) do |result, hash|
|
10
|
+
next unless write?(result.status)
|
11
|
+
|
12
|
+
assign_result(hash, result)
|
13
|
+
end
|
14
|
+
|
15
|
+
File.write(file_name, hash.to_yaml)
|
16
|
+
end
|
17
|
+
|
18
|
+
def write?(status)
|
19
|
+
status == :fail
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def assign_result(hash, result)
|
25
|
+
hash[result.table_or_model_name] ||= {}
|
26
|
+
hash[result.table_or_model_name][result.column_or_attribute_name] ||= {}
|
27
|
+
hash[result.table_or_model_name][result.column_or_attribute_name][result.checker_name] = {'enabled' => false}
|
28
|
+
end
|
29
|
+
|
30
|
+
def file_name
|
31
|
+
[nil, *(1..100)].each do |number|
|
32
|
+
name = generate_file_name(number)
|
33
|
+
|
34
|
+
return name unless File.exists?(name)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def generate_file_name(number = nil)
|
39
|
+
".database_consistency.todo#{number}.yml"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/database_consistency.rb
CHANGED
@@ -10,6 +10,7 @@ require 'database_consistency/errors'
|
|
10
10
|
|
11
11
|
require 'database_consistency/writers/base_writer'
|
12
12
|
require 'database_consistency/writers/simple_writer'
|
13
|
+
require 'database_consistency/writers/todo_writer'
|
13
14
|
|
14
15
|
require 'database_consistency/databases/factory'
|
15
16
|
require 'database_consistency/databases/types/base'
|
@@ -48,16 +49,19 @@ require 'database_consistency/processors/indexes_processor'
|
|
48
49
|
# The root module
|
49
50
|
module DatabaseConsistency
|
50
51
|
class << self
|
51
|
-
def run(*args)
|
52
|
+
def run(*args, **opts)
|
52
53
|
configuration = Configuration.new(*args)
|
53
54
|
reports = Processors.reports(configuration)
|
54
55
|
|
55
|
-
|
56
|
-
reports,
|
57
|
-
config: configuration
|
58
|
-
)
|
56
|
+
if opts[:todo]
|
57
|
+
Writers::TodoWriter.write(reports, config: configuration)
|
59
58
|
|
60
|
-
|
59
|
+
0
|
60
|
+
else
|
61
|
+
Writers::SimpleWriter.write(reports, config: configuration)
|
62
|
+
|
63
|
+
reports.any? { |report| report.status == :fail } || !RescueError.empty? ? 1 : 0
|
64
|
+
end
|
61
65
|
end
|
62
66
|
end
|
63
67
|
end
|
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: 1.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evgeniy Demin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -180,6 +180,7 @@ files:
|
|
180
180
|
- lib/database_consistency/version.rb
|
181
181
|
- lib/database_consistency/writers/base_writer.rb
|
182
182
|
- lib/database_consistency/writers/simple_writer.rb
|
183
|
+
- lib/database_consistency/writers/todo_writer.rb
|
183
184
|
homepage: https://github.com/djezzzl/database_consistency
|
184
185
|
licenses:
|
185
186
|
- MIT
|
@@ -199,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
200
|
- !ruby/object:Gem::Version
|
200
201
|
version: '0'
|
201
202
|
requirements: []
|
202
|
-
rubygems_version: 3.1
|
203
|
+
rubygems_version: 3.0.3.1
|
203
204
|
signing_key:
|
204
205
|
specification_version: 4
|
205
206
|
summary: Provide an easy way to check the consistency of the database constraints
|