Created
October 3, 2012 07:05
-
-
Save bakineggs/3825498 to your computer and use it in GitHub Desktop.
Test to ensure people update db/schema.rb when they add a migration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/lint/database_schema_spec.rb | |
describe 'db/schema.rb' do | |
it 'includes the changes from all migrations' do | |
if checksum_line = File.read('db/schema.rb').split("\n").detect {|line| line.match /^# Checksum: \w+$/} | |
checksum = checksum_line.match(/^# Checksum: (\w+)$/)[1] | |
checksum.should == Digest::MD5.hexdigest(Dir.glob('db/migrate/*').sort.map {|path| File.read path}.join "\n") | |
else | |
fail 'db/schema.rb does not contain a migration directory checksum! Please run rake db:migrate' | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/tasks/migrate.rake | |
namespace :db do | |
task :migrate do | |
checksum = Digest::MD5.hexdigest Dir.glob('db/migrate/*').sort.map {|path| File.read path}.join "\n" | |
`echo '# Checksum: #{checksum}' >> db/schema.rb` | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment