Class: Idxfence::Checker
- Inherits:
-
Object
- Object
- Idxfence::Checker
- Defined in:
- lib/idxfence/checker.rb
Overview
Joins the two passes: every uniqueness validation ModelParser found
in app/models/*.rb, resolved to a table name (via
Inflector.table_name_for, unless the model set self.table_name
explicitly), against every unique index SchemaParser found in
db/schema.rb for that same table. A validation with no matching
unique index -- one covering exactly its column set (the validated
column plus any scope: column(s), unordered) -- is a real gap: the
AR validation can be raced, and only a DB-level unique index closes
it. See DETAILS.md for the full algorithm and its documented
limitations (case-insensitive uniqueness, irregular pluralization,
etc).
Instance Method Summary collapse
-
#call ⇒ Array<Finding>, String
Findings, and a warning string (nil if none) when db/schema.rb was missing/unparseable -- in that case findings is always [] since nothing can be cross-referenced without it.
-
#initialize(model_paths:, schema_path:) ⇒ Checker
constructor
A new instance of Checker.
Constructor Details
#initialize(model_paths:, schema_path:) ⇒ Checker
19 20 21 22 |
# File 'lib/idxfence/checker.rb', line 19 def initialize(model_paths:, schema_path:) @model_paths = model_paths @schema_path = schema_path end |
Instance Method Details
#call ⇒ Array<Finding>, String
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/idxfence/checker.rb', line 28 def call begin schema_tables = SchemaParser.parse(schema_path) rescue SchemaParser::MissingSchemaError => e return [[], "idxfence: warning: #{e.} -- skipping uniqueness cross-check for #{model_paths.size} model file(s)"] end findings = model_paths.flat_map do |model_path| ModelParser.new(path: model_path).call.flat_map do |parsed_model| check_model(parsed_model, schema_tables) end end [findings, nil] end |