Permalink
Browse files

simple rake tasks to migrate up and down

  • Loading branch information...
1 parent 9995d63 commit 3ab46c3160dbecaddb3f50b874cb891c67146b49 @mikesea mikesea committed Jul 13, 2012
Showing with 8 additions and 2 deletions.
  1. +8 −2 Rakefile
View
@@ -4,6 +4,7 @@ require 'rubygems'
require 'bundler'
Bundler.setup
require 'wd_sinatra/app_loader'
+require 'active_record'
root = File.expand_path(File.dirname(__FILE__))
@@ -33,8 +34,7 @@ end
namespace :db do
task :environment do
- require 'active_record'
- ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: 'db/development.sqlite3'
+ ActiveRecord::Base.establish_connection adapter: "sqlite3", database: "db/#{ENV['RACK_ENV']}.sqlite3"
end
desc "migrate"
@@ -43,4 +43,10 @@ namespace :db do
ActiveRecord::Migration.verbose = true
ActiveRecord::Migrator.migrate("db/migrate")
end
+
+ desc "rolls back the migration (use steps with STEP=n)"
+ task(rollback: :environment) do
+ step = ENV["STEP"] ? ENV["STEP"].to_i : 1
+ ActiveRecord::Migrator.rollback('db/migrate', step)
+ end
end

0 comments on commit 3ab46c3

Please sign in to comment.