class Nandi::Validator
Attributes
migration[R]
Public Class Methods
call(migration)
click to toggle source
# File lib/nandi/validator.rb, line 27 def self.call(migration) new(migration).call end
new(migration)
click to toggle source
# File lib/nandi/validator.rb, line 31 def initialize(migration) @migration = migration end
Public Instance Methods
call()
click to toggle source
# File lib/nandi/validator.rb, line 35 def call migration_invariants_respected << each_instruction_validation end
Private Instance Methods
at_most_one_object_modified()
click to toggle source
# File lib/nandi/validator.rb, line 57 def at_most_one_object_modified [migration.up_instructions, migration.down_instructions].all? do |instructions| affected_tables = instructions.map do |instruction| instruction.respond_to?(:table) && instruction.table.to_sym end affected_tables.uniq.count <= 1 end end
each_instruction_validation()
click to toggle source
# File lib/nandi/validator.rb, line 86 def each_instruction_validation instructions.inject(success) do |result, instruction| collect_errors(Validation::EachValidator.call(instruction), result) end end
instructions()
click to toggle source
# File lib/nandi/validator.rb, line 96 def instructions [*migration.up_instructions, *migration.down_instructions] end
lock_timeout_is_within_acceptable_bounds()
click to toggle source
# File lib/nandi/validator.rb, line 80 def lock_timeout_is_within_acceptable_bounds migration.strictest_lock != Nandi::Migration::LockWeights::ACCESS_EXCLUSIVE || migration.lock_timeout <= Nandi.config.access_exclusive_lock_timeout_limit end
migration_invariants_respected()
click to toggle source
# File lib/nandi/validator.rb, line 41 def migration_invariants_respected Validation::Result.new.tap do |result| result << assert( at_most_one_object_modified, "modifying more than one table per migration", ) result << assert( new_indexes_are_separated_from_other_migrations, "creating more than one index per migration", ) result << validate_timeouts end end
new_indexes_are_separated_from_other_migrations()
click to toggle source
# File lib/nandi/validator.rb, line 67 def new_indexes_are_separated_from_other_migrations [migration.up_instructions, migration.down_instructions].map do |instructions| instructions.none? { |i| i.procedure == :add_index } || instructions.count == 1 end.all? end
statement_timeout_is_within_acceptable_bounds()
click to toggle source
# File lib/nandi/validator.rb, line 74 def statement_timeout_is_within_acceptable_bounds migration.strictest_lock != Nandi::Migration::LockWeights::ACCESS_EXCLUSIVE || migration.statement_timeout <= Nandi.config.access_exclusive_statement_timeout_limit end
validate_timeouts()
click to toggle source
# File lib/nandi/validator.rb, line 92 def validate_timeouts Nandi::Validation::TimeoutValidator.call(migration) end