diff --git a/docker-compose.yml b/docker-compose.yml index 50c3ed37a..71e8f43d7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,8 +3,6 @@ services: image: postgres:16-alpine shm_size: 4gb restart: unless-stopped - env_file: - - .env environment: { # This might seem insecure but is usually not a problem. # You should leave this at the "akkoma" default. @@ -24,8 +22,6 @@ services: akkoma: image: akkoma/akkoma:latest restart: unless-stopped - env_file: - - .env links: - db ports: [ diff --git a/docker-resources/migrate-postgresql-version.sh b/docker-resources/migrate-postgresql-version.sh index 6cfa3cbd4..7d5015b2c 100755 --- a/docker-resources/migrate-postgresql-version.sh +++ b/docker-resources/migrate-postgresql-version.sh @@ -14,32 +14,67 @@ fi data_directory=$1 old_version=$2 new_version=$3 +new_data_directory=$data_directory.new + +# we'll need the credentials to create the new container +echo "Please provide the credentials for your database" +echo "If you set a different password for the old container, you'll need to provide it here! Check your config file if you're not sure" +echo "" + +echo "Database user (default 'akkoma'):" +read DB_USER +echo "Database password (default: 'akkoma'):" +read DB_PASS +echo "Database name (default: 'akkoma'):" +read DB_NAME + +echo "" +echo "Ok! Using user:$DB_USER to migrate db:$DB_NAME from version $old_version to $new_version" + +trap "docker stop pg$old_version pg$new_version" INT TERM # Start a PostgreSQL 14 container -docker run --rm -d --name pg14 -v $(pwd)/$data_directory:/var/lib/postgresql/data -e "POSTGRES_PASSWORD=password" postgres:$old_version-alpine +docker run --rm -d --name pg$old_version \ + -v $(pwd)/$data_directory:/var/lib/postgresql/data \ + -e "POSTGRES_PASSWORD=$DB_PASS" \ + -e "POSTGRES_USER=$DB_USER" \ + -e "POSTGRES_DB=$DB_NAME" \ + postgres:$old_version-alpine # wait a bit for the container to start sleep 10 # Dump the db from the old container -docker exec pg14 pg_dumpall -U postgres > dump.sql +echo "Dumping your old database..." + +docker exec pg$old_version pg_dumpall -U $DB_USER > dump.sql # Stop the old container -docker stop pg14 +echo "Stopping the old database..." +docker stop pg$old_version # Start a PostgreSQL 16 container -docker run --rm -d --name pg16 -v $(pwd)/$data_directory.new:/var/lib/postgresql/data -e "POSTGRES_PASSWORD=password" postgres:$new_version-alpine +echo "Creating a new database with version $new_version..." +docker run --rm -d --name pg$new_version \ + -v $(pwd)/$new_data_directory:/var/lib/postgresql/data \ + -e "POSTGRES_PASSWORD=password" \ + -e "POSTGRES_USER=$DB_USER" \ + -e "POSTGRES_DB=$DB_NAME" \ + postgres:$new_version-alpine + +# wait for it +sleep 10 # Load the db into the new container -docker exec -i pg16 psql -U postgres < dump.sql +docker exec -i pg$new_version psql -U $DB_USER < dump.sql # Stop the new container -docker stop pg16 +docker stop pg$new_version # Remove the dump file -rm dump.sql +# rm dump.sql echo "Migration complete! Your new database folder is $data_directory.new - you can now move your old data and replace it" echo "mv $data_directory $data_directory.old" -echo "mv $data_directory.new $data_directory" \ No newline at end of file +echo "mv $new_data_directory $data_directory" \ No newline at end of file