Sha256: f269d627ca86437910490a80fd4baf01458214618e6f82c9312ccfad6bcd688a
Contents?: true
Size: 844 Bytes
Versions: 3
Compression:
Stored size: 844 Bytes
Contents
module PreCommit class MigrationCheck def self.call(staged_files) migration_present = migration_file_present?(staged_files) schema_change = schema_file_present?(staged_files) if migration_present && !schema_change "It looks like you're adding a migration, but did not update the schema file" elsif schema_change && !migration_present "You're trying to change the schema without adding a migration file" end end def self.migration_file_present?(staged_files) staged_files.any? { |file| file =~ /db\/migrate\/.*\.rb/ } end def self.schema_file_present?(staged_files) staged_files.any? do |file| basename = File.basename(file) [/schema\.rb/i, /structure.*\.sql/].any? do |regex| basename =~ regex end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
pre-commit-0.9.2 | lib/pre-commit/checks/migration_check.rb |
pre-commit-0.9.1 | lib/pre-commit/checks/migration_check.rb |
pre-commit-0.9.0 | lib/pre-commit/checks/migration_check.rb |