Skip to content

Commit

Permalink
Merge pull request #402 from NickLaMuro/support-magic-number-pre-fetc…
Browse files Browse the repository at this point in the history
…h-in-postgres-admin-restore

Add :backup_type option to PostgresAdmin.restore
  • Loading branch information
carbonin authored Nov 6, 2018
2 parents 9e99167 + 0505809 commit b7d29b3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/gems/pending/util/postgres_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ def self.backup(opts)
end

def self.restore(opts)
file = opts[:local_file]
if pg_dump_file?(file)
file = opts[:local_file]
backup_type = opts.delete(:backup_type)
if backup_type == :pgdump || pg_dump_file?(file)
restore_pg_dump(opts)
elsif base_backup_file?(file)
elsif backup_type == :basebackup || base_backup_file?(file)
restore_pg_basebackup(file)
else
raise "#{file} is not a database backup"
Expand Down
22 changes: 22 additions & 0 deletions spec/util/postgres_admin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,28 @@
expect(book_count).to eq(3)
end
end

# Note, we aren't actually prefetching the magic here, but this is mean to
# simulate that an override works as expected. We are stubbing the the
# restore calls here, so just making sure the logic works.
context "'pre-fetching' magic number" do
let(:dummy_base_opts) { { :local_file => "foo" } }

before do
allow(PostgresAdmin).to receive(:pg_dump_file?).and_return(false)
allow(PostgresAdmin).to receive(:base_backup_file?).and_return(false)
end

it "calls `.restore_pg_dump` with :backup_type => :pgdump" do
expect(PostgresAdmin).to receive(:restore_pg_dump).with(dummy_base_opts)
PostgresAdmin.restore(dummy_base_opts.merge(:backup_type => :pgdump))
end

it "calls `.restore_pg_basebackup` with :backup_type => :basebackup" do
expect(PostgresAdmin).to receive(:restore_pg_basebackup).with("foo")
PostgresAdmin.restore(dummy_base_opts.merge(:backup_type => :basebackup))
end
end
end

describe ".base_backup_file?" do
Expand Down

0 comments on commit b7d29b3

Please sign in to comment.