mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-10-30 17:20:02 +00:00
Switch PostgreSQL container to use pgautoupgrade (#4892)
* Switch PostgreSQL container to use pgautoupgrade This handles automatically upgrading the data files to newer versions of PostgreSQL. * Fixing other uses of postgres:16-alpine image. * Simplifying upgrade scripts. --------- Co-authored-by: Dessalines <tyhou13@gmx.com>
This commit is contained in:
parent
ba044c7d98
commit
8abbd56400
5 changed files with 8 additions and 82 deletions
|
@ -306,7 +306,7 @@ steps:
|
|||
|
||||
services:
|
||||
database:
|
||||
image: postgres:16-alpine
|
||||
image: pgautoupgrade/pgautoupgrade:16-alpine
|
||||
environment:
|
||||
POSTGRES_USER: lemmy
|
||||
POSTGRES_PASSWORD: password
|
||||
|
|
|
@ -97,7 +97,7 @@ services:
|
|||
logging: *default-logging
|
||||
|
||||
postgres:
|
||||
image: postgres:16-alpine
|
||||
image: pgautoupgrade/pgautoupgrade:16-alpine
|
||||
# this needs to match the database host in lemmy.hson
|
||||
# Tune your settings via
|
||||
# https://pgtune.leopard.in.ua/#/
|
||||
|
|
|
@ -20,7 +20,7 @@ x-lemmy-default: &lemmy-default
|
|||
restart: always
|
||||
|
||||
x-postgres-default: &postgres-default
|
||||
image: postgres:16-alpine
|
||||
image: pgautoupgrade/pgautoupgrade:16-alpine
|
||||
environment:
|
||||
- POSTGRES_USER=lemmy
|
||||
- POSTGRES_PASSWORD=password
|
||||
|
|
|
@ -1,48 +1,8 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
echo "Do not stop in the middle of this upgrade, wait until you see the message: Upgrade complete."
|
||||
|
||||
echo "Stopping lemmy and all services..."
|
||||
sudo docker-compose stop
|
||||
|
||||
echo "Make sure postgres is started..."
|
||||
sudo docker-compose up -d postgres
|
||||
sleep 20s
|
||||
|
||||
echo "Exporting the Database to 12_15.dump.sql ..."
|
||||
sudo docker-compose exec -T postgres pg_dumpall -c -U lemmy > 12_15_dump.sql
|
||||
echo "Done."
|
||||
|
||||
echo "Stopping postgres..."
|
||||
sudo docker-compose stop postgres
|
||||
sleep 20s
|
||||
|
||||
echo "Removing the old postgres folder"
|
||||
sudo rm -rf volumes/postgres
|
||||
|
||||
echo "Updating docker-compose to use postgres version 15."
|
||||
sed -i "s/image: postgres:.*/image: postgres:15-alpine/" ./docker-compose.yml
|
||||
|
||||
echo "Starting up new postgres..."
|
||||
sudo docker-compose up -d postgres
|
||||
sleep 20s
|
||||
|
||||
echo "Importing the database...."
|
||||
cat 12_15_dump.sql | sudo docker-compose exec -T postgres psql -U lemmy
|
||||
echo "Done."
|
||||
|
||||
POSTGRES_PASSWORD=$(grep "POSTGRES_PASSWORD" ./docker-compose.yml | cut -d"=" -f2)
|
||||
|
||||
echo "Fixing a weird password issue with postgres 15"
|
||||
sudo docker-compose exec -T postgres psql -U lemmy -c "alter user lemmy with password '$POSTGRES_PASSWORD'"
|
||||
sudo docker-compose restart postgres
|
||||
|
||||
echo "Setting correct perms for pictrs folder"
|
||||
sudo chown -R 991:991 volumes/pictrs
|
||||
echo "Updating docker-compose to use postgres version 16."
|
||||
sudo sed -i "s/image: .*postgres:.*/image: pgautoupgrade\/pgautoupgrade:16-alpine/" ./docker-compose.yml
|
||||
|
||||
echo "Starting up lemmy..."
|
||||
sudo docker-compose up -d
|
||||
|
||||
echo "A copy of your old database is at 12_15.dump.sql . You can delete this file if the upgrade went smoothly."
|
||||
echo "Upgrade complete."
|
||||
|
|
|
@ -1,42 +1,8 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
echo "Do not stop in the middle of this upgrade, wait until you see the message: Upgrade complete."
|
||||
|
||||
echo "Stopping lemmy and all services..."
|
||||
sudo docker compose stop
|
||||
|
||||
echo "Make sure postgres is started..."
|
||||
sudo docker compose up -d postgres
|
||||
echo "Waiting..."
|
||||
sleep 20s
|
||||
|
||||
echo "Exporting the Database to 15_16.dump.sql ..."
|
||||
sudo docker compose exec -T postgres pg_dumpall -c -U lemmy | sudo tee 15_16_dump.sql > /dev/null
|
||||
echo "Done."
|
||||
|
||||
echo "Stopping postgres..."
|
||||
sudo docker compose stop postgres
|
||||
echo "Waiting..."
|
||||
sleep 20s
|
||||
|
||||
echo "Removing the old postgres folder"
|
||||
sudo rm -rf volumes/postgres
|
||||
|
||||
echo "Updating docker compose to use postgres version 16."
|
||||
sudo sed -i "s/image: .*postgres:.*/image: docker.io\/postgres:16-alpine/" ./docker-compose.yml
|
||||
|
||||
echo "Starting up new postgres..."
|
||||
sudo docker compose up -d postgres
|
||||
echo "Waiting..."
|
||||
sleep 20s
|
||||
|
||||
echo "Importing the database...."
|
||||
sudo cat 15_16_dump.sql | sudo docker compose exec -T postgres psql -U lemmy
|
||||
echo "Done."
|
||||
echo "Updating docker-compose to use postgres version 16."
|
||||
sudo sed -i "s/image: .*postgres:.*/image: pgautoupgrade\/pgautoupgrade:16-alpine/" ./docker-compose.yml
|
||||
|
||||
echo "Starting up lemmy..."
|
||||
sudo docker compose up -d
|
||||
|
||||
echo "A copy of your old database is at 15_16.dump.sql . You can delete this file if the upgrade went smoothly."
|
||||
echo "Upgrade complete."
|
||||
sudo docker-compose up -d
|
||||
|
|
Loading…
Reference in a new issue