Class: KamalBackup::Databases::Postgres

Inherits:
Base
  • Object
show all
Defined in:
lib/kamal_backup/databases/postgres.rb

Constant Summary collapse

SOURCE_ENV_KEYS =
%w[
  PGHOST
  PGPORT
  PGUSER
  PGPASSWORD
  PGDATABASE
  PGSSLMODE
  PGSSLROOTCERT
  PGSSLCERT
  PGSSLKEY
  PGCONNECT_TIMEOUT
  PGSERVICE
  PGPASSFILE
].freeze

Instance Attribute Summary

Attributes inherited from Base

#config, #redactor

Instance Method Summary collapse

Methods inherited from Base

#backup, #backup_tags, build, #database_filename, #initialize, #restore_to_current, #restore_to_scratch

Constructor Details

This class inherits a constructor from KamalBackup::Databases::Base

Instance Method Details

#adapter_nameObject



24
25
26
# File 'lib/kamal_backup/databases/postgres.rb', line 24

def adapter_name
  'postgres'
end

#current_restore_commandObject



37
38
39
40
41
42
43
44
# File 'lib/kamal_backup/databases/postgres.rb', line 37

def current_restore_command
  connection = current_connection
  database = connection.fetch('PGDATABASE')

  argv = %w[pg_restore --clean --if-exists --no-owner --no-privileges --dbname]
  argv << database
  CommandSpec.new(argv: argv, env: connection)
end

#current_target_identifierObject



54
55
56
# File 'lib/kamal_backup/databases/postgres.rb', line 54

def current_target_identifier
  value('DATABASE_URL') || value('PGDATABASE')
end

#dump_commandObject



32
33
34
35
# File 'lib/kamal_backup/databases/postgres.rb', line 32

def dump_command
  argv = %w[pg_dump --format=custom --no-owner --no-privileges]
  CommandSpec.new(argv: argv, env: current_connection)
end

#dump_extensionObject



28
29
30
# File 'lib/kamal_backup/databases/postgres.rb', line 28

def dump_extension
  'pgdump'
end

#scratch_restore_command(target) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/kamal_backup/databases/postgres.rb', line 46

def scratch_restore_command(target)
  connection = current_connection.merge('PGDATABASE' => target)

  argv = %w[pg_restore --clean --if-exists --no-owner --no-privileges --dbname]
  argv << target
  CommandSpec.new(argv: argv, env: connection)
end

#scratch_target_identifier(target) ⇒ Object



58
59
60
# File 'lib/kamal_backup/databases/postgres.rb', line 58

def scratch_target_identifier(target)
  [current_connection['PGHOST'], target].compact.join('/')
end