Class: Hanami::CLI::Commands::App::DB::Utils::Postgres Private

Inherits:
Database
  • Object
show all
Defined in:
lib/hanami/cli/commands/app/db/utils/postgres.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 Database

Database::SCHEME_MAP

Instance Attribute Summary

Attributes inherited from Database

#app, #config

Instance Method Summary collapse

Methods inherited from Database

[], #applied_migrations, #connection, #gateway, #initialize, #migrator, #name, #rom_config, #root_path, #run_migrations

Constructor Details

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

Instance Method Details

#cli_env_varsObject

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



45
46
47
48
49
50
51
52
# File 'lib/hanami/cli/commands/app/db/utils/postgres.rb', line 45

def cli_env_vars
  @cli_env_vars ||= {}.tap do |vars|
    vars["PGHOST"] = config.host.to_s
    vars["PGPORT"] = config.port.to_s if config.port
    vars["PGUSER"] = config.user.to_s if config.user
    vars["PGPASSWORD"] = config.pass.to_s if config.pass
  end
end

#create_commandObject

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



16
17
18
19
20
21
22
# File 'lib/hanami/cli/commands/app/db/utils/postgres.rb', line 16

def create_command
  existing_stdout, status = Open3.capture2(cli_env_vars, "psql -t -c '\\l #{escaped_name}'")

  return true if status.success? && existing_stdout.include?(escaped_name)

  system(cli_env_vars, "createdb #{escaped_name}")
end

#drop_commandObject

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



25
26
27
# File 'lib/hanami/cli/commands/app/db/utils/postgres.rb', line 25

def drop_command
  system(cli_env_vars, "dropdb #{escaped_name}")
end

#dump_commandObject

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



30
31
32
# File 'lib/hanami/cli/commands/app/db/utils/postgres.rb', line 30

def dump_command
  system(cli_env_vars, "pg_dump --schema-only --no-owner #{escaped_name} > #{dump_file}")
end

#dump_fileObject

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



55
56
57
# File 'lib/hanami/cli/commands/app/db/utils/postgres.rb', line 55

def dump_file
  "#{root_path}/db/structure.sql"
end

#escaped_nameObject

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



40
41
42
# File 'lib/hanami/cli/commands/app/db/utils/postgres.rb', line 40

def escaped_name
  Shellwords.escape(name)
end

#load_commandObject

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



35
36
37
# File 'lib/hanami/cli/commands/app/db/utils/postgres.rb', line 35

def load_command
  raise "Not Implemented Yet"
end