Skip to content

Commit 1d2c5fb

Browse files
committed
Phase 6b: structural comparison in pg-upgrade-test (both twin databases)
Adapts the intent of #35 (branched before pg-upgrade-test's twin-database redesign, now stale) to the current job shape: prepare-old/update/run-suite already loop bin/test_existing over count_nulls_upgrade_none (schema "") and count_nulls_upgrade_quoted (schema Quoted) sharing one binary pg_upgrade call. Adds an EXISTING_DB argument to bin/compare_fresh_vs_update so it can structurally diff an already-populated database (the real pg_upgraded one) against a fresh install, instead of only ever creating its own scratch "updated" database - then loops that comparison over both databases/schemas after run-suite, same as extension-update-test already does for its own in-place update leg.
1 parent dca71f7 commit 1d2c5fb

2 files changed

Lines changed: 46 additions & 9 deletions

File tree

.github/workflows/ci.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,20 @@ jobs:
337337
run: |
338338
bin/test_existing run-suite count_nulls_upgrade_none ""
339339
bin/test_existing run-suite count_nulls_upgrade_quoted Quoted
340+
- name: Structurally compare the pg_upgraded database against a fresh install, across every TEST_SCHEMA value
341+
# Same rationale as extension-update-test's own use of this tool (see
342+
# above), but here the "other side" is the REAL database a binary
343+
# pg_upgrade + ALTER EXTENSION UPDATE just produced, not a scratch
344+
# database this tool created itself - passed as EXISTING_DB so the
345+
# script queries it in place instead of re-deriving it. Catches a
346+
# divergence class the fixed pgTAP suite above doesn't: an object
347+
# left subtly different (body, comment, ACL) by surviving a real
348+
# catalog migration, as opposed to only an in-place update. Each
349+
# pg_upgraded database is compared against a fresh install in ITS
350+
# OWN schema, matching prepare-old above.
351+
run: |
352+
bin/compare_fresh_vs_update "" 0.9.6 count_nulls_upgrade_none
353+
bin/compare_fresh_vs_update Quoted 0.9.6 count_nulls_upgrade_quoted
340354
341355
# Fresh-install smoke test only, deliberately - NOT extended to the
342356
# update path. pgxntool 2.3.0's fix for installcheck's ordering bug

bin/compare_fresh_vs_update

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,50 @@
2727
# for the relevant catalog (pg_class for views, pg_type for types, ...) the
2828
# same way if count_nulls ever grows one.
2929
#
30-
# USAGE: bin/compare_fresh_vs_update [SCHEMA] [FROM_VERSION]
30+
# USAGE: bin/compare_fresh_vs_update [SCHEMA] [FROM_VERSION] [EXISTING_DB]
3131
# SCHEMA - schema both installs target (default: unqualified, same
3232
# as TEST_SCHEMA empty - see the Makefile). Both installs
3333
# use the SAME schema, since the point is comparing object
3434
# definitions, not exercising schema-qualification (that's
3535
# TEST_SCHEMA's job in the regular suite).
3636
# FROM_VERSION - the update origin (default: 0.9.6, the oldest version
3737
# count_nulls still ships a full install script for).
38+
# Ignored when EXISTING_DB is given - that database's
39+
# history is whatever already produced it.
40+
# EXISTING_DB - compare against this ALREADY-POPULATED database instead
41+
# of creating+updating a scratch one (default: none, create
42+
# our own scratch "updated" database as before). Lets
43+
# callers that produced their update/upgrade result some
44+
# other way - e.g. bin/test_existing's real binary
45+
# pg_upgrade path - reuse this same comparison without this
46+
# script re-deriving that database itself. The caller owns
47+
# EXISTING_DB's lifecycle: it is never created, updated, or
48+
# dropped here, only queried.
3849
#
3950
# Exits nonzero (and prints a real diff) on ANY difference. Scratch
40-
# databases are dropped on exit regardless of outcome.
51+
# database(s) this script created itself are dropped on exit regardless of
52+
# outcome; an EXISTING_DB passed in is left untouched.
4153
set -euo pipefail
4254

4355
cd "$(dirname "$(readlink -f "$0")")/.."
4456

4557
schema=${1:-}
4658
from_version=${2:-0.9.6}
59+
existing_db=${3:-}
4760

4861
fresh_db=compare_fresh_vs_update_fresh
49-
update_db=compare_fresh_vs_update_updated
62+
update_db=${existing_db:-compare_fresh_vs_update_updated}
5063
fresh_snapshot=$(mktemp)
5164
update_snapshot=$(mktemp)
5265

5366
cleanup() {
5467
dropdb --if-exists "$fresh_db"
55-
dropdb --if-exists "$update_db"
68+
# Only drop update_db if we created it ourselves - an EXISTING_DB belongs
69+
# to the caller (e.g. the real pg_upgraded database bin/test_existing is
70+
# still using) and must survive this script running.
71+
if [ -z "$existing_db" ]; then
72+
dropdb --if-exists "$update_db"
73+
fi
5674
rm -f "$fresh_snapshot" "$update_snapshot"
5775
}
5876
trap cleanup EXIT
@@ -88,16 +106,21 @@ install_in_schema() {
88106
createdb "$fresh_db"
89107
psql -d "$fresh_db" -v ON_ERROR_STOP=1 -c "$(install_in_schema)CREATE EXTENSION count_nulls"
90108

91-
createdb "$update_db"
92-
psql -d "$update_db" -v ON_ERROR_STOP=1 -c "$(install_in_schema)CREATE EXTENSION count_nulls VERSION '$from_version'"
93-
psql -d "$update_db" -v ON_ERROR_STOP=1 -c "SET client_min_messages = WARNING; ALTER EXTENSION count_nulls UPDATE"
109+
if [ -z "$existing_db" ]; then
110+
createdb "$update_db"
111+
psql -d "$update_db" -v ON_ERROR_STOP=1 -c "$(install_in_schema)CREATE EXTENSION count_nulls VERSION '$from_version'"
112+
psql -d "$update_db" -v ON_ERROR_STOP=1 -c "SET client_min_messages = WARNING; ALTER EXTENSION count_nulls UPDATE"
113+
fi
94114

95115
psql -d "$fresh_db" -tA -v ON_ERROR_STOP=1 -c "$(query)" > "$fresh_snapshot"
96116
psql -d "$update_db" -tA -v ON_ERROR_STOP=1 -c "$(query)" > "$update_snapshot"
97117

118+
source_desc="$from_version->current update"
119+
[ -n "$existing_db" ] && source_desc="'$existing_db'"
120+
98121
if diff -u "$fresh_snapshot" "$update_snapshot"; then
99-
echo "OK: fresh install and $from_version->current update produce IDENTICAL object definitions/comments/ACLs"
122+
echo "OK: fresh install and $source_desc produce IDENTICAL object definitions/comments/ACLs"
100123
else
101-
echo "FAIL: update path diverges from a fresh install of the same version - see diff above" >&2
124+
echo "FAIL: $source_desc diverges from a fresh install of the same version - see diff above" >&2
102125
exit 1
103126
fi

0 commit comments

Comments
 (0)