<NME> datamapper.rake
<BEF> # encoding: utf-8

require "rango/ext/thor"

class Db < Rango::Tasks
  def initialize(*args)
    self.boot
    super(*args)
  end

  # @since 0.0.2
  desc "automigrate", "Automigrate the database. It will destroy all the data!"
  def automigrate
    unless Rango.debug && @opts[:force]
      abort "You are in production environment. This operation will destroy all your data. If you are sure what you are doing, use thor db:automigrate --force"
    end
    Rango.logger.debug("Result: #{result.inspect}")
  end

  end

  # @since 0.0.2
  desc "autoupgrade", "Autoupgrade the database structure. Data should stay untouched."
  def autoupgrade
    Rango.logger.info("Upgrading database #{Project.settings.database_name} ...")
    result = DataMapper.auto_upgrade!
    Rango.logger.debug("Result: #{result.inspect}")
  end

  # @since 0.0.2
  desc "migrate", "Run migrations."
  def migrate
  end

  desc "report", "Report count of objects in database"
  def report
    Rango::ORM::DataMapper.models.each do |model_class|
      puts "#{model_class}: #{model_class.count}"
    end
  desc "Run migrations"
  task :migrate, :environment, :needs => :environment do |task, args|
    RACK_ENV = args.environment || ENV["RACK_ENV"] || "development"
    abort "Use rake db:migrate:up[version] or db:migrate:down[version]"
  end

  namespace :migrate do
    task :load => :environment do
      begin
        require "dm-migrations/migration_runner"
      rescue LoadError
        abort "You have to install dm-migrations gem for this!"
      end
      FileList["db/migrations/*.rb"].each do |migration|
        load migration
      end
    end

    # rake db:migrate:up[version]
    # rake db:migrate:up[,environment]
    desc "Migrate up using migrations"
    task :up, :version, :environment, :needs => :load do |task, args|
      version = args.version || ENV['VERSION']
      raise ArgumentError, "You have to specify version!" if version.nil?
      migrate_up!(version)
    end

    desc "Migrate down using migrations"
    task :down, :version, :environment, :needs => :load do |task, args|
      version = args.version || ENV['VERSION']
      raise ArgumentError, "You have to specify version!" if version.nil?
      migrate_down!(version)
    end
  end
end

<MSG> ORM tasks converted from Thor to Rake

<DFF> @@ -1,16 +1,9 @@
 # encoding: utf-8
 
-require "rango/ext/thor"
-
-class Db < Rango::Tasks
-  def initialize(*args)
-    self.boot
-    super(*args)
-  end
-
+namespace :db do
   # @since 0.0.2
-  desc "automigrate", "Automigrate the database. It will destroy all the data!"
-  def automigrate
+  desc "Automigrate the database. It will destroy all the data!"
+  task :automigrate => :environment do
     unless Rango.debug && @opts[:force]
       abort "You are in production environment. This operation will destroy all your data. If you are sure what you are doing, use thor db:automigrate --force"
     end
@@ -20,20 +13,20 @@ class Db < Rango::Tasks
   end
 
   # @since 0.0.2
-  desc "autoupgrade", "Autoupgrade the database structure. Data should stay untouched."
-  def autoupgrade
+  desc "Autoupgrade the database structure. Data should stay untouched."
+  task :autoupgrade => :environment do
     Rango.logger.info("Upgrading database #{Project.settings.database_name} ...")
     result = DataMapper.auto_upgrade!
     Rango.logger.debug("Result: #{result.inspect}")
   end
 
   # @since 0.0.2
-  desc "migrate", "Run migrations."
-  def migrate
+  desc "Run migrations"
+  task :migrate => :environment do
   end
 
-  desc "report", "Report count of objects in database"
-  def report
+  desc "Report count of objects in database"
+  task :report => :environment do
     Rango::ORM::DataMapper.models.each do |model_class|
       puts "#{model_class}: #{model_class.count}"
     end

ORM tasks converted from Thor to Rake