Skip to content

Instantly share code, notes, and snippets.

@WaYdotNET
Created November 30, 2011 13:35
Show Gist options
  • Save WaYdotNET/1409071 to your computer and use it in GitHub Desktop.
Save WaYdotNET/1409071 to your computer and use it in GitHub Desktop.
Migrate All Of Your Model Classes When Using MiniRecord with Padrino
# /rake/minirecord.rake
namespace :mini_record do
desc "Auto migration of database"
task :migrate => :environment do
Dir["models/*.rb"].each do |file_path|
basename = File.basename(file_path, File.extname(file_path))
clazz = basename.camelize.constantize
clazz.auto_upgrade! if clazz.ancestors.include?(ActiveRecord::Base)
end
end
end
@dan-watson
Copy link

Been using this rake task for a project of mine and it started to fall over when I have model classes that are not ActiveRecord classes (such as the cancan ability class - which the generator for cancan places in app/models). So here is the update with a nice fix.

ENV["RAILS_ENV"] ||= 'development'
require File.expand_path("../../../config/environment", __FILE__)

namespace :mini_record do
  desc "Auto migration of database"
  task :migrate do
    Dir["app/models/*.rb"].each do |file_path|
      basename = File.basename(file_path, File.extname(file_path))
      clazz = basename.camelize.constantize
      clazz.auto_upgrade! if clazz.ancestors.include?(ActiveRecord::Base)
    end
  end
end

@WaYdotNET
Copy link
Author

many thx for your fix...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment