Class: Captive::Commands::DbCommands
- Inherits:
-
Thor
- Object
- Thor
- Captive::Commands::DbCommands
- Includes:
- Captive::CLIDependencies
- Defined in:
- lib/captive/commands/db_commands.rb
Class Method Summary collapse
Instance Method Summary collapse
- #dump(app, output_file = nil) ⇒ Object
- #exec(app, file) ⇒ Object
- #psql(app) ⇒ Object
- #restore(app, dump_file) ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
12 |
# File 'lib/captive/commands/db_commands.rb', line 12 def self.exit_on_failure? = true |
Instance Method Details
#dump(app, output_file = nil) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/captive/commands/db_commands.rb', line 23 def dump(app, output_file = nil) labels = { dumping: "Dump en cours..." } result = DbDump.new(kubectl: kubectl, trail: trail).run(app, output_file) { |step| puts paint.dim(" → #{labels[step]}") } puts paint.green(" ✓ Dump terminé : #{result}") rescue Captive::DumpError => e abort paint.red("✗ #{e.}") end |
#exec(app, file) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/captive/commands/db_commands.rb', line 43 def exec(app, file) result = DbExec.new(kubectl: kubectl).run(app, file, single_transaction: [:transaction]) puts paint.green(" ✓ #{result} appliqué.") rescue Errno::ENOENT => e abort paint.red("✗ Fichier introuvable : #{e.}") rescue Captive::ExecError => e abort paint.red("✗ #{e.}") end |
#psql(app) ⇒ Object
60 61 62 |
# File 'lib/captive/commands/db_commands.rb', line 60 def psql(app) DbPsql.new(kubectl: kubectl).run(app) end |
#restore(app, dump_file) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/captive/commands/db_commands.rb', line 73 def restore(app, dump_file) labels = { scaling_down: "Arrêt de l'app...", transferring: "Transfert du dump...", restoring: "Restauration...", scaling_up: "Relance de l'app...", } spinner = restore_spinner DbRestore.new(kubectl: kubectl, trail: trail).run(app, dump_file) do |step, elapsed = nil, info = nil| if step == :waiting spinner.auto_spin unless spinner.spinning? spinner.update(info: (info && !info.empty?) ? info : "en cours... #{elapsed.to_i}s") else spinner.success if spinner.spinning? puts paint.dim(" → #{labels[step]}") end end puts paint.green(" ✓ Restauration terminée.") rescue Errno::ENOENT => e abort paint.red("✗ Fichier introuvable : #{e.}") rescue Captive::RestoreError => e spinner.error if spinner.spinning? abort paint.red("✗ #{e.}") end |