Skip to content

Commit

Permalink
simple rake tasks to migrate up and down
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesea committed Jul 13, 2012
1 parent 9995d63 commit 3ab46c3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Rakefile
Expand Up @@ -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__))

Expand Down Expand Up @@ -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"
Expand All @@ -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.