This repository was archived by the owner on Mar 8, 2020. It is now read-only.
forked from codeforamerica/workforwardnola
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRakefile
More file actions
60 lines (50 loc) · 1.51 KB
/
Rakefile
File metadata and controls
60 lines (50 loc) · 1.51 KB
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
task :app do
require './app'
end
# rubocop:disable Metrics/BlockLength
namespace :db do
require 'sequel'
Sequel.extension :migration
desc 'Run DB migrations'
task migrate: :app do
puts 'Running migrations'
Sequel::Migrator.apply(WorkForwardNola::App.database, 'db/migrations')
end
desc 'Rollback migration'
task rollback: :app do
database = WorkForwardNola::App.database
version = (row = database[:schema_info].first) ? row[:version] : nil
Sequel::Migrator.apply(database, 'db/migrations', version - 1)
end
desc 'Dump the database schema'
task dump: :app do
database = WorkForwardNola::App.database
`sequel -d #{database.url} > db/schema.rb`
`pg_dump --schema-only #{database.url} > db/schema.sql`
end
desc 'Seed DB'
task seed: :app do
puts 'Running seed'
require 'sequel/extensions/seed'
Sequel.extension :seed
Sequel::Seeder.apply(WorkForwardNola::App.database, 'db')
end
desc 'Reset DB (delete all data)'
task reset: :app do
database = WorkForwardNola::App.database
Sequel::Migrator.run(database, 'db/migrations', target: 0)
Sequel::Migrator.run(database, 'db/migrations')
database.run 'delete from schema_seeds'
end
desc 'Migrate & seed DB all in one'
task setup: %i[migrate seed]
end
# rubocop:enable Metrics/BlockLength
begin
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
rescue LoadError
puts 'Failed to load RSpec::Core::RakeTask'
end
desc 'Default task: setup'
task default: ['db:setup', 'spec']