database_consistency
Advanced tools
@@ -45,4 +45,9 @@ # frozen_string_literal: true | ||
| # | missing | fail | | ||
| def check | ||
| if model.connection.foreign_keys(model.table_name).find { |fk| fk.column == association.foreign_key.to_s } | ||
| def check # rubocop:disable Metrics/AbcSize | ||
| fk_exist = model.connection.foreign_keys(model.table_name).any? do |fk| | ||
| (Helper.extract_columns(association.foreign_key.to_s) - Array.wrap(fk.column)).empty? && | ||
| fk.to_table == association.klass.table_name | ||
| end | ||
| if fk_exist | ||
| report_template(:ok) | ||
@@ -49,0 +54,0 @@ else |
@@ -115,2 +115,6 @@ # frozen_string_literal: true | ||
| def extract_columns(str) | ||
| str.scan(/(\w+)/).flatten | ||
| end | ||
| def foreign_key_or_attribute(model, attribute) | ||
@@ -117,0 +121,0 @@ model._reflect_on_association(attribute)&.foreign_key || attribute |
| # frozen_string_literal: true | ||
| module DatabaseConsistency | ||
| VERSION = '2.0.5' | ||
| VERSION = '2.0.6' | ||
| end |