database_consistency 1.1.6 → 1.1.7
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 +37 -12
- data/lib/database_consistency/configuration.rb +24 -9
- data/lib/database_consistency/version.rb +1 -1
- data/lib/database_consistency.rb +2 -2
- 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: 2a742a08f374228e004b155fef15ec5ddaa23404c5aacf42b462eb2cb82ba09a
|
4
|
+
data.tar.gz: 8359e199cdbb89fc9d4b8700728bbef938d2d90a1474e4c2400c2aaa6d31f28f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 962c814731ed2c85427e4b3e765df897c8cd8574f6075e3566e65b72af5effa370a14593019748ff9833a9658a0e55841219acdf3fe9caf212aa9db4bc426df3
|
7
|
+
data.tar.gz: df3aab9a1b6b5d5b2a815ad237b76ff3ffe127cd7921050c09a57e5f53e08087344ad5777224a603c52978382f6568c0c8a19c16038863cb759cac147bb7f9be
|
data/bin/database_consistency
CHANGED
@@ -1,27 +1,52 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
require_relative '../lib/database_consistency/configuration'
|
4
|
+
|
5
|
+
default_config = DatabaseConsistency::Configuration::DEFAULT_PATH
|
6
|
+
|
3
7
|
if ARGV.include?('install')
|
4
|
-
|
5
|
-
|
6
|
-
file_exists = File.exists?(
|
8
|
+
require 'pathname'
|
9
|
+
|
10
|
+
file_exists = File.exists?(default_config)
|
7
11
|
rules = Pathname.new(__FILE__).dirname.join('..', 'lib', 'database_consistency', 'templates', 'rails_defaults.yml').read
|
8
|
-
if file_exists && File.foreach(
|
9
|
-
puts "#{
|
12
|
+
if file_exists && File.foreach(default_config).grep(Regexp.new(rules.lines.first.chomp)).any?
|
13
|
+
puts "#{default_config} is already present"
|
10
14
|
else
|
11
|
-
File.open(
|
15
|
+
File.open(default_config, 'a') do |file|
|
12
16
|
file << "\n" * 2 if file_exists
|
13
17
|
file << rules
|
14
18
|
end
|
15
|
-
puts "#{
|
19
|
+
puts "#{default_config} #{file_exists ? 'updated' : 'added'}"
|
16
20
|
end
|
17
21
|
exit 0
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'optparse'
|
25
|
+
|
26
|
+
config = [default_config]
|
27
|
+
opt_parser = OptionParser.new do |opts|
|
28
|
+
opts.banner = <<-DESC
|
29
|
+
Usage: database_consistency install - run installation
|
30
|
+
database_consistency [options]
|
31
|
+
DESC
|
32
|
+
|
33
|
+
opts.on('-cFILE', '--config=FILE', 'Use additional configuration file') do |f|
|
34
|
+
config << f
|
35
|
+
end
|
36
|
+
|
37
|
+
opts.on('-h', '--help', 'Prints this help') do
|
38
|
+
puts opts
|
39
|
+
exit
|
22
40
|
end
|
23
41
|
end
|
24
42
|
|
43
|
+
opt_parser.parse!
|
44
|
+
|
45
|
+
base_dir = File.join(Dir.pwd, ARGV.first.to_s)
|
46
|
+
unless File.realpath(base_dir).start_with?(Dir.pwd)
|
47
|
+
puts "\nWarning! You are going out of current directory, ruby version may be wrong and some gems may be missing.\n"
|
48
|
+
end
|
49
|
+
|
25
50
|
# Load Rails project
|
26
51
|
begin
|
27
52
|
require File.join(base_dir, 'config', 'boot')
|
@@ -41,5 +66,5 @@ $LOAD_PATH.unshift(File.expand_path('lib', __dir__))
|
|
41
66
|
require 'database_consistency'
|
42
67
|
|
43
68
|
# Process checks
|
44
|
-
code = DatabaseConsistency.run
|
69
|
+
code = DatabaseConsistency.run(config)
|
45
70
|
exit code
|
@@ -5,15 +5,20 @@ require 'yaml'
|
|
5
5
|
module DatabaseConsistency
|
6
6
|
# The class to access configuration options
|
7
7
|
class Configuration
|
8
|
-
|
9
|
-
|
10
|
-
def initialize(
|
11
|
-
@configuration =
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
8
|
+
DEFAULT_PATH = '.database_consistency.yml'
|
9
|
+
|
10
|
+
def initialize(filepaths = DEFAULT_PATH)
|
11
|
+
@configuration = Array(filepaths).each_with_object({}) do |filepath, result|
|
12
|
+
content =
|
13
|
+
if filepath && File.exist?(filepath)
|
14
|
+
data = YAML.load_file(filepath)
|
15
|
+
data.is_a?(Hash) ? data : {}
|
16
|
+
else
|
17
|
+
{}
|
18
|
+
end
|
19
|
+
|
20
|
+
combine_configs!(result, content)
|
21
|
+
end
|
17
22
|
end
|
18
23
|
|
19
24
|
def debug?
|
@@ -48,6 +53,16 @@ module DatabaseConsistency
|
|
48
53
|
|
49
54
|
attr_reader :configuration
|
50
55
|
|
56
|
+
def combine_configs!(config, new_config)
|
57
|
+
config.merge!(new_config) do |_key, val, new_val|
|
58
|
+
if val.is_a?(Hash) && new_val.is_a?(Hash)
|
59
|
+
combine_configs!(val, new_val)
|
60
|
+
else
|
61
|
+
new_val
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
51
66
|
def settings
|
52
67
|
@settings ||= configuration['DatabaseConsistencySettings']
|
53
68
|
end
|
data/lib/database_consistency.rb
CHANGED
@@ -48,8 +48,8 @@ require 'database_consistency/processors/indexes_processor'
|
|
48
48
|
# The root module
|
49
49
|
module DatabaseConsistency
|
50
50
|
class << self
|
51
|
-
def run
|
52
|
-
configuration = Configuration.new
|
51
|
+
def run(*args)
|
52
|
+
configuration = Configuration.new(*args)
|
53
53
|
reports = Processors.reports(configuration)
|
54
54
|
|
55
55
|
Writers::SimpleWriter.write(
|
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.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evgeniy Demin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|