database_consistency 1.1.14 → 1.2.1
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 +4 -4
- data/bin/database_consistency +8 -3
- data/lib/database_consistency/checkers/association_checkers/association_checker.rb +1 -0
- data/lib/database_consistency/checkers/base_checker.rb +1 -1
- data/lib/database_consistency/checkers/column_checkers/column_checker.rb +1 -0
- data/lib/database_consistency/checkers/index_checkers/index_checker.rb +1 -0
- data/lib/database_consistency/checkers/validator_checkers/validator_checker.rb +1 -0
- data/lib/database_consistency/checkers/validators_fraction_checkers/validators_fraction_checker.rb +1 -0
- data/lib/database_consistency/configuration.rb +11 -3
- data/lib/database_consistency/databases/types/base.rb +1 -1
- data/lib/database_consistency/helper.rb +13 -2
- data/lib/database_consistency/version.rb +1 -1
- data/lib/database_consistency/writers/simple_writer.rb +7 -5
- 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: 5774c6b4064a081e7a285013456b39fef68f39ec7dd536063c236d54abec3e84
|
4
|
+
data.tar.gz: 18ed6073af882e007ec6ea70a9a55fad8daa8fef755049a3070d9f68ce1377dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 575b90af564642b397b5a93d2c5a94a3b3b2fb8f6de12e40225361ebb96128df61a8d3e19fb4982986985c6bd1ae110539cc93f00688bab3b44205f7aa5f3716
|
7
|
+
data.tar.gz: 051360a87facb2062451b17c59ff596156b0211dfbf73d6e3345c1b45d470f45177c280d6dd6fb59602faa719a959534252dc4f9615378724d2a321d39c64394
|
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)
|
@@ -23,8 +23,10 @@ module DatabaseConsistency
|
|
23
23
|
|
24
24
|
# Returns list of models to check
|
25
25
|
def models
|
26
|
-
ActiveRecord::Base.descendants.delete_if(&:abstract_class?).
|
27
|
-
|
26
|
+
ActiveRecord::Base.descendants.delete_if(&:abstract_class?).select do |klass|
|
27
|
+
klass.connection.table_exists?(klass.table_name) &&
|
28
|
+
!klass.name.include?('HABTM_') &&
|
29
|
+
project_klass?(klass)
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
@@ -35,6 +37,15 @@ module DatabaseConsistency
|
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
40
|
+
# @param klass [ActiveRecord::Base]
|
41
|
+
#
|
42
|
+
# @return [Boolean]
|
43
|
+
def project_klass?(klass)
|
44
|
+
return true unless Module.respond_to?(:const_source_location) && defined?(Bundler)
|
45
|
+
|
46
|
+
!Module.const_source_location(klass.to_s).first.to_s.include?(Bundler.bundle_path.to_s)
|
47
|
+
end
|
48
|
+
|
38
49
|
# @return [Boolean]
|
39
50
|
def check_inclusion?(array, element)
|
40
51
|
array.include?(element.to_s) || array.include?(element.to_sym)
|
@@ -12,6 +12,12 @@ module DatabaseConsistency
|
|
12
12
|
red: "\e[31m"
|
13
13
|
}.freeze
|
14
14
|
|
15
|
+
COLOR_BY_STATUS = {
|
16
|
+
ok: :green,
|
17
|
+
warning: :yellow,
|
18
|
+
fail: :red
|
19
|
+
}.freeze
|
20
|
+
|
15
21
|
def write
|
16
22
|
results.each do |result|
|
17
23
|
next unless write?(result.status)
|
@@ -31,11 +37,7 @@ module DatabaseConsistency
|
|
31
37
|
end
|
32
38
|
|
33
39
|
def status_text(result)
|
34
|
-
color =
|
35
|
-
when :ok then :green
|
36
|
-
when :warning then :yellow
|
37
|
-
when :fail then :red
|
38
|
-
end
|
40
|
+
color = COLOR_BY_STATUS[result.status]
|
39
41
|
|
40
42
|
colorize(result.status, color)
|
41
43
|
end
|
@@ -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.1
|
4
|
+
version: 1.2.1
|
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-08 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.
|
203
|
+
rubygems_version: 3.3.21
|
203
204
|
signing_key:
|
204
205
|
specification_version: 4
|
205
206
|
summary: Provide an easy way to check the consistency of the database constraints
|