Skip to content

Commit ddabbe9

Browse files
authored
feat(postgres): Add auto upgrade from pg 9.5 to 9.6 (#283)
1 parent b461a75 commit ddabbe9

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

install.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,26 @@ if [ "$RAM_AVAILABLE_IN_DOCKER" -lt "$MIN_RAM" ]; then
5555
exit -1
5656
fi
5757

58+
# Very naively check whether there's an existing sentry-postgres volume and the PG version in it
59+
if [[ $(docker volume ls -q --filter name=sentry-postgres) && $(docker run --rm -v sentry-postgres:/db busybox cat /db/PG_VERSION 2>/dev/null) == "9.5" ]]; then
60+
# If this is Postgres 9.5 data, start upgrading it to 9.6 in a new volume
61+
docker run --rm \
62+
-v sentry-postgres:/var/lib/postgresql/9.5/data \
63+
-v sentry-postgres-new:/var/lib/postgresql/9.6/data \
64+
tianon/postgres-upgrade:9.5-to-9.6
65+
66+
# Get rid of the old volume as we'll rename the new one to that
67+
docker volume rm sentry-postgres
68+
docker volume create --name sentry-postgres
69+
# There's no rename volume in Docker so copy the contents from old to new name
70+
# Also append the `host all all all trust` line as `tianon/postgres-upgrade:9.5-to-9.6`
71+
# doesn't do that automatically.
72+
docker run --rm -it -v sentry-postgres-new:/from -v sentry-postgres:/to alpine ash -c \
73+
"cd /from ; cp -av . /to ; echo 'host all all all trust' >> /to/pg_hba.conf"
74+
# Finally, remove the new old volume as we are all in sentry-postgres now
75+
docker volume rm sentry-postgres-new
76+
fi
77+
5878
echo ""
5979
ensure_file_from_example $SENTRY_CONFIG_PY
6080
ensure_file_from_example $SENTRY_CONFIG_YML

0 commit comments

Comments
 (0)