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



22
23
24
# File 'lib/kamal_backup/databases/postgres.rb', line 22

def adapter_name
  "postgres"
end

#current_restore_commandObject



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

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



52
53
54
# File 'lib/kamal_backup/databases/postgres.rb', line 52

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

#dump_commandObject



30
31
32
33
# File 'lib/kamal_backup/databases/postgres.rb', line 30

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

#dump_extensionObject



26
27
28
# File 'lib/kamal_backup/databases/postgres.rb', line 26

def dump_extension
  "pgdump"
end

#scratch_restore_command(target) ⇒ Object



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

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



56
57
58
# File 'lib/kamal_backup/databases/postgres.rb', line 56

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