database_consistency 1.3.5 → 1.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/database_consistency/version.rb +1 -1
- data/lib/database_consistency/writers/autofix_writer.rb +2 -2
- data/lib/database_consistency/writers/simple/association_missing_index.rb +22 -0
- data/lib/database_consistency/writers/simple/association_missing_null_constraint.rb +22 -0
- data/lib/database_consistency/writers/simple/base.rb +8 -0
- data/lib/database_consistency/writers/simple/error_message.rb +7 -0
- data/lib/database_consistency/writers/simple/has_one_missing_unique_index.rb +23 -0
- data/lib/database_consistency/writers/simple/inconsistent_types.rb +8 -0
- data/lib/database_consistency/writers/simple/length_validator_greater_limit.rb +22 -0
- data/lib/database_consistency/writers/simple/length_validator_lower_limit.rb +22 -0
- data/lib/database_consistency/writers/simple/length_validator_missing.rb +22 -0
- data/lib/database_consistency/writers/simple/missing_foreign_key.rb +24 -0
- data/lib/database_consistency/writers/simple/missing_unique_index.rb +23 -0
- data/lib/database_consistency/writers/simple/missing_uniqueness_validation.rb +22 -0
- data/lib/database_consistency/writers/simple/null_constraint_association_misses_validator.rb +7 -0
- data/lib/database_consistency/writers/simple/null_constraint_misses_validator.rb +22 -0
- data/lib/database_consistency/writers/simple/null_constraint_missing.rb +22 -0
- data/lib/database_consistency/writers/simple/possible_null.rb +22 -0
- data/lib/database_consistency/writers/simple/redundant_index.rb +6 -0
- data/lib/database_consistency/writers/simple/redundant_unique_index.rb +6 -0
- data/lib/database_consistency/writers/simple/small_primary_key.rb +22 -0
- data/lib/database_consistency/writers/simple_writer.rb +19 -20
- data/lib/database_consistency.rb +13 -0
- metadata +15 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad00c3759184fa0098812d4cb79169f109205bff2861c37965d56c42c4da568f
|
4
|
+
data.tar.gz: 579087c2a52d57bac85af5fc7f9e86fa31b6c78bbaab1583128e319f9156dafb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 206324a83d7f850bde79bb8a4399362ba7ff4f94cf848139d55781cf7e6f54d8b03d5e4641928193689c0c818c803badbcbb4f72685031f72dab26eea1f4a80a
|
7
|
+
data.tar.gz: 2cbaed407b168b1100de5cb6962d2fedac6ce2e8f955a5ed4811ef9d80227a2f3f396de98c9ed0a9de8c5ca751c092f389b482852663a510860cbaad85866643
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseConsistency
|
4
|
+
module Writers
|
5
|
+
module Simple
|
6
|
+
class AssociationMissingIndex < Base # :nodoc:
|
7
|
+
private
|
8
|
+
|
9
|
+
def template
|
10
|
+
'associated model should have proper index in the database'
|
11
|
+
end
|
12
|
+
|
13
|
+
def unique_attributes
|
14
|
+
{
|
15
|
+
table_name: report.table_name,
|
16
|
+
columns: report.columns
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseConsistency
|
4
|
+
module Writers
|
5
|
+
module Simple
|
6
|
+
class AssociationMissingNullConstraint < Base # :nodoc:
|
7
|
+
private
|
8
|
+
|
9
|
+
def template
|
10
|
+
'association foreign key column should be required in the database'
|
11
|
+
end
|
12
|
+
|
13
|
+
def unique_attributes
|
14
|
+
{
|
15
|
+
table_name: report.table_name,
|
16
|
+
column_name: report.column_name
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -36,8 +36,16 @@ module DatabaseConsistency
|
|
36
36
|
"#{report.checker_name} #{status_text} #{key_text} #{message_text}"
|
37
37
|
end
|
38
38
|
|
39
|
+
def unique_key
|
40
|
+
{ class: self.class }.merge(unique_attributes)
|
41
|
+
end
|
42
|
+
|
39
43
|
private
|
40
44
|
|
45
|
+
def unique_attributes
|
46
|
+
raise StandardError, 'Missing the implementation'
|
47
|
+
end
|
48
|
+
|
41
49
|
def message_text
|
42
50
|
template % attributes
|
43
51
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseConsistency
|
4
|
+
module Writers
|
5
|
+
module Simple
|
6
|
+
class HasOneMissingUniqueIndex < Base # :nodoc:
|
7
|
+
private
|
8
|
+
|
9
|
+
def template
|
10
|
+
'associated model should have proper unique index in the database'
|
11
|
+
end
|
12
|
+
|
13
|
+
def unique_attributes
|
14
|
+
{
|
15
|
+
table_name: report.table_name,
|
16
|
+
columns: report.columns,
|
17
|
+
unique: true
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseConsistency
|
4
|
+
module Writers
|
5
|
+
module Simple
|
6
|
+
class LengthValidatorGreaterLimit < Base # :nodoc:
|
7
|
+
private
|
8
|
+
|
9
|
+
def template
|
10
|
+
'column has greater limit in the database than in length validator'
|
11
|
+
end
|
12
|
+
|
13
|
+
def unique_attributes
|
14
|
+
{
|
15
|
+
table_or_model_name: report.table_or_model_name,
|
16
|
+
column_or_attribute_name: report.column_or_attribute_name
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseConsistency
|
4
|
+
module Writers
|
5
|
+
module Simple
|
6
|
+
class LengthValidatorLowerLimit < Base # :nodoc:
|
7
|
+
private
|
8
|
+
|
9
|
+
def template
|
10
|
+
'column has lower limit in the database than in length validator'
|
11
|
+
end
|
12
|
+
|
13
|
+
def unique_attributes
|
14
|
+
{
|
15
|
+
table_or_model_name: report.table_or_model_name,
|
16
|
+
column_or_attribute_name: report.column_or_attribute_name
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseConsistency
|
4
|
+
module Writers
|
5
|
+
module Simple
|
6
|
+
class LengthValidatorMissing < Base # :nodoc:
|
7
|
+
private
|
8
|
+
|
9
|
+
def template
|
10
|
+
'column has limit in the database but do not have length validator'
|
11
|
+
end
|
12
|
+
|
13
|
+
def unique_attributes
|
14
|
+
{
|
15
|
+
table_or_model_name: report.table_or_model_name,
|
16
|
+
column_or_attribute_name: report.column_or_attribute_name
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseConsistency
|
4
|
+
module Writers
|
5
|
+
module Simple
|
6
|
+
class MissingForeignKey < Base # :nodoc:
|
7
|
+
private
|
8
|
+
|
9
|
+
def template
|
10
|
+
'should have foreign key in the database'
|
11
|
+
end
|
12
|
+
|
13
|
+
def unique_attributes
|
14
|
+
{
|
15
|
+
foreign_table: report.foreign_table,
|
16
|
+
foreign_key: report.foreign_key,
|
17
|
+
primary_table: report.primary_table,
|
18
|
+
primary_key: report.primary_key
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseConsistency
|
4
|
+
module Writers
|
5
|
+
module Simple
|
6
|
+
class MissingUniqueIndex < Base # :nodoc:
|
7
|
+
private
|
8
|
+
|
9
|
+
def template
|
10
|
+
'model should have proper unique index in the database'
|
11
|
+
end
|
12
|
+
|
13
|
+
def unique_attributes
|
14
|
+
{
|
15
|
+
table_name: report.table_name,
|
16
|
+
columns: report.columns,
|
17
|
+
unique: true
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseConsistency
|
4
|
+
module Writers
|
5
|
+
module Simple
|
6
|
+
class MissingUniquenessValidation < Base # :nodoc:
|
7
|
+
private
|
8
|
+
|
9
|
+
def template
|
10
|
+
'index is unique in the database but do not have uniqueness validator'
|
11
|
+
end
|
12
|
+
|
13
|
+
def unique_attributes
|
14
|
+
{
|
15
|
+
table_or_model_name: report.table_or_model_name,
|
16
|
+
column_or_attribute_name: report.column_or_attribute_name
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/database_consistency/writers/simple/null_constraint_association_misses_validator.rb
CHANGED
@@ -15,6 +15,13 @@ module DatabaseConsistency
|
|
15
15
|
association_name: report.association_name
|
16
16
|
}
|
17
17
|
end
|
18
|
+
|
19
|
+
def unique_attributes
|
20
|
+
{
|
21
|
+
table_or_model_name: report.table_or_model_name,
|
22
|
+
column_or_attribute_name: report.column_or_attribute_name
|
23
|
+
}
|
24
|
+
end
|
18
25
|
end
|
19
26
|
end
|
20
27
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseConsistency
|
4
|
+
module Writers
|
5
|
+
module Simple
|
6
|
+
class NullConstraintMissesValidator < Base # :nodoc:
|
7
|
+
private
|
8
|
+
|
9
|
+
def template
|
10
|
+
'column is required in the database but do not have presence validator'
|
11
|
+
end
|
12
|
+
|
13
|
+
def unique_attributes
|
14
|
+
{
|
15
|
+
table_or_model_name: report.table_or_model_name,
|
16
|
+
column_or_attribute_name: report.column_or_attribute_name
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseConsistency
|
4
|
+
module Writers
|
5
|
+
module Simple
|
6
|
+
class NullConstraintMissing < Base # :nodoc:
|
7
|
+
private
|
8
|
+
|
9
|
+
def template
|
10
|
+
'column should be required in the database'
|
11
|
+
end
|
12
|
+
|
13
|
+
def unique_attributes
|
14
|
+
{
|
15
|
+
table_name: report.table_name,
|
16
|
+
column_name: report.column_name
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseConsistency
|
4
|
+
module Writers
|
5
|
+
module Simple
|
6
|
+
class PossibleNull < Base # :nodoc:
|
7
|
+
private
|
8
|
+
|
9
|
+
def template
|
10
|
+
'column is required but there is possible null value insert'
|
11
|
+
end
|
12
|
+
|
13
|
+
def unique_attributes
|
14
|
+
{
|
15
|
+
table_or_model_name: report.table_or_model_name,
|
16
|
+
column_or_attribute_name: report.column_or_attribute_name
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseConsistency
|
4
|
+
module Writers
|
5
|
+
module Simple
|
6
|
+
class SmallPrimaryKey < Base # :nodoc:
|
7
|
+
private
|
8
|
+
|
9
|
+
def template
|
10
|
+
'column has int/serial type but recommended to have bigint/bigserial/uuid'
|
11
|
+
end
|
12
|
+
|
13
|
+
def unique_attributes
|
14
|
+
{
|
15
|
+
table_or_model_name: report.table_or_model_name,
|
16
|
+
column_or_attribute_name: report.column_or_attribute_name
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -6,39 +6,38 @@ module DatabaseConsistency
|
|
6
6
|
# The simplest formatter
|
7
7
|
class SimpleWriter < BaseWriter
|
8
8
|
SLUG_TO_WRITER = {
|
9
|
-
association_missing_index: Simple::
|
10
|
-
association_missing_null_constraint: Simple::
|
11
|
-
has_one_missing_unique_index: Simple::
|
9
|
+
association_missing_index: Simple::AssociationMissingIndex,
|
10
|
+
association_missing_null_constraint: Simple::AssociationMissingNullConstraint,
|
11
|
+
has_one_missing_unique_index: Simple::HasOneMissingUniqueIndex,
|
12
12
|
inconsistent_types: Simple::InconsistentTypes,
|
13
|
-
length_validator_greater_limit: Simple::
|
14
|
-
length_validator_lower_limit: Simple::
|
15
|
-
length_validator_missing: Simple::
|
16
|
-
missing_foreign_key: Simple::
|
17
|
-
missing_unique_index: Simple::
|
18
|
-
missing_uniqueness_validation: Simple::
|
13
|
+
length_validator_greater_limit: Simple::LengthValidatorGreaterLimit,
|
14
|
+
length_validator_lower_limit: Simple::LengthValidatorLowerLimit,
|
15
|
+
length_validator_missing: Simple::LengthValidatorMissing,
|
16
|
+
missing_foreign_key: Simple::MissingForeignKey,
|
17
|
+
missing_unique_index: Simple::MissingUniqueIndex,
|
18
|
+
missing_uniqueness_validation: Simple::MissingUniquenessValidation,
|
19
19
|
null_constraint_association_misses_validator: Simple::NullConstraintAssociationMissesValidator,
|
20
|
-
null_constraint_misses_validator: Simple::
|
21
|
-
null_constraint_missing: Simple::
|
22
|
-
possible_null: Simple::
|
20
|
+
null_constraint_misses_validator: Simple::NullConstraintMissesValidator,
|
21
|
+
null_constraint_missing: Simple::NullConstraintMissing,
|
22
|
+
possible_null: Simple::PossibleNull,
|
23
23
|
redundant_index: Simple::RedundantIndex,
|
24
24
|
redundant_unique_index: Simple::RedundantUniqueIndex,
|
25
|
-
small_primary_key: Simple::
|
25
|
+
small_primary_key: Simple::SmallPrimaryKey
|
26
26
|
}.freeze
|
27
27
|
|
28
28
|
def write
|
29
|
-
results.
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
results.select(&method(:write?))
|
30
|
+
.map(&method(:writer))
|
31
|
+
.uniq(&:unique_key)
|
32
|
+
.each do |writer|
|
34
33
|
puts writer.msg
|
35
34
|
end
|
36
35
|
end
|
37
36
|
|
38
37
|
private
|
39
38
|
|
40
|
-
def write?(
|
41
|
-
status == :fail || config.debug?
|
39
|
+
def write?(report)
|
40
|
+
report.status == :fail || config.debug?
|
42
41
|
end
|
43
42
|
|
44
43
|
def writer(report)
|
data/lib/database_consistency.rb
CHANGED
@@ -18,6 +18,19 @@ require 'database_consistency/writers/simple/inconsistent_types'
|
|
18
18
|
require 'database_consistency/writers/simple/null_constraint_association_misses_validator'
|
19
19
|
require 'database_consistency/writers/simple/redundant_index'
|
20
20
|
require 'database_consistency/writers/simple/redundant_unique_index'
|
21
|
+
require 'database_consistency/writers/simple/association_missing_index'
|
22
|
+
require 'database_consistency/writers/simple/association_missing_null_constraint'
|
23
|
+
require 'database_consistency/writers/simple/has_one_missing_unique_index'
|
24
|
+
require 'database_consistency/writers/simple/length_validator_lower_limit'
|
25
|
+
require 'database_consistency/writers/simple/length_validator_greater_limit'
|
26
|
+
require 'database_consistency/writers/simple/length_validator_missing'
|
27
|
+
require 'database_consistency/writers/simple/missing_foreign_key'
|
28
|
+
require 'database_consistency/writers/simple/missing_unique_index'
|
29
|
+
require 'database_consistency/writers/simple/missing_uniqueness_validation'
|
30
|
+
require 'database_consistency/writers/simple/null_constraint_misses_validator'
|
31
|
+
require 'database_consistency/writers/simple/null_constraint_missing'
|
32
|
+
require 'database_consistency/writers/simple/possible_null'
|
33
|
+
require 'database_consistency/writers/simple/small_primary_key'
|
21
34
|
require 'database_consistency/writers/simple_writer'
|
22
35
|
|
23
36
|
require 'database_consistency/writers/autofix/helpers/migration'
|
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.3.
|
4
|
+
version: 1.3.6
|
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-
|
11
|
+
date: 2022-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -196,12 +196,25 @@ files:
|
|
196
196
|
- lib/database_consistency/writers/autofix/templates/redundant_index.tt
|
197
197
|
- lib/database_consistency/writers/autofix_writer.rb
|
198
198
|
- lib/database_consistency/writers/base_writer.rb
|
199
|
+
- lib/database_consistency/writers/simple/association_missing_index.rb
|
200
|
+
- lib/database_consistency/writers/simple/association_missing_null_constraint.rb
|
199
201
|
- lib/database_consistency/writers/simple/base.rb
|
200
202
|
- lib/database_consistency/writers/simple/error_message.rb
|
203
|
+
- lib/database_consistency/writers/simple/has_one_missing_unique_index.rb
|
201
204
|
- lib/database_consistency/writers/simple/inconsistent_types.rb
|
205
|
+
- lib/database_consistency/writers/simple/length_validator_greater_limit.rb
|
206
|
+
- lib/database_consistency/writers/simple/length_validator_lower_limit.rb
|
207
|
+
- lib/database_consistency/writers/simple/length_validator_missing.rb
|
208
|
+
- lib/database_consistency/writers/simple/missing_foreign_key.rb
|
209
|
+
- lib/database_consistency/writers/simple/missing_unique_index.rb
|
210
|
+
- lib/database_consistency/writers/simple/missing_uniqueness_validation.rb
|
202
211
|
- lib/database_consistency/writers/simple/null_constraint_association_misses_validator.rb
|
212
|
+
- lib/database_consistency/writers/simple/null_constraint_misses_validator.rb
|
213
|
+
- lib/database_consistency/writers/simple/null_constraint_missing.rb
|
214
|
+
- lib/database_consistency/writers/simple/possible_null.rb
|
203
215
|
- lib/database_consistency/writers/simple/redundant_index.rb
|
204
216
|
- lib/database_consistency/writers/simple/redundant_unique_index.rb
|
217
|
+
- lib/database_consistency/writers/simple/small_primary_key.rb
|
205
218
|
- lib/database_consistency/writers/simple_writer.rb
|
206
219
|
- lib/database_consistency/writers/todo_writer.rb
|
207
220
|
homepage: https://github.com/djezzzl/database_consistency
|