Class: Overcommit::Hook::PreCommit::RailsSchemaUpToDate
- Defined in:
- lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb
Overview
Check to see whether the schema file is in line with the migrations
Instance Method Summary collapse
Methods inherited from Base
#applicable_files, #description, #enabled?, #execute, #in_path?, #initialize, #name, #quiet?, #required?, #run?, #skip?
Constructor Details
This class inherits a constructor from Overcommit::Hook::Base
Instance Method Details
#run ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb', line 4 def run if migration_files.any? && schema_files.none? return :bad, "It looks like you're adding a migration, but did not update the schema file" elsif migration_files.none? && schema_files.any? return :bad, "You're trying to change the schema without adding a migration file" elsif migration_files.any? && schema_files.any? latest_version = migration_files.map { |file| file[/\d+/] }.sort.last schema = schema_files.map { |file| File.read(file) }.join up_to_date = schema.include?(latest_version) unless up_to_date return :bad, "The latest migration version you're committing is " \ "#{latest_version}, but your schema file " \ "#{schema_files.join(' or ')} is on a different version." end end :good end |