-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
108 lines (89 loc) · 3.01 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
$LOAD_PATH.unshift '.'
require 'resque/tasks'
require 'resque/scheduler/tasks'
task 'resque:setup' => 'gorge:environment'
task 'resque:scheduler' => 'resque:setup'
namespace :gorge do
desc 'Spawns an interactive console'
task :console => :environment do |t|
interactive_ruby = ENV.fetch('INTERACTIVE_RUBY', 'pry')
exec "bundle exec #{ interactive_ruby } -I. -r config/boot"
end
desc 'Setup environment'
task :environment do
require 'config/boot'
end
end
namespace :db do
desc "Run migrations"
task :migrate, [:version] do |t, args|
# Don't load models when executing DB migrations.
# This is required, since some of the tables they refer to might not exist
# yet. It also prevents accidentally using them within migrations - which
# is asking for trouble anyway.
ENV['GORGE_SKIP_MODELS'] = '1'
require 'config/boot'
logger = Gorge.logger(program: 'migrations')
Sequel.extension :migration
db = Sequel::Model.db
if args[:version]
logger.info "Migrating to version #{args[:version]}"
Sequel::Migrator.run(db, "db/migrations", target: args[:version].to_i)
else
logger.info "Migrating to latest"
Sequel::Migrator.run(db, "db/migrations")
end
end
desc 'Drop and recreate database'
task :recreate do |t|
ENV['GORGE_SKIP_MODELS'] = '1'
require 'config/boot'
logger = Gorge.logger(program: 'migrations')
application_db = Gorge::Config::Database::DATABASE
# Reassigning a constant is a bit ugly - but less ugly than duplicating
# `config/database.rb` for the purpose of getting a DB instance to work
# with.
Gorge::Config::Database::DATABASE = 'postgres'
db = Gorge::Config::Database.database
# Terminate existing connnections.
Sequel::Model.db.disconnect
logger.info "Resetting database #{ application_db }"
db.execute("DROP DATABASE #{ application_db }")
db.execute("CREATE DATABASE #{ application_db }")
end
desc 'Reset database and apply all migrations'
task :reset => :recreate do |t|
ENV['GORGE_SKIP_MODELS'] = '1'
require 'config/boot'
logger = Gorge.logger(program: 'migrations')
Sequel.extension :migration
logger.info 'Migrating to latest'
Sequel::Migrator.run(Sequel::Model.db, "db/migrations")
end
end
namespace :spec do
begin
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:all) do |t|
t.fail_on_error = false
t.rspec_opts = '--format doc'
end
RSpec::Core::RakeTask.new(:importer) do |t|
t.fail_on_error = false
t.pattern = 'spec/gorge/importer/**/*_spec.rb'
t.rspec_opts = '--format doc'
end
RSpec::Core::RakeTask.new(:models) do |t|
t.fail_on_error = false
t.pattern = 'spec/gorge/models/**/*_spec.rb'
t.rspec_opts = '--format doc'
end
RSpec::Core::RakeTask.new(:feature) do |t|
t.fail_on_error = false
t.pattern = 'spec/feature/**/*_spec.rb'
t.rspec_opts = '--format doc'
end
rescue LoadError
# no rspec available
end
end