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