FIX: backups taken by pg_dump >= 11 are nonportable (#7893)

FIX: backups taken by pg_dump >= 11 are nonportable (#7893)

diff --git a/lib/backup_restore/restorer.rb b/lib/backup_restore/restorer.rb
index c7ff926..1e95502 100644
--- a/lib/backup_restore/restorer.rb
+++ b/lib/backup_restore/restorer.rb
@@ -11,7 +11,7 @@ module BackupRestore
     attr_reader :success
 
     def self.pg_produces_portable_dump?(version)
-      version = Gem::Version.new(version)
+      gem_version = Gem::Version.new(version)
 
       %w{
         10.3
@@ -20,7 +20,9 @@ module BackupRestore
         9.4.17
         9.3.22
       }.each do |unportable_version|
-        return false if Gem::Dependency.new("", "~> #{unportable_version}").match?("", version)
+        # anything pg 11 or above will produce a non-portable dump
+        return false if version.to_i >= 11
+        return false if Gem::Dependency.new("", "~> #{unportable_version}").match?("", gem_version)
       end
 
       true
diff --git a/spec/lib/backup_restore/restorer_spec.rb b/spec/lib/backup_restore/restorer_spec.rb
index 1cd1dd6..49f829b 100644
--- a/spec/lib/backup_restore/restorer_spec.rb
+++ b/spec/lib/backup_restore/restorer_spec.rb
@@ -12,6 +12,9 @@ describe BackupRestore::Restorer do
       "10.3" => false,
       "10.3.1" => false,
       "10.4" => false,
+      "11" => false,
+      "11.4" => false,
+      "21" => false,
     }.each do |key, value|
       expect(described_class.pg_produces_portable_dump?(key)).to eq(value)
     end

GitHub sha: 08b28680

Why is that in the loop if it isn’t using the unportable_version variable?

1 Like

Resolved by DEV: pull static check out of loop by Supermathie · Pull Request #7924 · discourse/discourse · GitHub (I think :smiley: )

1 Like

DEV: pull static check out of loop