Class: Jatai::Commands::Database

Inherits:
Thor
  • Object
show all
Defined in:
lib/jatai/commands/database.rb

Instance Method Summary collapse

Instance Method Details

#backupObject



46
47
48
49
50
51
52
53
54
55
# File 'lib/jatai/commands/database.rb', line 46

def backup
  slug = helper.app_slug

  name = "manual-#{Time.now.strftime("%Y%m%d-%H%M%S")}"
  helper.info("Criando backup do banco de dados...")
  result = helper.api.post("/api/v1/apps/#{slug}/database/backups", body: { name: name })
  helper.success("Backup criado: #{result["id"]} (#{name})")
rescue Api::Client::ApiError => e
  helper.error("Erro: #{e.message}")
end

#backupsObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/jatai/commands/database.rb', line 27

def backups
  slug = helper.app_slug

  result = helper.api.get("/api/v1/apps/#{slug}/database/backups")
  backups_list = result["backups"] || []

  if backups_list.empty?
    helper.info("Nenhum backup disponível.")
    return
  end

  backups_list.each do |b|
    puts "#{helper.pastel.bold(b["id"])}#{b["name"]} (#{b["created_at"]})"
  end
rescue Api::Client::ApiError => e
  helper.error("Erro: #{e.message}")
end

#infoObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/jatai/commands/database.rb', line 11

def info
  slug = helper.app_slug

  db = helper.api.get("/api/v1/apps/#{slug}/database")

  puts helper.pastel.bold("Banco de dados de #{slug}")
  puts "  Tier:     #{db["database_tier"] || db["mode"]}"
  puts "  Host:     #{db["host"]}"
  puts "  Porta:    #{db["port"]}"
  puts "  Nome:     #{db["name"]}"
  puts "  Status:   #{db["status"]}"
rescue Api::Client::ApiError => e
  helper.error("Erro: #{e.message}")
end

#restore(backup_id) ⇒ Object



58
59
60
# File 'lib/jatai/commands/database.rb', line 58

def restore(backup_id)
  helper.error("Recurso em desenvolvimento. Restauração de backups ainda não está disponível.")
end