forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 1
/
evm_dba.rake
70 lines (54 loc) · 2.37 KB
/
evm_dba.rake
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
require 'awesome_spawn'
require 'evm_rake_helper'
namespace :evm do
namespace :db do
desc 'Start the local ManageIQ EVM Database (VMDB)'
task :start do
LinuxAdmin::Service.new(ENV.fetch("APPLIANCE_PG_SERVICE")).start
end
desc 'Stop the local ManageIQ EVM Database (VMDB)'
task :stop do
LinuxAdmin::Service.new(ENV.fetch("APPLIANCE_PG_SERVICE")).stop
end
# Start the EVM Database silently - not to be a visible rake task
task :silent_start do
LinuxAdmin::Service.new(ENV.fetch("APPLIANCE_PG_SERVICE")).start
rescue AwesomeSpawn::CommandResultError
# ignore issues (ala silent)
end
# Stop the EVM Database silently - not to be a visible rake task
task :silent_stop do
LinuxAdmin::Service.new(ENV.fetch("APPLIANCE_PG_SERVICE")).stop
rescue AwesomeSpawn::CommandResultError
# ignore issues (ala silent)
end
desc "Seed the ManageIQ EVM Database (VMDB) with defaults"
task :seed => "db:seed"
desc "Destroys the ManageIQ EVM Database (VMDB) of all tables, views and indices"
task :destroy => %w[environment db:drop db:create]
desc "Resets the ManageIQ EVM Database (VMDB) of all tables, views and indices"
task :reset => [:destroy, 'db:migrate']
# schema.rb doesn't support views which is used by metrics
task :db_setup_not_supported do
warn "db:setup and db:reset are not supported! Please use evm:db:reset, db:migrate, or test:vmdb:setup instead."
exit 1
end
# this is used by the appliance console to create a db
# Example usage:
# RAILS_ENV=production REGION=99 bin/rake evm:db:region
# Alt usage:
# RAILS_ENV=production REGION=99 VERBOSE=false bin/rake db:reset db:seed
desc 'Set the region of the current ManageIQ EVM Database (VMDB)'
task :region => "evm:db:reset" do
region = ENV.fetch("REGION", nil)
puts "Initializing region and database..."
AwesomeSpawn.run!("bin/rails runner", :params => ["MiqDatabase.seed; MiqRegion.seed"])
rescue => err
message = err.kind_of?(AwesomeSpawn::CommandResultError) ? err.result.error : err.message
warn "Encountered issue setting up Database using region #{region}: #{message}\n"
raise
end
end
end
Rake::Task["db:setup"].prerequisites.unshift("evm:db:db_setup_not_supported")
Rake::Task["db:reset"].prerequisites.unshift("evm:db:db_setup_not_supported")