Class: RailsLens::Analyzers::DatabaseConstraints
- Defined in:
- lib/rails_lens/analyzers/database_constraints.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
Methods included from ErrorHandling
Constructor Details
This class inherits a constructor from RailsLens::Analyzers::Base
Instance Method Details
#analyze ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rails_lens/analyzers/database_constraints.rb', line 6 def analyze return nil unless connection.respond_to?(:check_constraints) constraints = [] # Get check constraints check_constraints = connection.check_constraints(table_name) return nil if check_constraints.empty? constraints << '[check_constraints]' formatted = check_constraints.map do |constraint| name = constraint.[:name] || constraint.name expression = constraint.expression || constraint.[:validate] "{ name = \"#{name}\", expr = \"#{expression.to_s.gsub('"', '\\"')}\" }" end constraints << "constraints = [#{formatted.join(', ')}]" constraints.empty? ? nil : constraints.join("\n") rescue ActiveRecord::StatementInvalid => e RailsLens.logger.debug { "Failed to fetch check constraints for #{table_name}: #{e.}" } nil rescue NoMethodError => e RailsLens.logger.debug { "Check constraints not supported by adapter: #{e.}" } nil end |