1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
|
#!/bin/sh
EXIT_ON_FIRST_FAILURE=0
EXTDIR=`pg_config --sharedir`/extension/
CTBDIR=`pg_config --sharedir`/contrib/
TMPDIR=/tmp/check_all_upgrades-$$-tmp
PGVER=`pg_config --version | awk '{print $2}'`
PGVER_MAJOR=$(echo "${PGVER}" | sed 's/\.[^\.]*//' | sed 's/\(alpha\|beta\|rc\).*//' )
SKIP_LABEL_REGEXP=
echo "INFO: PostgreSQL version: ${PGVER} [${PGVER_MAJOR}]"
MAKE=$(which gmake make | head -1)
BUILDDIR=$PWD # TODO: allow override ?
cd $(dirname $0)/..
SRCDIR=$PWD # TODO: allow override ?
cd - > /dev/null
# This is useful to run database queries
export PGDATABASE=template1
usage() {
echo "Usage: $0 [-s] <to_version>"
echo "Options:"
echo "\t-s Stop on first failure"
echo "\t--skip <regexp> Do not run tests with label matching given extended regexp"
}
while test -n "$1"; do
if test "$1" = "-s"; then
EXIT_ON_FIRST_FAILURE=1
elif test "$1" = "--skip"; then
shift
SKIP_LABEL_REGEXP=$1
elif test -z "$to_version_param"; then
to_version_param="$1"
else
usage >&2
exit 1
fi
shift
done
if test -z "$to_version_param"; then
usage >&2
exit 1
fi
mkdir -p ${TMPDIR}
cleanup()
{
echo "Cleaning up"
rm -rf ${TMPDIR}
}
trap 'cleanup' EXIT
# Return -1, 1 or 0 if the first version
# is respectively smaller, greater or equal
# to the second version
semver_compare()
{
V1=`echo "$1" | tr '.' ' '`
V2=$2
# echo "V1: $V1" >&2
# echo "V2: $V2" >&2
for v1 in $V1; do
v2=`echo "$V2" | cut -d. -f1`
if [ -z "$v2" ]; then
echo 1; return;
fi
V2=`echo "$V2" | cut -d. -sf2-`
# echo "v: $v1 - $v2" >&2
if expr "$v1" '<' "$v2" > /dev/null; then
echo -1; return;
fi
if expr "$v1" '>' "$v2" > /dev/null; then
echo 1; return;
fi
done
if [ -n "$V2" ]; then
echo -1; return;
fi
echo 0; return;
}
failed()
{
failures=$((failures+1))
if test $EXIT_ON_FIRST_FAILURE != 0; then
exit $failures
fi
}
minimum_postgis_version_for_postgresql_major_version()
{
pgver=$1
supportfile=${TMPDIR}/minimum_supported_version_for_postgresql
if ! test -e ${supportfile}; then
# Source: https://trac.osgeo.org/postgis/wiki/UsersWikiPostgreSQLPostGIS
cat > ${supportfile} <<EOF
9.6:2.3
10:2.4
11:2.5
12:2.5
13:3.0
14:3.1
15:3.2
16:3.3
17:3.3
EOF
fi
# Drop patch-level number from PostgreSQL version
minsupported=`grep ^${pgver}: ${supportfile} | cut -d: -f2`
test -n "${minsupported}" || {
echo "Cannot determine minimum supported PostGIS version for PostgreSQL major version ${pgver}" >&2
exit 1
}
echo "${minsupported}"
}
kept_label()
{
label=$1
if test -n "${SKIP_LABEL_REGEXP}"; then
if echo "${label}" | egrep -q "${SKIP_LABEL_REGEXP}"; then
echo "SKIP: $label (matches regexp '${SKIP_LABEL_REGEXP}')"
return 1;
fi
fi
return 0;
}
compatible_upgrade()
{
label=$1
from=$2
to=$3
#echo "XXXX compatible_upgrade: upgrade_path=${upgrade_path}"
#echo "XXXX compatible_upgrade: from=${from}"
#echo "XXXX compatible_upgrade: to=${to}"
# only consider versions older than ${to}
cmp=`semver_compare "${from}" "${to}"`
#echo "INFO: semver_compare ${from} ${to} returned $cmp"
if test $cmp -ge 0; then
echo "SKIP: $label ($to is not newer than $from)"
return 1
fi
cmp=`semver_compare "${PGIS_MIN_VERSION}" "${from}"`
if test $cmp -gt 0; then
echo "SKIP: $label ($from older than ${PGIS_MIN_VERSION}, which is required to run in PostgreSQL ${PGVER})"
return 1
fi
return 0
}
report_missing_versions()
{
if test -n "${MISSING_EXT_UPGRADES}"; then
echo "INFO: missing upgrade scripts: ${MISSING_EXT_UPGRADES}"
echo "HINT: use 'postgis install-extension-upgrades' to install them"
fi
cleanup
}
to_version=$to_version_param
if expr $to_version : ':auto' >/dev/null; then
to_version=`psql -XAtc "select default_version from pg_available_extensions where name = 'postgis'"` || exit 1
MISSING_EXT_UPGRADES=
trap report_missing_versions EXIT
elif expr $to_version : '.*!$' >/dev/null; then
to_version=$(echo "${to_version}" | sed 's/\!$//')
fi
PGIS_MIN_VERSION=`minimum_postgis_version_for_postgresql_major_version "${PGVER_MAJOR}"`
echo "INFO: minimum PostGIS version supporting PostgreSQL ${PGVER_MAJOR}: ${PGIS_MIN_VERSION}"
cd $EXTDIR
failures=0
INSTALLED_EXTENSIONS=postgis
if test -f postgis_topology--${to_version}.sql; then
INSTALLED_EXTENSIONS="$INSTALLED_EXTENSIONS postgis_topology"
fi
if test -f postgis_raster--${to_version}.sql; then
INSTALLED_EXTENSIONS="$INSTALLED_EXTENSIONS postgis_raster"
fi
if test -f postgis_sfcgal--${to_version}.sql; then
INSTALLED_EXTENSIONS="$INSTALLED_EXTENSIONS postgis_sfcgal"
fi
echo "INFO: installed extensions: $INSTALLED_EXTENSIONS"
USERTESTFLAGS=${RUNTESTFLAGS}
# Make use of all public functions defined by source version
# and use double-upgrade
USERTESTFLAGS="\
${USERTESTFLAGS} \
--before-upgrade-script ${SRCDIR}/regress/hooks/use-all-functions.sql \
--after-upgrade-script ${SRCDIR}/regress/hooks/hook-after-upgrade.sql \
"
for EXT in ${INSTALLED_EXTENSIONS}; do #{
if test "${EXT}" = "postgis"; then
REGDIR=${BUILDDIR}/regress
elif test "${EXT}" = "postgis_topology"; then
REGDIR=${BUILDDIR}/topology/test
elif test "${EXT}" = "postgis_raster"; then
REGDIR=${BUILDDIR}/raster/test/regress
elif test "${EXT}" = "postgis_sfcgal"; then
REGDIR=${BUILDDIR}/sfcgal/regress
else
echo "SKIP: don't know where to find regress tests for extension ${EXT}"
fi
# Check extension->extension upgrades
files=`'ls' ${EXT}--* | grep -v -- '--.*--' | sed "s/^${EXT}--\(.*\)\.sql/\1/"`
for fname in $files; do
from_version="$fname"
if test "$from_version" = "unpackaged"; then
# We deal with unpackaged tests separately
continue;
fi
UPGRADE_PATH="${from_version}--${to_version_param}"
test_label="${EXT} extension upgrade ${UPGRADE_PATH}"
if expr $to_version_param : ':auto' >/dev/null; then
test_label="${test_label} ($to_version)"
fi
kept_label "${test_label}" || continue
compatible_upgrade "${test_label}" ${from_version} ${to_version} || continue
path=$( psql -XAtc "
SELECT path
FROM pg_catalog.pg_extension_update_paths('${EXT}')
WHERE source = '${from_version}'
AND target = '${to_version}'
" ) || exit 1
if test -z "${path}"; then
echo "SKIP: ${test_label} (no upgrade path from ${from_version} to ${to_version} known by postgresql)"
MISSING_EXT_UPGRADES="${from_version} ${MISSING_EXT_UPGRADES}"
continue
fi
echo "Testing ${test_label}"
RUNTESTFLAGS="-v --extension --upgrade-path=${UPGRADE_PATH} ${USERTESTFLAGS}" \
${MAKE} -C ${REGDIR} check ${MAKE_ARGS} && {
echo "PASS: ${test_label}"
} || {
echo "FAIL: ${test_label}"
failed
}
done
if ! kept_label "unpackaged"; then
echo "SKIP: ${EXT} script-based upgrades (disabled by commandline)"
continue;
fi
# Check unpackaged->extension upgrades
for majmin in `'ls' -d ${CTBDIR}/postgis-* | sed 's/.*postgis-//'`; do
UPGRADE_PATH="unpackaged${majmin}--${to_version_param}"
test_label="${EXT} extension upgrade ${UPGRADE_PATH}"
if expr $to_version_param : ':auto' >/dev/null; then
test_label="${test_label} ($to_version)"
fi
kept_label "${test_label}" || continue
compatible_upgrade "${test_label}" ${majmin} ${to_version} || continue
path=$( psql -XAtc "
SELECT path
FROM pg_catalog.pg_extension_update_paths('${EXT}')
WHERE source = 'unpackaged'
AND target = '${to_version}'
" ) || exit 1
if test -z "${path}"; then
echo "SKIP: ${test_label} (no upgrade path from unpackaged to ${to_version} known by postgresql)"
continue
fi
echo "Testing ${test_label}"
RUNTESTFLAGS="-v --extension --upgrade-path=${UPGRADE_PATH} ${USERTESTFLAGS}" \
${MAKE} -C ${REGDIR} check ${MAKE_ARGS} && {
echo "PASS: ${test_label}"
} || {
echo "FAIL: ${test_label}"
failed
}
done
# Check unpackaged->unpackaged upgrades (if target version == current version)
# CURRENTVERSION=`grep '^POSTGIS_' ${SRCDIR}/Version.config | cut -d= -f2 | paste -sd '.'`
CURRENTVERSION=$(grep '^POSTGIS_' ${SRCDIR}/Version.config | cut -d= -f2 | tr '\n' '.')
if test "${to_version}" != "${CURRENTVERSION}"; then #{
echo "SKIP: ${EXT} script-based upgrades (${to_version_param} [${to_version}] does not match built version ${CURRENTVERSION})"
continue
fi #}
for majmin in `'ls' -d ${CTBDIR}/postgis-* | sed 's/.*postgis-//'`
do #{
UPGRADE_PATH="unpackaged${majmin}--:auto"
test_label="${EXT} script soft upgrade ${UPGRADE_PATH}"
if expr $to_version_param : ':auto' >/dev/null; then
test_label="${test_label} ($to_version)"
fi
compatible_upgrade "${test_label}" ${majmin} ${to_version} || continue
if kept_label "${test_label}"; then #{
echo "Testing ${test_label}"
RUNTESTFLAGS="-v --upgrade-path=${UPGRADE_PATH} ${USERTESTFLAGS}" \
${MAKE} -C ${REGDIR} check ${MAKE_ARGS} && {
echo "PASS: ${test_label}"
} || {
echo "FAIL: ${test_label}"
failed
}
fi #}
test_label="${EXT} script hard upgrade ${UPGRADE_PATH}"
if kept_label "${test_label}"; then #{
echo "Testing ${test_label}"
RUNTESTFLAGS="-v --dumprestore --upgrade-path=${UPGRADE_PATH} ${USERTESTFLAGS}" \
${MAKE} -C ${REGDIR} check ${MAKE_ARGS} && {
echo "PASS: ${test_label}"
} || {
echo "FAIL: ${test_label}"
failed
}
fi #}
done #}
done #}
exit $failures
|