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
Database::DATABASE_CLASS_RESOLVER
Instance Attribute Summary
Attributes inherited from Database
#gateway_name, #slice, #system_call
Instance Method Summary collapse
- #exec_create_command ⇒ Object private
- #exec_drop_command ⇒ Object private
- #exec_dump_command ⇒ Object private
- #exec_load_command ⇒ Object private
- #exists? ⇒ Boolean private
- #schema_migrations_sql_dump ⇒ Object private
Methods inherited from Database
#applied_migrations, #connection, database_class, #database_uri, #database_url, #db_config_dir?, #db_config_path, from_slice, #gateway, #initialize, #migrations_dir?, #migrations_path, #migrator, #name, #run_migrations, #sequel_migrator, #structure_file
Constructor Details
This class inherits a constructor from Hanami::CLI::Commands::App::DB::Utils::Database
Instance Method Details
#exec_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.
18 19 20 21 22 |
# File 'lib/hanami/cli/commands/app/db/utils/postgres.rb', line 18 def exec_create_command return true if exists? system_call.call("createdb #{escaped_name}", env: cli_env_vars) end |
#exec_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.
26 27 28 29 30 |
# File 'lib/hanami/cli/commands/app/db/utils/postgres.rb', line 26 def exec_drop_command return true unless exists? system_call.call("dropdb #{escaped_name}", env: cli_env_vars) end |
#exec_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.
41 42 43 44 45 46 |
# File 'lib/hanami/cli/commands/app/db/utils/postgres.rb', line 41 def exec_dump_command system_call.call( "pg_dump --schema-only --no-privileges --no-owner --file #{structure_file} #{escaped_name}", env: cli_env_vars ) end |
#exec_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.
50 51 52 53 54 55 |
# File 'lib/hanami/cli/commands/app/db/utils/postgres.rb', line 50 def exec_load_command system_call.call( "psql --set ON_ERROR_STOP=1 --quiet --no-psqlrc --output #{File::NULL} --file #{structure_file} #{escaped_name}", env: cli_env_vars ) end |
#exists? ⇒ Boolean
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.
34 35 36 37 |
# File 'lib/hanami/cli/commands/app/db/utils/postgres.rb', line 34 def exists? result = system_call.call("psql -t -A -c '\\list #{escaped_name}'", env: cli_env_vars) result.successful? && result.out.include?("#{name}|") # start_with? end |
#schema_migrations_sql_dump ⇒ 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.
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/hanami/cli/commands/app/db/utils/postgres.rb', line 57 def schema_migrations_sql_dump migrations_sql = super return unless migrations_sql search_path = gateway.connection .fetch("SHOW search_path").to_a.first .fetch(:search_path) +"SET search_path TO #{search_path};\n\n" << migrations_sql end |