-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathRakefile
92 lines (77 loc) · 2.24 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
require 'bundler/gem_tasks'
require 'rake/testtask'
require 'tech404logs'
Rake::TestTask.new(test: ['env:test', 'db:schema:load', :environment]) do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/**/*_test.rb']
end
task :default => :test
namespace :env do
task :test do
ENV['RACK_ENV'] = 'test'
ENV['DATABASE_URL'] = ENV.fetch('TEST_DATABASE_URL')
end
end
task :environment do
Tech404logs.preboot
end
task :reindex => [:environment] do
Tech404logs.db.execute 'REFRESH MATERIALIZED VIEW searchable_messages'
end
namespace :user do
desc 'Set a users opted_out flag to true and stop recording messages from them'
task :optout => [:environment] do
Tech404logs::Tasks::OptOutUser.run
end
desc 'Redact user profile and historic messages'
task :redact => [:environment] do
Tech404logs::Tasks::RedactUser.run
end
end
namespace :db do
task auto: :environment do
DataMapper.auto_upgrade!
end
task :create do
system("psql #{ENV['DATABASE_URL']} -c '\\q'")
next if $?.success?
db_name = ENV['DATABASE_URL'].split('/').last.strip
sh "createdb #{db_name}"
end
task load_migrations: :environment do
require 'dm-migrations/migration_runner'
FileList['db/migrate/*.rb'].each do |migration|
load migration
end
end
task :migrate, [:version] => [:load_migrations] do |t, args|
if version = args[:version]
puts "=> Migrating up to version #{version}"
migrate_up!(version)
else
puts '=> Migrating up'
migrate_up!
end
end
task :rollback, [:verson] => [:load_migrations] do |t, args|
if version = args[:version]
puts "=> Rolling back to version #{version}"
migrate_down!(version)
else
puts "=> Rolling back one migration"
applied = migrations.sort.reverse.drop_while(&:needs_up?).reverse
current = applied.last
migrate_down!(current.position - 1)
end
end
namespace :schema do
task :dump do
sh "pg_dump --schema-only --no-owner #{ENV['DATABASE_URL']} > db/schema.sql"
sh "pg_dump --table migration_info --data-only --no-owner #{ENV['DATABASE_URL']} >> db/schema.sql"
end
task load: 'db:create' do
sh "psql #{ENV['DATABASE_URL']} < db/schema.sql"
end
end
end