Module: Capistrano::Postgresql::PsqlHelpers
- Defined in:
- lib/capistrano/postgresql/psql_helpers.rb
Instance Method Summary collapse
- #database_exists? ⇒ Boolean
- #db_user_exists? ⇒ Boolean
- #psql(*args) ⇒ Object
-
#psql_on_app_db(*args) ⇒ Object
Runs psql on the application database.
Instance Method Details
#database_exists? ⇒ Boolean
23 24 25 |
# File 'lib/capistrano/postgresql/psql_helpers.rb', line 23 def database_exists? psql_on_db fetch(:pg_system_db), '-tAc', %Q{"SELECT 1 FROM pg_database WHERE datname='#{fetch(:pg_database)}';" | grep -q 1} end |
#db_user_exists? ⇒ Boolean
19 20 21 |
# File 'lib/capistrano/postgresql/psql_helpers.rb', line 19 def db_user_exists? psql_on_db fetch(:pg_system_db),'-tAc', %Q{"SELECT 1 FROM pg_roles WHERE rolname='#{fetch(:pg_username)}';" | grep -q 1} end |
#psql(*args) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/capistrano/postgresql/psql_helpers.rb', line 5 def psql(*args) # Reminder: -u #{fetch(:pg_system_user)} seen below differs slightly from -U, an option on the psql command: https://www.postgresql.org/docs/9.6/static/app-psql.html args.unshift("-U #{fetch(:pg_system_user)}") if fetch(:pg_without_sudo) # Add the :pg_system_user to psql command since we aren't using sudo anymore # test :sudo, "-u #{fetch(:pg_system_user)} psql", *args cmd = [ :psql, *args ] cmd = [ :sudo, "-u #{fetch(:pg_system_user)}", *cmd ] unless fetch(:pg_without_sudo) test *cmd.flatten end |
#psql_on_app_db(*args) ⇒ Object
Runs psql on the application database
15 16 17 |
# File 'lib/capistrano/postgresql/psql_helpers.rb', line 15 def psql_on_app_db(*args) psql_on_db(fetch(:pg_database), *args) end |