From 28ce9d51f9082318e84f2a84385871394dcf2130 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Mon, 24 Jul 2023 17:14:22 +0200 Subject: [PATCH] Compare only major versions in AdjustUpgrade.pm Because PostgreSQL::Version is very nuanced about development version numbers, the comparison to 16beta2 makes it think that that release is older than 16, therefore applying a database tweak that doesn't work there (the comparison is only supposed to match when run on version 15). As suggested by Andrew Dunstan, fix by having AdjustUpgrade.pm public methods create a separate PostgreSQL::Version object to use for these comparisons, that only carries the major version number. While at it, have the same methods ensure that the objects given are of the expected type. Backpatch to 16. This module goes all the way back to 9.2, but there's probably no need for this fix except where betas still live. Co-authored-by: Andrew Dunstan Discussion: https://postgr.es/m/20230719110504.zbu74o54bqqlsufb@alvherre.pgsql --- src/test/perl/PostgreSQL/Test/AdjustUpgrade.pm | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/perl/PostgreSQL/Test/AdjustUpgrade.pm b/src/test/perl/PostgreSQL/Test/AdjustUpgrade.pm index a241d2ceff..e34dfb9243 100644 --- a/src/test/perl/PostgreSQL/Test/AdjustUpgrade.pm +++ b/src/test/perl/PostgreSQL/Test/AdjustUpgrade.pm @@ -76,6 +76,14 @@ sub adjust_database_contents my ($old_version, %dbnames) = @_; my $result = {}; + die "wrong type for \$old_version\n" + unless $old_version->isa("PostgreSQL::Version"); + + # The version tests can be sensitive if fixups have been applied in a + # recent version and pg_upgrade is run with a beta version, or such. + # Therefore, use a modified version object that only contains the major. + $old_version = PostgreSQL::Version->new($old_version->major); + # remove dbs of modules known to cause pg_upgrade to fail # anything not builtin and incompatible should clean up its own db foreach my $bad_module ('test_ddl_deparse', 'tsearch2') @@ -262,6 +270,11 @@ sub adjust_old_dumpfile { my ($old_version, $dump) = @_; + die "wrong type for \$old_version\n" + unless $old_version->isa("PostgreSQL::Version"); + # See adjust_database_contents about this + $old_version = PostgreSQL::Version->new($old_version->major); + # use Unix newlines $dump =~ s/\r\n/\n/g; @@ -579,6 +592,11 @@ sub adjust_new_dumpfile { my ($old_version, $dump) = @_; + die "wrong type for \$old_version\n" + unless $old_version->isa("PostgreSQL::Version"); + # See adjust_database_contents about this + $old_version = PostgreSQL::Version->new($old_version->major); + # use Unix newlines $dump =~ s/\r\n/\n/g;