Class: Duple::PGRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/duple/pg_runner.rb

Overview

Decorates a Duple::Runner instance with helper methods for executing PostgreSQL commands.

Instance Method Summary collapse

Constructor Details

#initialize(runner) ⇒ PGRunner

Returns a new instance of PGRunner.



6
7
8
# File 'lib/duple/pg_runner.rb', line 6

def initialize(runner)
  @runner = runner
end

Instance Method Details

#pg_command(pg_command, flags, db_config, db_flag, tail = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/duple/pg_runner.rb', line 18

def pg_command(pg_command, flags, db_config, db_flag, tail = nil)
    command = []
    command << %{PGPASSWORD="#{db_config[:password]}"}
    command << pg_command
    command << flags
    command << %{-h #{db_config[:host]} -U #{db_config[:username]} -p #{db_config[:port]}}
    command << db_flag if db_flag
    command << db_config[:database]
    command << tail if tail
    @runner.run(command.join(' '))
end

#pg_dump(flags, dump_file, db_config) ⇒ Object



10
11
12
# File 'lib/duple/pg_runner.rb', line 10

def pg_dump(flags, dump_file, db_config)
  pg_command('pg_dump', flags, db_config, nil, "> #{dump_file}")
end

#pg_restore(flags, dump_file, db_config) ⇒ Object



14
15
16
# File 'lib/duple/pg_runner.rb', line 14

def pg_restore(flags, dump_file, db_config)
  pg_command('pg_restore', flags, db_config, '-d', "< #{dump_file}")
end