7824: Merge branch 'master' into 7824-arvls-arvput-collection-api-usage
[arvados.git] / services / api / Rakefile
1 #!/usr/bin/env rake
2 # Add your own tasks in files placed in lib/tasks ending in .rake,
3 # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
5 require File.expand_path('../config/application', __FILE__)
6
7 begin
8   ok = PgPower
9 rescue
10   abort "Hm, pg_power is missing. Make sure you use 'bundle exec rake ...'"
11 end
12
13 Server::Application.load_tasks
14
15 namespace :test do
16   task(:run).clear
17   # Copied from the definition in Rails 3.2.
18   # This may need to be updated if we upgrade Rails.
19   task :run do
20     errors = %w(test:units test:functionals test:integration test:tasks).collect do |task|
21       begin
22         Rake::Task[task].invoke
23         nil
24       rescue => e
25         { :task => task, :exception => e }
26       end
27     end.compact
28
29     if errors.any?
30       puts errors.map { |e| "Errors running #{e[:task]}! #{e[:exception].inspect}" }.join("\n")
31       abort
32     end
33   end
34 end
35
36 namespace :db do
37   namespace :structure do
38     task :dump do
39       require 'tempfile'
40       origfnm = File.expand_path('../db/structure.sql', __FILE__)
41       tmpfnm = Tempfile.new 'structure.sql', File.expand_path('..', origfnm)
42       begin
43         tmpfile = File.new tmpfnm, 'w'
44         origfile = File.new origfnm
45         origfile.each_line do |line|
46           if /^SET lock_timeout = 0;/ =~ line
47             # Avoid edit wars between versions that do/don't write this line.
48             next
49           elsif /^COMMENT ON EXTENSION/ =~ line
50             # Avoid warning message when loading:
51             # "structure.sql:22: ERROR:  must be owner of extension plpgsql"
52             tmpfile.write "-- "
53           end
54           tmpfile.write line
55         end
56         origfile.close
57         tmpfile.close
58         File.rename tmpfnm, origfnm
59         tmpfnm = false
60       ensure
61         File.unlink tmpfnm if tmpfnm
62       end
63     end
64   end
65 end
66
67 # Work around Rails3+PostgreSQL9.5 incompatibility (pg_dump used to
68 # accept -i as a no-op, but now it's not accepted at all).
69 module Kernel
70   alias_method :orig_backtick, :`
71   def `(*args) #`#` sorry, parsers
72     args[0].sub!(/\Apg_dump -i /, 'pg_dump ') rescue nil
73     orig_backtick(*args)
74   end
75 end