Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Rakefile for blog post
# 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, "migrations", :target => 0), "migrations")
puts "<= sq:migrate:reset executed"
desc "Perform migration up/down to VERSION"
task :to do
version = ENV['VERSION'].to_i
raise "No VERSION was provided" if version.nil?, "migrations", :target => version)
puts "<= sq:migrate:to version=[#{version}] executed"
desc "Perform migration up to latest migration available"
task :up do, "migrations")
puts "<= sq:migrate:up executed"
desc "Perform migration down (erase all data)"
task :down do, "migrations", :target => 0)
puts "<= sq:migrate:down executed"
Copy link

DevL commented Dec 12, 2012

The :to task has a slight problem. Since nil.to_i and "".to_i both return 0, not setting the VERSION environment variable (or setting it to empty string) will actually wipe the database. Line 19 will never raise an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment