Class: ElasticDot::Command::Db
- Defined in:
- lib/elasticdot/command/db.rb
Class Method Summary collapse
- .console(opts) ⇒ Object
- .create(opts) ⇒ Object
- .destroy(opts) ⇒ Object
- .dump(opts) ⇒ Object
- .import(args, opts) ⇒ Object
- .info(opts) ⇒ Object
- .list(opts) ⇒ Object
- .promote(opts) ⇒ Object
Class Method Details
.console(opts) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/elasticdot/command/db.rb', line 37 def self.console(opts) unless which 'mysql' puts 'MySQL client is not installed.' puts 'Please install it to proceed.' exit 1 end find_db! opts info = api.get("/databases/#{@db}") uri = URI.parse info['uri'] puts 'Attaching... ' system "mysql -f -u#{info['user']} -p#{info['pass']} -h#{uri.host} -P#{uri.port} #{info['name']}" end |
.create(opts) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/elasticdot/command/db.rb', line 83 def self.create(opts) find_plan! opts params = {plan: @plan} if conf = opts[:conf] unless File.exists? conf puts "#{conf}: no such file or directory" exit 1 end f = File.read conf params.merge!(conf: f) end info = api.post "/databases", params spinner "Database #{info['identifier']} is provisioning..." do until info['status'] == 'active' sleep 3 info = api.get("/databases/#{info['identifier']}") end end end |
.destroy(opts) ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/elasticdot/command/db.rb', line 109 def self.destroy(opts) find_db! opts print "Destroying database #{@db}... " info = api.delete("/databases/#{@db}") puts 'done' end |
.dump(opts) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/elasticdot/command/db.rb', line 21 def self.dump(opts) unless which 'mysqldump' puts 'MySQL client is not installed.' puts 'Please install it to proceed.' exit 1 end find_db! opts info = api.get("/databases/#{@db}") uri = URI.parse info['uri'] system "mysqldump --opt -c -u#{info['user']} -p#{info['pass']} -h#{uri.host} -P#{uri.port} #{info['name']}" end |
.import(args, opts) ⇒ Object
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 |
# File 'lib/elasticdot/command/db.rb', line 54 def self.import(args, opts) unless which 'mysql' puts 'MySQL client is not installed.' puts 'Please install it to proceed.' exit 1 end find_db! opts dump = args.shift unless dump puts 'Please specify a dump file.' exit 1 end unless File.exists? dump puts "#{dump}: no such file or directory" exit 1 end info = api.get("/databases/#{@db}") uri = URI.parse info['uri'] spinner 'Importing...' do system "mysql -f -u#{info['user']} -p#{info['pass']} -h#{uri.host} -P#{uri.port} #{info['name']} < #{dump}" end end |
.info(opts) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/elasticdot/command/db.rb', line 119 def self.info(opts) find_db! opts db = api.get("/databases/#{@db}") puts "=== Database #{db['identifier']}" puts "Plan: \t#{db['plan']['name']}" puts "Nodes: \t#{db['plan']['nodes']}" unless db['plan']['shared'] puts "Version: \t#{db['version']}" puts "Status: \t#{db['status']}" puts "Name: \t#{db['name']}" puts "User: \t#{db['user']}" puts "Password: \t#{db['pass']}" puts "URI: \t#{db['uri']}" puts "Tables: \t#{db['tables']}" puts "Disk Space Used:\t#{db['space_used']}" puts "AVG CPU Load: \t#{db['cpu_load']}" puts "Created at: \t#{db['created_at']}" end |
.list(opts) ⇒ Object
139 140 141 142 143 144 145 |
# File 'lib/elasticdot/command/db.rb', line 139 def self.list(opts) puts "=== database list" list = api.get("/databases") list.each {|db| puts db['identifier'] } end |
.promote(opts) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/elasticdot/command/db.rb', line 4 def self.promote(opts) find_app! opts find_db! opts spinner "Promoting database..." do info = api.post "/databases/#{@db}/promote", app: @app end spinner "Restarting dots..." do loop do sleep 3 info = api.get "/domains/#{@app}" break if info['status'] == 'active' end end end |