Class: Pgchief::Command::DatabaseRestore

Inherits:
Base
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/pgchief/command/database_restore.rb

Overview

Command object to restore a database

Instance Attribute Summary collapse

Attributes inherited from Base

#conn, #params

Instance Method Summary collapse

Methods inherited from Base

call, #initialize

Constructor Details

This class inherits a constructor from Pgchief::Command::Base

Instance Attribute Details

#databaseObject (readonly)

Returns the value of attribute database.



11
12
13
# File 'lib/pgchief/command/database_restore.rb', line 11

def database
  @database
end

#filenameObject (readonly)

Returns the value of attribute filename.



11
12
13
# File 'lib/pgchief/command/database_restore.rb', line 11

def filename
  @filename
end

Instance Method Details

#callObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pgchief/command/database_restore.rb', line 15

def call
  @database = params.first
  @filename = params.last
  raise Pgchief::Errors::DatabaseMissingError unless db_exists?

  download! if Pgchief::Config.remote_restore
  restore!

  "Database '#{database}' restored from #{filename}"
rescue PG::Error => e
  "Error: #{e.message}"
ensure
  conn.close
end