Class: Hanami::CLI::Commands::App::DB::Structure::Dump Private

Inherits:
Command show all
Defined in:
lib/hanami/cli/commands/app/db/structure/dump.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0

Constant Summary

Constants inherited from Command

Command::ACTION_SEPARATOR

Instance Attribute Summary

Attributes inherited from Command

#system_call, #test_env_executor

Instance Method Summary collapse

Methods inherited from Command

#initialize, #nested_command?, #run_command

Methods inherited from Command

#app, inherited, #measure, #run_command

Methods inherited from Hanami::CLI::Command

#initialize, new

Constructor Details

This class inherits a constructor from Hanami::CLI::Commands::App::DB::Command

Instance Method Details

#call(app: false, slice: nil, gateway: nil, command_exit: method(:exit)) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0



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
# File 'lib/hanami/cli/commands/app/db/structure/dump.rb', line 17

def call(app: false, slice: nil, gateway: nil, command_exit: method(:exit), **)
  exit_codes = []

  databases(app: app, slice: slice, gateway: gateway).each do |database|
    relative_structure_path = database.structure_file
      .relative_path_from(database.slice.app.root)

    measure("#{database.name} structure dumped to #{relative_structure_path}") do
      catch :dump_failed do
        result = database.exec_dump_command
        exit_codes << result.exit_code if result.respond_to?(:exit_code)

        unless result.successful?
          out.puts result.err
          throw :dump_failed, false
        end

        migrations_sql = database.schema_migrations_sql_dump
        if migrations_sql
          File.open(database.structure_file, "a") do |f|
            f.puts "#{migrations_sql}\n"
          end
        end

        true
      end
    end
  end

  exit_codes.each do |code|
    break command_exit.(code) if code > 0
  end
end