Class: Hanami::CLI::Commands::App::DB::Utils::Postgres Private
- 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.
Constant Summary
Constants inherited from Database
Instance Attribute Summary
Attributes inherited from Database
Instance Method Summary collapse
-
#cli_env_vars ⇒ Object
private
-
#create_command ⇒ Object
private
-
#drop_command ⇒ Object
private
-
#dump_command ⇒ Object
private
-
#dump_file ⇒ Object
private
-
#escaped_name ⇒ Object
private
-
#load_command ⇒ Object
private
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_vars ⇒ 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.
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_command ⇒ 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.
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_command ⇒ 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.
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_command ⇒ 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.
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_file ⇒ 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.
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_name ⇒ 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.
40 41 42 |
# File 'lib/hanami/cli/commands/app/db/utils/postgres.rb', line 40 def escaped_name Shellwords.escape(name) end |
#load_command ⇒ 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.
35 36 37 |
# File 'lib/hanami/cli/commands/app/db/utils/postgres.rb', line 35 def load_command raise "Not Implemented Yet" end |