-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRakefile
48 lines (40 loc) · 1.35 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require 'bundler/setup'
require 'padrino-core/cli/rake'
require 'thor'
require File.dirname(__FILE__) + '/config/boot.rb'
PadrinoTasks.use(:database)
PadrinoTasks.use(:sequel)
PadrinoTasks.init
namespace :db do
require "sequel"
Sequel.extension :migration
case Padrino.env
when :development then ENV['DATABASE_URL'] = 'postgres://confy:confy@localhost/confy'
when :test then ENV['DATABASE_URL'] = 'postgres://confy:confy@localhost/confy_test'
end
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, "db/migrate")
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, "db/migrate", :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, "db/migrate", :target => 0)
Sequel::Migrator.run(DB, "db/migrate")
Rake::Task['db:version'].execute
end
end