namespace :db do desc "abort rake if using bad memory techniques" task :safety_migrate => :environment do path = "#{RAILS_ROOT}/db/migrate/" migration_directory = Dir.new(path) proceed = true migration_directory.each do |file| if file != "." and file != ".." migration = File.open("#{path}#{file}") text = migration.read if text =~ /\.all[\s|\(|\.]/ proceed = false puts "migration #{file} contains a memory problem!" end end end Rake::Task['db:migrate'].invoke if proceed end end