2016-12-24 04:15:24 +03:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-02-06 04:14:06 +03:00
|
|
|
set -e -x
|
2016-12-24 04:15:24 +03:00
|
|
|
|
|
|
|
# Prepare the test databases in Travis CI.
|
2017-02-06 04:14:06 +03:00
|
|
|
#
|
2016-12-24 04:15:24 +03:00
|
|
|
# The script should be run with sudo.
|
|
|
|
# The script is not idempotent: it assumes the machine in a clean state
|
|
|
|
# and is designed for a sudo-enabled Trusty environment.
|
2017-02-06 04:14:06 +03:00
|
|
|
#
|
|
|
|
# The variables TEST_PAST, TEST_FUTURE, DONT_TEST_PRESENT can be used to test
|
|
|
|
# against unsupported Postgres versions and skip tests with supported ones.
|
|
|
|
#
|
|
|
|
# The variables can be set in the travis configuration
|
|
|
|
# (https://travis-ci.org/psycopg/psycopg2/settings)
|
2016-12-24 04:15:24 +03:00
|
|
|
|
|
|
|
set_param () {
|
|
|
|
# Set a parameter in a postgresql.conf file
|
2017-02-06 04:14:06 +03:00
|
|
|
param=$1
|
|
|
|
value=$2
|
2016-12-24 04:15:24 +03:00
|
|
|
|
2017-02-06 04:14:06 +03:00
|
|
|
sed -i "s/^\s*#\?\s*$param.*/$param = $value/" "$DATADIR/postgresql.conf"
|
2016-12-24 04:15:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
create () {
|
2017-02-06 04:14:06 +03:00
|
|
|
export VERSION=$1
|
|
|
|
export PACKAGE=${2:-$VERSION}
|
2016-12-24 04:15:24 +03:00
|
|
|
|
2017-06-08 20:45:07 +03:00
|
|
|
# Version as number: 9.6 -> 906; 11 -> 1100
|
|
|
|
export VERNUM=$(echo $VERSION \
|
|
|
|
| sed 's/\([0-9]\+\)\(\.\([0-9]\+\)\)\?/100 * \1 + 0\3/' | bc)
|
2017-02-06 04:14:06 +03:00
|
|
|
|
|
|
|
# Port number: 9.6 -> 50906
|
|
|
|
export PORT=$(( 50000 + $VERNUM ))
|
|
|
|
|
|
|
|
export DATADIR="/var/lib/postgresql/$PACKAGE/psycopg"
|
|
|
|
export PGDIR="/usr/lib/postgresql/$PACKAGE"
|
|
|
|
export PGBIN="$PGDIR/bin"
|
|
|
|
|
|
|
|
# install postgres versions not available on the image
|
2018-06-28 16:28:50 +03:00
|
|
|
if [[ ! -d "${PGDIR}" ]]; then
|
2019-10-19 15:22:19 +03:00
|
|
|
if (( "$VERNUM" >= 904 )); then
|
|
|
|
# A versiou supported by postgres
|
|
|
|
if [[ ! "${apt_updated:-}" ]]; then
|
|
|
|
apt_updated="yeah"
|
|
|
|
sudo apt-get update -y
|
|
|
|
fi
|
|
|
|
sudo apt-get install -y \
|
|
|
|
postgresql-server-dev-${VERSION} postgresql-${VERSION}
|
|
|
|
else
|
|
|
|
# A dinosaur
|
|
|
|
wget -O - \
|
|
|
|
http://initd.org/psycopg/upload/postgresql/postgresql-${PACKAGE}-$(lsb_release -cs).tar.bz2 \
|
|
|
|
| sudo tar xjf - -C /usr/lib/postgresql
|
|
|
|
fi
|
2017-02-06 04:14:06 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
sudo -u postgres "$PGBIN/initdb" -D "$DATADIR"
|
|
|
|
|
|
|
|
set_param port "$PORT"
|
|
|
|
if (( "$VERNUM" >= 800 )); then
|
|
|
|
set_param listen_addresses "'*'"
|
|
|
|
else
|
|
|
|
set_param tcpip_socket true
|
|
|
|
fi
|
2016-12-25 19:49:58 +03:00
|
|
|
|
|
|
|
# for two-phase commit testing
|
2017-02-06 04:14:06 +03:00
|
|
|
if (( "$VERNUM" >= 801 )); then set_param max_prepared_transactions 10; fi
|
2016-12-25 19:49:58 +03:00
|
|
|
|
|
|
|
# for replication testing
|
2017-02-06 04:14:06 +03:00
|
|
|
if (( "$VERNUM" >= 900 )); then set_param max_wal_senders 5; fi
|
|
|
|
if (( "$VERNUM" >= 904 )); then set_param max_replication_slots 5; fi
|
|
|
|
|
|
|
|
if (( "$VERNUM" >= 904 )); then
|
|
|
|
set_param wal_level logical
|
|
|
|
elif (( "$VERNUM" >= 900 )); then
|
|
|
|
set_param wal_level hot_standby
|
|
|
|
fi
|
|
|
|
|
|
|
|
if (( "$VERNUM" >= 900 )); then
|
|
|
|
echo "host replication travis 0.0.0.0/0 trust" >> "$DATADIR/pg_hba.conf"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# start the server, wait for start
|
|
|
|
sudo -u postgres "$PGBIN/pg_ctl" -w -l /dev/null -D "$DATADIR" start
|
|
|
|
|
|
|
|
# create the test database
|
|
|
|
DBNAME=psycopg2_test
|
|
|
|
CONNINFO="user=postgres host=localhost port=$PORT dbname=template1"
|
|
|
|
|
|
|
|
if (( "$VERNUM" >= 901 )); then
|
|
|
|
psql -c "create user travis createdb createrole replication" "$CONNINFO"
|
|
|
|
elif (( "$VERNUM" >= 801 )); then
|
|
|
|
psql -c "create user travis createdb createrole" "$CONNINFO"
|
2016-12-25 19:49:58 +03:00
|
|
|
else
|
2017-02-06 04:14:06 +03:00
|
|
|
psql -c "create user travis createdb createuser" "$CONNINFO"
|
2016-12-25 19:49:58 +03:00
|
|
|
fi
|
|
|
|
|
2017-02-06 04:14:06 +03:00
|
|
|
psql -c "create database $DBNAME with owner travis" "$CONNINFO"
|
2016-12-25 19:49:58 +03:00
|
|
|
|
2017-02-06 04:14:06 +03:00
|
|
|
# configure global objects on the test database
|
|
|
|
CONNINFO="user=postgres host=localhost port=$PORT dbname=$DBNAME"
|
2016-12-25 19:49:58 +03:00
|
|
|
|
2017-02-06 04:14:06 +03:00
|
|
|
if (( "$VERNUM" >= 901 )); then
|
|
|
|
psql -c "create extension hstore" "$CONNINFO"
|
|
|
|
elif (( "$VERNUM" >= 803 )); then
|
|
|
|
psql -f "$PGDIR/share/contrib/hstore.sql" "$CONNINFO"
|
|
|
|
fi
|
2016-12-24 04:15:24 +03:00
|
|
|
|
2017-02-06 04:14:06 +03:00
|
|
|
if (( "$VERNUM" == 901 )); then
|
|
|
|
psql -c "create extension json" "$CONNINFO"
|
|
|
|
fi
|
2016-12-24 04:15:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# Would give a permission denied error in the travis build dir
|
|
|
|
cd /
|
|
|
|
|
2017-02-06 04:14:06 +03:00
|
|
|
# Postgres versions supported by Travis CI
|
2019-10-19 15:49:27 +03:00
|
|
|
if (( ! "$DONT_TEST_PRESENT" )); then
|
2019-10-19 15:08:29 +03:00
|
|
|
create 12
|
|
|
|
create 11
|
2017-10-19 01:02:08 +03:00
|
|
|
create 10
|
2017-02-06 04:14:06 +03:00
|
|
|
create 9.6
|
|
|
|
create 9.5
|
|
|
|
create 9.4
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Unsupported postgres versions that we still support
|
|
|
|
# Images built by https://github.com/psycopg/psycopg2-wheels/tree/build-dinosaurs
|
2019-10-19 15:49:27 +03:00
|
|
|
if (( "$TEST_PAST" )); then
|
2017-02-06 04:14:06 +03:00
|
|
|
create 7.4
|
|
|
|
create 8.0
|
|
|
|
create 8.1
|
|
|
|
create 8.2
|
|
|
|
create 8.3
|
|
|
|
create 8.4
|
|
|
|
create 9.0
|
|
|
|
create 9.1
|
2017-10-19 01:02:08 +03:00
|
|
|
create 9.2
|
2018-06-28 16:28:50 +03:00
|
|
|
create 9.3
|
2017-02-06 04:14:06 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Postgres built from master
|
2019-10-19 15:49:27 +03:00
|
|
|
if (( "$TEST_FUTURE" )); then
|
2019-10-19 15:08:29 +03:00
|
|
|
create 13 13-master
|
2017-02-06 04:14:06 +03:00
|
|
|
fi
|