-
-
Save ugisozols/1e10f739c44b838714b6 to your computer and use it in GitHub Desktop.
This file contains 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
namespace :db do | |
require "sequel" | |
Sequel.extension :migration | |
DB = Sequel.connect(ENV['DATABASE_URL']) | |
desc "Prints current schema version" | |
task :version do | |
version = if DB.tables.include?(:schema_info) | |
DB[:schema_info].first[:version] | |
end || 0 | |
puts "Schema Version: #{version}" | |
end | |
desc "Perform migration up to latest migration available" | |
task :migrate do | |
Sequel::Migrator.run(DB, "migrations") | |
Rake::Task['db:version'].execute | |
end | |
desc "Perform rollback to specified target or full rollback as default" | |
task :rollback, :target do |t, args| | |
args.with_defaults(:target => 0) | |
Sequel::Migrator.run(DB, "migrations", :target => args[:target].to_i) | |
Rake::Task['db:version'].execute | |
end | |
desc "Perform migration reset (full rollback and migration)" | |
task :reset do | |
Sequel::Migrator.run(DB, "migrations", :target => 0) | |
Sequel::Migrator.run(DB, "migrations") | |
Rake::Task['db:version'].execute | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment