database_consistency 0.6.7 → 0.6.8
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 +0 -4
- data/lib/database_consistency.rb +1 -1
- data/lib/database_consistency/checkers/missing_index_checker.rb +11 -1
- data/lib/database_consistency/configuration.rb +25 -0
- data/lib/database_consistency/version.rb +1 -1
- data/lib/database_consistency/writers/base_writer.rb +6 -10
- data/lib/database_consistency/writers/simple_writer.rb +34 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73fc6eabb9e2451dad6a2f238102f9eea3ee79ae7561c05649599e12301cacf3
|
4
|
+
data.tar.gz: f6251f161e8c5b2ce232c6632eb1176b9333d74b23c91a421ef21c9622ff85de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5417be3a2afe6072884395e6fd54e3c9b4134f953d052d8c83b6cad8652c78f7db39c42a5b698cd6e1f6b7fab3cf8f0ae6316748e9eb1a816d684d57b6fbf17
|
7
|
+
data.tar.gz: c7844e3f18f15768b85e75c121328301b7f0d78e145c52485f1d27c577d35f531fffdbb078e6c33e2f35dca736849be18a11c4a52708a6092c954731ebdea033
|
data/bin/database_consistency
CHANGED
@@ -22,10 +22,6 @@ Rails.application.eager_load! if defined?(Rails)
|
|
22
22
|
$LOAD_PATH.unshift(File.expand_path('lib', __dir__))
|
23
23
|
require 'database_consistency'
|
24
24
|
|
25
|
-
# Welcome message
|
26
|
-
puts 'Thank you for using the gem. Any contribution is welcome https://github.com/djezzzl/database_consistency!'
|
27
|
-
puts "(c) Evgeniy Demin <lawliet.djez@gmail.com>\n\n"
|
28
|
-
|
29
25
|
# Process checks
|
30
26
|
result = DatabaseConsistency.run
|
31
27
|
exit result
|
data/lib/database_consistency.rb
CHANGED
@@ -34,9 +34,19 @@ module DatabaseConsistency
|
|
34
34
|
|
35
35
|
def index
|
36
36
|
@index ||= association.klass.connection.indexes(association.klass.table_name).find do |index|
|
37
|
-
index
|
37
|
+
index_keys(index) == association_keys
|
38
38
|
end
|
39
39
|
end
|
40
|
+
|
41
|
+
def association_keys
|
42
|
+
@association_keys ||= [association.foreign_key, association.type].compact.map(&:to_s).sort
|
43
|
+
end
|
44
|
+
|
45
|
+
def index_keys(index)
|
46
|
+
return unless index.columns.is_a?(Array)
|
47
|
+
|
48
|
+
index.columns[0...association_keys.size].sort
|
49
|
+
end
|
40
50
|
end
|
41
51
|
end
|
42
52
|
end
|
@@ -16,6 +16,18 @@ module DatabaseConsistency
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
def debug?
|
20
|
+
log_level.to_s.match?(/DEBUG/i)
|
21
|
+
end
|
22
|
+
|
23
|
+
def colored?
|
24
|
+
if ENV.key?('COLOR')
|
25
|
+
ENV['COLOR'].match?(/1|true|yes/)
|
26
|
+
else
|
27
|
+
settings && settings['color']
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
19
31
|
# @return [Boolean]
|
20
32
|
def enabled?(*path)
|
21
33
|
current = configuration
|
@@ -35,5 +47,18 @@ module DatabaseConsistency
|
|
35
47
|
private
|
36
48
|
|
37
49
|
attr_reader :configuration
|
50
|
+
|
51
|
+
def settings
|
52
|
+
@settings ||= configuration['DatabaseConsistencySettings']
|
53
|
+
end
|
54
|
+
|
55
|
+
def log_level
|
56
|
+
@log_level ||=
|
57
|
+
if ENV.key?('LOG_LEVEL')
|
58
|
+
ENV['LOG_LEVEL']
|
59
|
+
else
|
60
|
+
settings && settings['log_level']
|
61
|
+
end
|
62
|
+
end
|
38
63
|
end
|
39
64
|
end
|
@@ -4,23 +4,19 @@ module DatabaseConsistency
|
|
4
4
|
module Writers
|
5
5
|
# The base class for writers
|
6
6
|
class BaseWriter
|
7
|
-
attr_reader :results, :
|
7
|
+
attr_reader :results, :config
|
8
8
|
|
9
|
-
def initialize(results,
|
9
|
+
def initialize(results, config: Configuration.new)
|
10
10
|
@results = results
|
11
|
-
@
|
11
|
+
@config = config
|
12
12
|
end
|
13
13
|
|
14
14
|
def write?(status)
|
15
|
-
status == :fail || debug?
|
15
|
+
status == :fail || config.debug?
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.write(results, log_level)
|
23
|
-
new(results, log_level).write
|
18
|
+
def self.write(results, config: Configuration.new)
|
19
|
+
new(results, config: config).write
|
24
20
|
end
|
25
21
|
end
|
26
22
|
end
|
@@ -5,22 +5,46 @@ module DatabaseConsistency
|
|
5
5
|
module Writers
|
6
6
|
# The simplest formatter
|
7
7
|
class SimpleWriter < BaseWriter
|
8
|
+
COLORS = {
|
9
|
+
blue: "\e[34m",
|
10
|
+
yellow: "\e[33m",
|
11
|
+
green: "\e[32m",
|
12
|
+
red: "\e[31m"
|
13
|
+
}.freeze
|
14
|
+
|
8
15
|
def write
|
9
|
-
|
16
|
+
results.each do |result|
|
17
|
+
next unless write?(result.status)
|
18
|
+
|
19
|
+
puts msg(result)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def msg(result)
|
24
|
+
msg = "#{status_text(result)} #{key_text(result)} #{result.message}"
|
25
|
+
msg += " (checker: #{result.checker_name})" if config.debug?
|
26
|
+
msg
|
10
27
|
end
|
11
28
|
|
12
|
-
|
13
|
-
results.map do |result|
|
14
|
-
next unless write?(result[:status])
|
29
|
+
private
|
15
30
|
|
16
|
-
|
17
|
-
|
31
|
+
def key_text(result)
|
32
|
+
"#{colorize(result.table_or_model_name, :blue)} #{colorize(result.column_or_attribute_name, :yellow)}"
|
18
33
|
end
|
19
34
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
|
35
|
+
def status_text(result)
|
36
|
+
color = case result.status
|
37
|
+
when :ok then :green
|
38
|
+
when :fail then :red
|
39
|
+
end
|
40
|
+
|
41
|
+
colorize(result.status, color)
|
42
|
+
end
|
43
|
+
|
44
|
+
def colorize(text, color)
|
45
|
+
return text unless config.colored? && color
|
46
|
+
|
47
|
+
"#{COLORS[color]}#{text}\e[0m"
|
24
48
|
end
|
25
49
|
end
|
26
50
|
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: 0.6.
|
4
|
+
version: 0.6.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evgeniy Demin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|