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 collapse
- SCHEMA_DUMP_FILTERS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[ /^\\(un)?restrict/, /^-- Dumped (from|by) (database version|pg_dump version)/, ].freeze
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
rubocop:disable Layout/LineLength.
- #exists? ⇒ Boolean private
-
#schema_migrations_sql_dump ⇒ Object
private
rubocop:enable Layout/LineLength.
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, #structure_sql_dump
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.
23 24 25 26 27 |
# File 'lib/hanami/cli/commands/app/db/utils/postgres.rb', line 23 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.
31 32 33 34 35 |
# File 'lib/hanami/cli/commands/app/db/utils/postgres.rb', line 31 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.
48 49 50 51 52 53 |
# File 'lib/hanami/cli/commands/app/db/utils/postgres.rb', line 48 def exec_dump_command system_call.call( "pg_dump --schema-only --no-privileges --no-owner #{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.
rubocop:disable Layout/LineLength
58 59 60 61 62 63 |
# File 'lib/hanami/cli/commands/app/db/utils/postgres.rb', line 58 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.
39 40 41 42 43 44 |
# File 'lib/hanami/cli/commands/app/db/utils/postgres.rb', line 39 def exists? result = system_call.call("psql -t -A -c '\\list #{escaped_name}' template1", env: cli_env_vars) raise Hanami::CLI::DatabaseExistenceCheckError.new(result.err) unless 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.
rubocop:enable Layout/LineLength
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/hanami/cli/commands/app/db/utils/postgres.rb', line 66 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 |