database_consistency 1.7.6 → 1.7.8

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: 905028bf5f85ba32f99076b621821a83f8b1bbd5b7662ebba0eb84bee85ce5f2
4
- data.tar.gz: 763574e25561f0eebb64922bc2b1ab2841c3bb791b570b2a62a5d0ee56758742
3
+ metadata.gz: b117faf2434c91f017d6c1fd66af9b60dd39a320eb483d8c55dafa4870a79458
4
+ data.tar.gz: 4a9adb41296cad3b8c091b0bd62a4c5affa320e26c69fe8c68affc20cc7ea44e
5
5
  SHA512:
6
- metadata.gz: a4ca99f196d02deb4286f3468c46e2a724b585f79fce48b8768c206c72ee9cd07da42f930edbfe457ab64083a118810de19bdf7149f617d0cda8dea490f82e65
7
- data.tar.gz: df2c8f4c0d7b4a2e7adf1b6a142f37bcc4b6864d8ae216e33848a5a1adec0723698f841b342080f0a2cefde1e98bd9fd21dfe85bf4721d93500c68bbcb2ba455
6
+ metadata.gz: bddbe6952f4e66a77108d01e016f452e016bbb43dceafc6e8c666e92426c06e3d7d8f65a0bfa8d4253e3eacb81f9eee71364e5a5fe1c82941d6dd9ab90d70243
7
+ data.tar.gz: 4466ef032c16a72a174ffd030347ed96a914bbc3cf844d930b22afadb938782da8074fe142f6fca36933c2a2e241ddb57041f33ebef19b45e7b1b5f0edeeacf3
@@ -38,18 +38,25 @@ module DatabaseConsistency
38
38
  end
39
39
 
40
40
  def check
41
- return analyse(attribute.to_s, type: :null_constraint_missing) if regular_column
41
+ if regular_column
42
+ analyse(attribute.to_s, type: :null_constraint_missing)
43
+ else
44
+ analyse_association
45
+ end
46
+ end
42
47
 
48
+ def analyse_association
43
49
  reports = [analyse(association.foreign_key.to_s, type: :association_missing_null_constraint)]
44
50
  if association.polymorphic?
45
51
  reports << analyse(association.foreign_type.to_s, type: :association_foreign_type_missing_null_constraint)
46
52
  end
47
-
48
- reports
53
+ reports.compact.presence
49
54
  end
50
55
 
51
56
  def analyse(column_name, type:)
52
57
  field = column(column_name)
58
+ # If the column is missing there is nothing we can do.
59
+ return if field.nil?
53
60
 
54
61
  can_be_null = field.null
55
62
  has_weak_option = weak_option?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DatabaseConsistency
4
- VERSION = '1.7.6'
4
+ VERSION = '1.7.8'
5
5
  end
@@ -12,11 +12,20 @@ module DatabaseConsistency
12
12
  assign_result(hash, result)
13
13
  end
14
14
 
15
- File.write(file_name, h.to_yaml)
15
+ sorted_hash = sort(h)
16
+
17
+ File.write(file_name, sorted_hash.to_yaml)
16
18
  end
17
19
 
18
20
  private
19
21
 
22
+ def sort(obj)
23
+ return obj unless obj.is_a?(Hash)
24
+
25
+ obj.sort_by { |(k, _)| k }
26
+ .to_h { |k, v| [k, sort(v)] }
27
+ end
28
+
20
29
  def write?(status)
21
30
  status == :fail
22
31
  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.7.6
4
+ version: 1.7.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: 2023-04-16 00:00:00.000000000 Z
11
+ date: 2023-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord