-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
73 lines (54 loc) · 1.25 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
require "rake/testtask"
Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = FileList['test/**/*_test.rb']
t.warning = false
end
task :default => :test
namespace :db do
task :setup => ['db:create', 'db:migrate']
task :create do
sh "createdb waldorfcamp"
end
task :migrate, [:version] do |task, args|
sequel migrate: (args[:version] || true)
end
task :demigrate do
sequel migrate: 0
end
task :remigrate => [:demigrate, :migrate]
def sequel(migrate: nil)
args = []
if migrate
args += %W[-m db/migrations]
args += %W[-M #{migrate}] if String === migrate
end
args += %W[-e #{ENV["RACK_ENV"] || "development"} config/database.yml]
sh ["sequel", *args].join(" ")
end
end
task :cache_photos => :setup do
DB[:photos].delete
count = 0
Waldorfcamp.cloudinary.photos do |photos|
records = photos.map do |photo|
photo.merge(
source: "cloudinary",
images: Sequel.pg_jsonb(photo[:images])
)
end
DB[:photos].multi_insert(records)
count += records.count
end
puts "#{count} cloudinary photos stored"
end
task :console => :setup do
ARGV.clear
require "pry"
Pry.start
end
task :setup do
require "waldorfcamp"
require "dotenv"
Dotenv.load!
end