-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
70 lines (58 loc) · 1.65 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
# rubocop:disable Metrics/BlockLength
require 'bundler/setup'
require 'byebug' unless ENV['RACK_ENV'] == 'production'
require 'rom/sql/rake_task'
require 'shellwords'
require_relative 'system/elias/container'
begin
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new :spec
task default: [:spec]
rescue LoadError
end
def db
Elias::Container['persistence.db']
end
namespace :db do
task :setup do
Elias::Container.init :rom
end
desc 'Prints current schema version'
task version: :setup do
version =
if db.tables.include?(:schema_migrations)
db[:schema_migrations].order(:filename).last[:filename]
else
'not available'
end
puts "Current schema version: #{version}"
end
desc 'Perform migration up to latest migration available'
task :migrate do
# Enhance the migration task provided by ROM
# Once it finishes, dump the db structure
Rake::Task['db:structure:dump'].execute
# And print the current migration version
Rake::Task['db:version'].execute
end
namespace :structure do
desc 'Dump database structure to db/structure.sql'
task :dump do
if system('which pg_dump', out: File::NULL)
system(
%(pg_dump -s -x -O #{Shellwords.escape(db.url)} > db/structure.sql)
)
end
end
end
desc 'Load seed data into the database'
task :seed do
seed_data = File.join('db', 'seed.rb')
load(seed_data) if File.exist?(seed_data)
end
desc 'Load a small, representative set of data (for development)'
task :sample_data do
sample_data = File.join('db', 'sample_data.rb')
load(sample_data) if File.exist?(sample_data)
end
end