Created
November 30, 2011 14:00
-
-
Save obfuscurity/1409152 to your computer and use it in GitHub Desktop.
Rakefile for blog post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rakefile | |
namespace :db do | |
require "sequel" | |
namespace :migrate do | |
Sequel.extension :migration | |
DB = Sequel.connect(ENV['DATABASE_URL']) | |
desc "Perform migration reset (full erase and migration up)" | |
task :reset do | |
Sequel::Migrator.run(DB, "migrations", :target => 0) | |
Sequel::Migrator.run(DB, "migrations") | |
puts "<= sq:migrate:reset executed" | |
end | |
desc "Perform migration up/down to VERSION" | |
task :to do | |
version = ENV['VERSION'].to_i | |
raise "No VERSION was provided" if version.nil? | |
Sequel::Migrator.run(DB, "migrations", :target => version) | |
puts "<= sq:migrate:to version=[#{version}] executed" | |
end | |
desc "Perform migration up to latest migration available" | |
task :up do | |
Sequel::Migrator.run(DB, "migrations") | |
puts "<= sq:migrate:up executed" | |
end | |
desc "Perform migration down (erase all data)" | |
task :down do | |
Sequel::Migrator.run(DB, "migrations", :target => 0) | |
puts "<= sq:migrate:down executed" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The :to task has a slight problem. Since
nil.to_i
and"".to_i
both return0
, not setting the VERSION environment variable (or setting it to empty string) will actually wipe the database. Line 19 will never raise an error.