|
27 | 27 | # for the relevant catalog (pg_class for views, pg_type for types, ...) the |
28 | 28 | # same way if count_nulls ever grows one. |
29 | 29 | # |
30 | | -# USAGE: bin/compare_fresh_vs_update [SCHEMA] [FROM_VERSION] |
| 30 | +# USAGE: bin/compare_fresh_vs_update [SCHEMA] [FROM_VERSION] [EXISTING_DB] |
31 | 31 | # SCHEMA - schema both installs target (default: unqualified, same |
32 | 32 | # as TEST_SCHEMA empty - see the Makefile). Both installs |
33 | 33 | # use the SAME schema, since the point is comparing object |
34 | 34 | # definitions, not exercising schema-qualification (that's |
35 | 35 | # TEST_SCHEMA's job in the regular suite). |
36 | 36 | # FROM_VERSION - the update origin (default: 0.9.6, the oldest version |
37 | 37 | # 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. |
38 | 49 | # |
39 | 50 | # 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. |
41 | 53 | set -euo pipefail |
42 | 54 |
|
43 | 55 | cd "$(dirname "$(readlink -f "$0")")/.." |
44 | 56 |
|
45 | 57 | schema=${1:-} |
46 | 58 | from_version=${2:-0.9.6} |
| 59 | +existing_db=${3:-} |
47 | 60 |
|
48 | 61 | 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} |
50 | 63 | fresh_snapshot=$(mktemp) |
51 | 64 | update_snapshot=$(mktemp) |
52 | 65 |
|
53 | 66 | cleanup() { |
54 | 67 | 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 |
56 | 74 | rm -f "$fresh_snapshot" "$update_snapshot" |
57 | 75 | } |
58 | 76 | trap cleanup EXIT |
@@ -88,16 +106,21 @@ install_in_schema() { |
88 | 106 | createdb "$fresh_db" |
89 | 107 | psql -d "$fresh_db" -v ON_ERROR_STOP=1 -c "$(install_in_schema)CREATE EXTENSION count_nulls" |
90 | 108 |
|
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 |
94 | 114 |
|
95 | 115 | psql -d "$fresh_db" -tA -v ON_ERROR_STOP=1 -c "$(query)" > "$fresh_snapshot" |
96 | 116 | psql -d "$update_db" -tA -v ON_ERROR_STOP=1 -c "$(query)" > "$update_snapshot" |
97 | 117 |
|
| 118 | +source_desc="$from_version->current update" |
| 119 | +[ -n "$existing_db" ] && source_desc="'$existing_db'" |
| 120 | + |
98 | 121 | 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" |
100 | 123 | 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 |
102 | 125 | exit 1 |
103 | 126 | fi |
0 commit comments