Skip to content

Commit

Permalink
Fixing #11 (#12)
Browse files Browse the repository at this point in the history
* Fixing #11 added extra param for which restore command to use, can't generalize based on file type.

* Need to catch empty logs oops

* psql command reverted to forked original and fixed grabbing of parameter for restore type

* Missed an equals sign... oops

* @ sign added by autocomplete, oops...
  • Loading branch information
Varjitt Jeeva authored Oct 9, 2017
1 parent 259c3b8 commit e3db57e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.mdown
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ Unless you need to change any of the defaults, a standard configuration for Mong

###### Full `postgresql` Engine Example

You can specify the username for accessing the postgres server (other than the default `postgres`) for when you run the tests. Furthermore, you can specify the file type to be `sql` or `dump`. If `sql`, then the restore will be done with the `psql` command, which takes a `.sql` file. If `dump`, then the restore will be done with the `pg_restore` command, which takes a `.pg_dump` file (usually, or whatever file is obtained using the pg_dump command).
You can specify the username for accessing the postgres server (other than the default `postgres`) for when you run the tests. Furthermore, you can specify the file type. Since the file type can be anything, the `restore_type` must be set to know which command to restore with. If `psql`, then the restore will be done with the `psql` command, which takes a `.sql` file. If `pg_restore`, then the restore will be done with the `pg_restore` command, which takes a dump file.

engine:
type: postgresql
Expand All @@ -320,6 +320,7 @@ You can specify the username for accessing the postgres server (other than the d
docker_image: postgres
docker_tag: 9.5.0
extension: .sql
restore_type: psql
port: 5432
sql_file: PostgreSQL.sql
username: postgres
Expand Down
7 changes: 4 additions & 3 deletions lib/engines/postgresql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def initialize(params)
@docker_image ||= 'postgres'
@docker_tag ||= '9.5'
@extension ||= '.sql'
@restore_type = params[:restore_type] || 'psql'
@port ||= 5432
@username = params[:username] || 'postgres'
@docker_env ||= ["POSTGRES_USER=#{@username}", "POSTGRES_DB=#{@database}"]
Expand All @@ -24,9 +25,9 @@ def initialize(params)

def load_backup(path)
Dir.chdir(path) do
if @extension.include?(".sql")
run_command("psql --no-password --exit-on-error --username=#{@username} --host=#{container_ip_address} --port=#{@port} --dbname=#{@database} < #{@sql_file}")
elsif @extension.include?(".pg_dump")
if @restore_type.include?("psql")
run_command("psql --no-password --set ON_ERROR_STOP=on --username=#{@username} --host=#{container_ip_address} --port=#{@port} --dbname=#{@database} < #{@sql_file}")
elsif @restore_type.include?("pg_restore")
run_command("pg_restore --no-password --exit-on-error --username=#{@username} --host=#{container_ip_address} --port=#{@port} --dbname=#{@database} < #{@sql_file}")
else
raise 'File Type parameter in Postgresql Driver is invalid.'
Expand Down
8 changes: 5 additions & 3 deletions ui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,11 @@ def backups_with_logs
backup = {}
backup[:date] = Files.extract_datetime_from_backup_path(config, path)
backup[:backup] = path
logss.each do |log|
if log[:epoch].to_s == backup[:date].strftime('%s').to_s
backup[:log] = log
if logss != nil
logss.each do |log|
if log[:epoch].to_s == backup[:date].strftime('%s').to_s
backup[:log] = log
end
end
end
backups << backup
Expand Down

0 comments on commit e3db57e

Please sign in to comment.