Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add sequel:redo, sequel:rollback, sequel:version tasks

  • Loading branch information...
commit 8ac45e4b329aa3cef8f819435cdce09071844c32 1 parent 64f0c5a
@pusewicz authored
Showing with 22 additions and 1 deletion.
  1. +22 −1 tasks/sequel.rake
View
23 tasks/sequel.rake
@@ -6,12 +6,33 @@
#
desc 'Sequel migration'
namespace :sequel do
+ def path
+ File.join(RAILS_ROOT, 'db', 'migrate')
+ end
+
+ namespace :migrate do
+ desc 'Rollbacks the database one migration and re migrate up. If you want to rollback more than one step, define STEP=x'
+ task :redo => [ 'sequel:rollback', 'sequel:migrate' ]
+ end
+
+ desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x"
task :migrate => :environment do
- path = File.join(RAILS_ROOT, 'db', 'migrate')
if ENV['VERSION']
Sequel::Migrator.apply(Sequel::Model.db, path, ENV['VERSION'].to_i)
else
Sequel::Migrator.apply(Sequel::Model.db, path)
end
end
+
+ desc 'Rolls the schema back to the previous version. Specify the number of steps with STEP=n'
+ task :rollback => :environment do
+ step = ENV['STEP'] ? ENV['STEP'].to_i : 1
+ version = Sequel::Migrator.get_current_migration_version(Sequel::Model.db) - step
+ Sequel::Migrator.apply(Sequel::Model.db, path, version)
+ end
+
+ desc "Retrieves the current schema version number"
+ task :version => :environment do
+ puts "Current version: #{Sequel::Migrator.get_current_migration_version(Sequel::Model.db)}"
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.