diff --git a/lib/backup_restore/restorer.rb b/lib/backup_restore/restorer.rb index 6c90d5ace4e..c5047132fa6 100644 --- a/lib/backup_restore/restorer.rb +++ b/lib/backup_restore/restorer.rb @@ -8,6 +8,22 @@ module BackupRestore class Restorer attr_reader :success + def self.pg_produces_portable_dump?(version) + version = Gem::Version.new(version) + + %w{ + 10.3 + 9.6.8 + 9.5.12 + 9.4.17 + 9.3.22 + }.each do |unportable_version| + return false if Gem::Dependency.new("", "~> #{unportable_version}").match?("", version) + end + + true + end + def initialize(user_id, opts = {}) @user_id = user_id @client_id = opts[:client_id] @@ -266,20 +282,7 @@ module BackupRestore end def can_restore_into_different_schema? - dumped_by_version = Gem::Version.new(get_dumped_by_version) - - return false if dumped_by_version >= Gem::Version.new("10.3") - - %w{ - 9.6.8 - 9.5.12 - 9.4.17 - 9.3.22 - }.each do |version| - return false if Gem::Dependency.new("", "~> #{version}").match?("", dumped_by_version) - end - - true + self.class.pg_produces_portable_dump?(get_dumped_by_version) end def restore_dump_command diff --git a/spec/lib/backup_restore/restorer_spec.rb b/spec/lib/backup_restore/restorer_spec.rb new file mode 100644 index 00000000000..b5c7cae5c7b --- /dev/null +++ b/spec/lib/backup_restore/restorer_spec.rb @@ -0,0 +1,17 @@ +require 'rails_helper' + +describe BackupRestore::Restorer do + it 'detects which pg_dump output is restorable to different schemas' do + { + "9.6.7" => true, + "9.6.8" => false, + "9.6.9" => false, + "10.2" => true, + "10.3" => false, + "10.3.1" => false, + "10.4" => false, + }.each do |key, value| + expect(described_class.pg_produces_portable_dump?(key)).to eq(value) + end + end +end