class Martilla::Postgres

Public Instance Methods

dump(tmp_file:, gzip:) click to toggle source
# File lib/martilla/databases/postgres.rb, line 3
def dump(tmp_file:, gzip:)
  if gzip
    bash("set -o pipefail && pg_dump #{connection_string} | gzip -c > #{tmp_file}")
  else
    bash("pg_dump #{connection_string} > #{tmp_file}")
  end

  return if $?.success?
  raise Error.new("Database dump failed with code #{$?.exitstatus}")
end

Private Instance Methods

connection_string() click to toggle source
# File lib/martilla/databases/postgres.rb, line 16
def connection_string
  "postgres://#{user}:#{password}@#{host}:#{port}/#{db}"
end
db() click to toggle source
# File lib/martilla/databases/postgres.rb, line 36
def db
  @options['db'] || ENV['PG_DATABASE']
end
host() click to toggle source
# File lib/martilla/databases/postgres.rb, line 20
def host
  @options['host'] || ENV['PG_HOST'] || 'localhost'
end
password() click to toggle source
# File lib/martilla/databases/postgres.rb, line 32
def password
  @options['password'] || ENV['PG_PASSWORD']
end
port() click to toggle source
# File lib/martilla/databases/postgres.rb, line 24
def port
  @options['port'] || ENV['PG_PORT'] || '5432'
end
user() click to toggle source
# File lib/martilla/databases/postgres.rb, line 28
def user
  @options['user'] || ENV['PG_USER']
end