Module: Capistrano::Postgresql::PsqlHelpers

Defined in:
lib/capistrano/postgresql/psql_helpers.rb

Instance Method Summary collapse

Instance Method Details

#database_exists?(db_name) ⇒ Boolean



19
20
21
# File 'lib/capistrano/postgresql/psql_helpers.rb', line 19

def database_exists?(db_name)
  psql '-tAc', %Q{"SELECT 1 FROM pg_database WHERE datname='#{db_name}';" | grep -q 1}
end

#db_user_exists?(name) ⇒ Boolean



15
16
17
# File 'lib/capistrano/postgresql/psql_helpers.rb', line 15

def db_user_exists?(name)
  psql '-tAc', %Q{"SELECT 1 FROM pg_roles WHERE rolname='#{name}';" | grep -q 1}
end

#psql(*args) ⇒ Object

returns true or false depending on the remote command exit status



6
7
8
# File 'lib/capistrano/postgresql/psql_helpers.rb', line 6

def psql(*args)
  psql_on_db(fetch(:pg_system_db), *args)
end

#psql_on_app_db(*args) ⇒ Object

Runs psql on the application database



11
12
13
# File 'lib/capistrano/postgresql/psql_helpers.rb', line 11

def psql_on_app_db(*args)
  psql_on_db(fetch(:pg_database), *args)
end