Skip to content

Instantly share code, notes, and snippets.

@nateware
Created September 23, 2011 23:25
Show Gist options
  • Save nateware/1238707 to your computer and use it in GitHub Desktop.
Save nateware/1238707 to your computer and use it in GitHub Desktop.
Task for Rakefile to hook into mini_record
# 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