-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
85 lines (71 loc) · 1.81 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Migrate
migrate = lambda do |env, version|
ENV['RACK_ENV'] = env
require_relative 'db'
require 'logger'
Sequel.extension :migration
DB.loggers << Logger.new($stdout) if DB.loggers.empty?
Sequel::Migrator.apply(DB, 'migrate', version)
end
desc 'Migrate test database to latest version'
task :test_up do
migrate.call('test', nil)
end
desc 'Migrate test database all the way down'
task :test_down do
migrate.call('test', 0)
end
desc 'Migrate test database all the way down and then back up'
task :test_bounce do
migrate.call('test', 0)
Sequel::Migrator.apply(DB, 'migrate')
end
desc 'Migrate development database to latest version'
task :dev_up do
migrate.call('development', nil)
end
desc 'Migrate development database to all the way down'
task :dev_down do
migrate.call('development', 0)
end
desc 'Migrate development database all the way down and then back up'
task :dev_bounce do
migrate.call('development', 0)
Sequel::Migrator.apply(DB, 'migrate')
end
desc 'Migrate production database to latest version'
task :prod_up do
migrate.call('production', nil)
end
# Shell
irb = proc do |env|
ENV['RACK_ENV'] = env
trap('INT', 'IGNORE')
dir, base = File.split(FileUtils::RUBY)
cmd = if base.sub!(/\Aruby/, 'irb')
File.join(dir, base)
else
"#{FileUtils::RUBY} -S irb"
end
sh "#{cmd} -r ./models"
end
desc 'Open irb shell in test mode'
task :test_irb do
irb.call('test')
end
desc 'Open irb shell in development mode'
task :dev_irb do
irb.call('development')
end
desc 'Open irb shell in production mode'
task :prod_irb do
irb.call('production')
end
desc 'Annotate Sequel models'
task 'annotate' do
ENV['RACK_ENV'] = 'development'
require_relative 'models'
DB.loggers.clear
require 'sequel/annotate'
Sequel::Annotate.annotate(Dir['models/*.rb'])
end