From 6a5bcdf6b3c9244e164455792cec612e317cb8d3 Mon Sep 17 00:00:00 2001
From: Justin Pryzby <pryzbyj@telsasoft.com>
Date: Sat, 5 Dec 2020 22:31:19 -0600
Subject: [PATCH v2 1/3] WIP: pg_upgrade/test.sh: changes needed to allow
 testing upgrade from v11

---
 src/bin/pg_upgrade/test.sh | 92 ++++++++++++++++++++++++++++++++++----
 1 file changed, 84 insertions(+), 8 deletions(-)

diff --git a/src/bin/pg_upgrade/test.sh b/src/bin/pg_upgrade/test.sh
index 04aa7fd9f5..9733217535 100644
--- a/src/bin/pg_upgrade/test.sh
+++ b/src/bin/pg_upgrade/test.sh
@@ -23,7 +23,7 @@ standard_initdb() {
 	# To increase coverage of non-standard segment size and group access
 	# without increasing test runtime, run these tests with a custom setting.
 	# Also, specify "-A trust" explicitly to suppress initdb's warning.
-	"$1" -N --wal-segsize 1 -g -A trust
+	"$1" -N -A trust
 	if [ -n "$TEMP_CONFIG" -a -r "$TEMP_CONFIG" ]
 	then
 		cat "$TEMP_CONFIG" >> "$PGDATA/postgresql.conf"
@@ -108,6 +108,9 @@ export EXTRA_REGRESS_OPTS
 mkdir "$outputdir"
 mkdir "$outputdir"/testtablespace
 
+mkdir "$outputdir"/sql
+mkdir "$outputdir"/expected
+
 logdir=`pwd`/log
 rm -rf "$logdir"
 mkdir "$logdir"
@@ -172,16 +175,83 @@ if "$MAKE" -C "$oldsrc" installcheck-parallel; then
 		fix_sql=""
 		case $oldpgversion in
 			804??)
-				fix_sql="DROP FUNCTION public.myfunc(integer); DROP FUNCTION public.oldstyle_length(integer, text);"
+				fix_sql="$fix_sql DROP FUNCTION public.myfunc(integer);"
 				;;
-			*)
-				fix_sql="DROP FUNCTION public.oldstyle_length(integer, text);"
+		esac
+
+		# Removed in v10 commit 5ded4bd21
+		case $oldpgversion in
+			804??|9????)
+				fix_sql="$fix_sql DROP FUNCTION public.oldstyle_length(integer, text);"
+				;;
+		esac
+
+		# commit 068503c76511cdb0080bab689662a20e86b9c845
+		case $oldpgversion in
+			10????) # XXX
+				fix_sql="$fix_sql DROP TRANSFORM FOR integer LANGUAGE sql CASCADE;"
+				;;
+		esac
+
+		# commit db3af9feb19f39827e916145f88fa5eca3130cb2
+		case $oldpgversion in
+			10????) # XXX
+				fix_sql="$fix_sql DROP FUNCTION boxarea(box);"
+				fix_sql="$fix_sql DROP FUNCTION funny_dup17();"
 				;;
 		esac
+
+		# commit cda6a8d01d391eab45c4b3e0043a1b2b31072f5f
+		case $oldpgversion in
+			10????) # XXX
+				fix_sql="$fix_sql DROP TABLE abstime_tbl;"
+				fix_sql="$fix_sql DROP TABLE reltime_tbl;"
+				fix_sql="$fix_sql DROP TABLE tinterval_tbl;"
+				;;
+		esac
+
+		# Various things removed for v14
+		case $oldpgversion in
+			804??|9????|10????|11????|12????|13????)
+				# commit 76f412ab3
+				# This one is only needed for v11+ ??
+				# (see below for more operators removed that also apply to older versions)
+				fix_sql="$fix_sql DROP OPERATOR public.!=- (pg_catalog.int8, NONE);"
+				;;
+		esac
+		case $oldpgversion in
+			804??|9????|10????|11????|12????|13????)
+				# commit 76f412ab3
+				fix_sql="$fix_sql DROP OPERATOR public.#@# (pg_catalog.int8, NONE);"
+				fix_sql="$fix_sql DROP OPERATOR public.#%# (pg_catalog.int8, NONE);"
+				fix_sql="$fix_sql DROP OPERATOR public.#@%# (pg_catalog.int8, NONE);"
+
+				# commit 9e38c2bb5 and 97f73a978
+				# fix_sql="$fix_sql DROP AGGREGATE array_larger_accum(anyarray);"
+				fix_sql="$fix_sql DROP AGGREGATE array_cat_accum(anyarray);"
+				fix_sql="$fix_sql DROP AGGREGATE first_el_agg_any(anyelement);"
+
+				# commit 76f412ab3
+				#fix_sql="$fix_sql DROP OPERATOR @#@(bigint,NONE);"
+				fix_sql="$fix_sql DROP OPERATOR @#@(NONE,bigint);"
+				;;
+		esac
+
+		# commit 578b22971: OIDS removed in v12
+		case $oldpgversion in
+			804??|9????|10????|11????)
+				fix_sql="$fix_sql ALTER TABLE public.tenk1 SET WITHOUT OIDS;"
+				fix_sql="$fix_sql ALTER TABLE public.tenk1 SET WITHOUT OIDS;"
+				#fix_sql="$fix_sql ALTER TABLE public.stud_emp SET WITHOUT OIDS;" # inherited
+				fix_sql="$fix_sql ALTER TABLE public.emp SET WITHOUT OIDS;"
+				fix_sql="$fix_sql ALTER TABLE public.tt7 SET WITHOUT OIDS;"
+				;;
+		esac
+
 		psql -X -d regression -c "$fix_sql;" || psql_fix_sql_status=$?
 	fi
 
-	pg_dumpall --no-sync -f "$temp_root"/dump1.sql || pg_dumpall1_status=$?
+	pg_dumpall --extra-float-digits=0 --no-sync -f "$temp_root"/dump1.sql || pg_dumpall1_status=$?
 
 	if [ "$newsrc" != "$oldsrc" ]; then
 		# update references to old source tree's regress.so etc
@@ -227,23 +297,29 @@ pg_upgrade $PG_UPGRADE_OPTS -d "${PGDATA}.old" -D "$PGDATA" -b "$oldbindir" -p "
 # Windows hosts don't support Unix-y permissions.
 case $testhost in
 	MINGW*) ;;
-	*)	if [ `find "$PGDATA" -type f ! -perm 640 | wc -l` -ne 0 ]; then
+	*)
+		x=`find "$PGDATA" -type f -perm /127 -ls`
+		if [ -n "$x" ]; then
 			echo "files in PGDATA with permission != 640";
+			echo "$x" |head
 			exit 1;
 		fi ;;
 esac
 
 case $testhost in
 	MINGW*) ;;
-	*)	if [ `find "$PGDATA" -type d ! -perm 750 | wc -l` -ne 0 ]; then
+	*)
+		x=`find "$PGDATA" -type d -perm /027 -ls`
+		if [ "$x" ]; then
 			echo "directories in PGDATA with permission != 750";
+			echo "$x" |head
 			exit 1;
 		fi ;;
 esac
 
 pg_ctl start -l "$logdir/postmaster2.log" -o "$POSTMASTER_OPTS" -w
 
-pg_dumpall --no-sync -f "$temp_root"/dump2.sql || pg_dumpall2_status=$?
+pg_dumpall --extra-float-digits=0 --no-sync -f "$temp_root"/dump2.sql || pg_dumpall2_status=$?
 pg_ctl -m fast stop
 
 if [ -n "$pg_dumpall2_status" ]; then
-- 
2.17.0

