database_consistency 1.2.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f18ab981e7a995312fcefac4aad1673991c0ca74f83e892ed443b55399f73621
4
- data.tar.gz: '0284902da44ea88322df42739eb9471212970ff4a2bde3ea91c491a0b3b6a8c6'
3
+ metadata.gz: 5774c6b4064a081e7a285013456b39fef68f39ec7dd536063c236d54abec3e84
4
+ data.tar.gz: 18ed6073af882e007ec6ea70a9a55fad8daa8fef755049a3070d9f68ce1377dd
5
5
  SHA512:
6
- metadata.gz: 3765a63635638981d1a7389ed4d5f4a611d188c08281a13fc2ae5c435e4da8ad09a9a0f49511be596126d75caca322a3a7bd16309d27914adcfcb386a135223a
7
- data.tar.gz: 6473f6990528f09bbb90e6e044b0e1c506b9c9586c65f2b76f8efaed68f1cb91d914703e11ba3747ce0663f9999e33065d7d5b0f5dbce44672a3ca33bd3be94f
6
+ metadata.gz: 575b90af564642b397b5a93d2c5a94a3b3b2fb8f6de12e40225361ebb96128df61a8d3e19fb4982986985c6bd1ae110539cc93f00688bab3b44205f7aa5f3716
7
+ data.tar.gz: 051360a87facb2062451b17c59ff596156b0211dfbf73d6e3345c1b45d470f45177c280d6dd6fb59602faa719a959534252dc4f9615378724d2a321d39c64394
@@ -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('-h', '--help', 'Prints this help') do
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DatabaseConsistency
4
- VERSION = '1.2.0'
4
+ VERSION = '1.2.1'
5
5
  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
@@ -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
- Writers::SimpleWriter.write(
56
- reports,
57
- config: configuration
58
- )
56
+ if opts[:todo]
57
+ Writers::TodoWriter.write(reports, config: configuration)
59
58
 
60
- reports.any? { |report| report.status == :fail } || !RescueError.empty? ? 1 : 0
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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: database_consistency
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeniy Demin
@@ -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