Created
September 23, 2011 23:25
-
-
Save nateware/1238707 to your computer and use it in GitHub Desktop.
Task for Rakefile to hook into mini_record
This file contains hidden or 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
# For Sinatra, put this a the top-level Rakefile directly: | |
namespace :db do | |
desc "Use model properties to auto-migrate" | |
task :automigrate => :environment do | |
Dir[File.expand_path 'app/models/**.rb', File.dirname(__FILE__)].each do |model| | |
require model | |
klass = File.basename(model.sub(/\.rb$/,'')).classify.constantize | |
puts "== Migrating #{klass.name}" | |
klass.auto_upgrade! | |
end | |
end | |
end | |
# For Rails 3, put this in lib/tasks/migrate.rake | |
# Only difference is the use of "Rails.root" | |
namespace :db do | |
desc "Use model properties to auto-migrate" | |
task :automigrate => :environment do | |
Dir[File.expand_path 'app/models/**.rb', Rails.root].each do |model| | |
require model | |
klass = File.basename(model.sub(/\.rb$/,'')).classify.constantize | |
puts "== Migrating #{klass.name}" | |
klass.auto_upgrade! | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment