Skip to content

Commit

Permalink
migrate to Postgres 16
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeragamba committed May 27, 2024
1 parent 1f942be commit e54b72c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ vendor/
.env
.volumes/

.migrations/*.done

!/**/.keep
16 changes: 16 additions & 0 deletions .migrations/001_upgrade-postgres-16_down.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -e

OLD_DATA_VOL=./.volumes/database
NEW_DATA_VOL=./.volumes/db/pg16
source .env

# check if migration already applied
if [ ! -f .migrations/001.done ]; then
echo "Migration already rolledback, skipping"
exit 0
fi

sudo rm -rf $NEW_DATA_VOL

rm .migrations/001.done
26 changes: 26 additions & 0 deletions .migrations/001_upgrade-postgres-16_up.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -e

OLD_DATA_VOL=./.volumes/database
NEW_DATA_VOL=./.volumes/db/pg16
source .env

# check if migration already applied
if [ -f .migrations/001.done ]; then
echo "Migration already complete, skipping"
exit 0
fi

docker run --rm \
-v $OLD_DATA_VOL:/var/lib/postgresql/15/data \
-v $NEW_DATA_VOL:/var/lib/postgresql/16/data \
-e PGUSER=$DB_USER \
-e PGPASS=$DB_PASS \
-e POSTGRES_INITDB_ARGS="--username=$DB_USER" \
tianon/postgres-upgrade:15-to-16

docker compose run --rm \
db \
bash -c 'echo "host all all all md5" >> /var/lib/postgresql/data/pg_hba.conf'

touch .migrations/001.done
7 changes: 6 additions & 1 deletion deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ if [[ $CLIENT_CHANGED == "true" ]]; then
docker compose -f docker-compose.production.yml up client
fi

echo "--- Restarting containers ---"
echo "--- Stopping containers ---"
docker compose -f docker-compose.production.yml down

echo "--- Migrating data ---"
.migrations/001_upgrade-postgres-16_up.sh

echo "--- Starting containers ---"
docker compose -f docker-compose.production.yml up router -d

echo "=== All Done ==="
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.shared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ services:
CLIENT_DIR: "/opt/client"

db:
image: postgres:15
image: postgres:16
volumes:
- ./.volumes/database:/var/lib/postgresql/data:rw
- ./.volumes/db/pg16:/var/lib/postgresql/data:rw
environment:
POSTGRES_DB: "${DB_NAME}"
POSTGRES_USER: "${DB_USER}"
Expand Down

0 comments on commit e54b72c

Please sign in to comment.