database_consistency 1.3.0 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 977b169b47dd5335a327746945ddd512717db1305744f44884d81bb0c7e82645
4
- data.tar.gz: 59eb6c6ddefd09e77ba3f51dfbc2d4474eb92f62ca7b92437a4d9d70778d0d85
3
+ metadata.gz: f0c1477361d612a93d643987fff549de519a50d8452b1019c04f32766598078a
4
+ data.tar.gz: 5132d1568f2573ef5a2bfdeb34321d29f8bc4938f2cc7fa3e75e383dec8a22d6
5
5
  SHA512:
6
- metadata.gz: 8b2b83f4ca288c7173f7abacc04c80f07b4d78c45f0fc949a801d1eb08b173c217ee524462eade7f443d9582243e593faa2730dd33e77e6d985f86c8ba86f6b4
7
- data.tar.gz: e461a6da7caab598150602dac3f02075f4da00b9e68b481419e5717bb33fd3390d5e3f5b90c9ec315c2445af06812e435dafb3db81a7c2ced6cda4b957b035d0
6
+ metadata.gz: f3b9c74967fa7143dca1606de94d9ff18ed48553a1dc916a255f012e22f2509ead5ed943ec1b331fdac9bd11a41a5a0c5549948b9961ace82c374b17dfa9b064
7
+ data.tar.gz: 59cfde80772740f400642739011136f1292dc9c34540835f534f77cac7c2fe4a25d44dc279553b29ee93137dfb718815a08c07b663fd1e8c5fa949fa3003b0da
@@ -78,17 +78,23 @@ module DatabaseConsistency
78
78
  end
79
79
 
80
80
  def uniqueness_validator_columns(attribute, validator, model)
81
- ([wrapped_attribute_name(attribute, validator)] + scope_columns(validator, model)).map(&:to_s)
81
+ ([wrapped_attribute_name(attribute, validator, model)] + scope_columns(validator, model)).map(&:to_s)
82
82
  end
83
83
 
84
84
  def scope_columns(validator, model)
85
85
  Array.wrap(validator.options[:scope]).map do |scope_item|
86
- model._reflect_on_association(scope_item)&.foreign_key || scope_item
86
+ foreign_key_or_attribute(model, scope_item)
87
87
  end
88
88
  end
89
89
 
90
+ def foreign_key_or_attribute(model, attribute)
91
+ model._reflect_on_association(attribute)&.foreign_key || attribute
92
+ end
93
+
90
94
  # @return [String]
91
- def wrapped_attribute_name(attribute, validator)
95
+ def wrapped_attribute_name(attribute, validator, model)
96
+ attribute = foreign_key_or_attribute(model, attribute)
97
+
92
98
  if validator.options[:case_sensitive].nil? || validator.options[:case_sensitive]
93
99
  attribute
94
100
  else
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DatabaseConsistency
4
- VERSION = '1.3.0'
4
+ VERSION = '1.3.2'
5
5
  end
@@ -7,7 +7,7 @@ module DatabaseConsistency
7
7
  private
8
8
 
9
9
  def migration_name
10
- "add_#{report.primary_table}_#{report.foreign_table}_foreign_key"
10
+ "add_#{report.primary_table}_#{report.primary_key}_#{report.foreign_table}_#{report.foreign_key}_fk"
11
11
  end
12
12
 
13
13
  def template_path
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.0
4
+ version: 1.3.2
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-06 00:00:00.000000000 Z
11
+ date: 2022-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -195,10 +195,19 @@ homepage: https://github.com/djezzzl/database_consistency
195
195
  licenses:
196
196
  - MIT
197
197
  metadata: {}
198
- post_install_message: "Thank you for using the gem!\n\nIf the project helps you or
199
- your organization, I would be very grateful if you contribute or donate. \nYour
200
- support is an incredible motivation and the biggest reward for my hard work.\n\nhttps://github.com/djezzzl/database_consistency#contributing\nhttps://opencollective.com/database_consistency#support\n\nThank
201
- you for your attention,\nEvgeniy Demin\n"
198
+ post_install_message: |2+
199
+
200
+ Thank you for using the gem!
201
+
202
+ If the project helps you or your organization, I would be very grateful if you contribute or donate.
203
+ Your support is an incredible motivation and the biggest reward for my hard work.
204
+
205
+ https://github.com/djezzzl/database_consistency#contributing
206
+ https://opencollective.com/database_consistency#support
207
+
208
+ Thank you for your attention,
209
+ Evgeniy Demin
210
+
202
211
  rdoc_options: []
203
212
  require_paths:
204
213
  - lib