diff --git a/README.md b/README.md index de6da4e..d5906ba 100644 --- a/README.md +++ b/README.md @@ -9,5 +9,5 @@ docker run --rm --name testdb -u 1000 -e POSTGRES_PASSWORD=password -v $(pwd)/te Perform the migration: ```bash -./build.sh && docker run -u 1000 -v $(pwd)/test-db:/db --rm -it pierre42100/postgresmig:16to17 +./build.sh && docker run -u 1000 -e POSTGRES_PASSWORD=password -v $(pwd)/test-db:/db --rm -it pierre42100/postgresmig:16to17 ``` \ No newline at end of file diff --git a/migrate.sh b/migrate.sh index ad8b846..2acd0cc 100644 --- a/migrate.sh +++ b/migrate.sh @@ -3,26 +3,29 @@ echo Migrate PostgreSQL version DB_PATH=/db OLD_DB_PATH=/tmp/old_db +NEW_DB_PATH=/tmp/new_db + +DB_PWD_FILE=/tmp/db_pwd_file + +# Handle password +if [ -z "$POSTGRES_PASSWORD" ] || [ "$POSTGRES_PASSWORD" == " " ]; +then + echo "Please specify database password in POSTGRES_PASSWORD env variable!" + exit 1; +fi +echo "$POSTGRES_PASSWORD" > "$DB_PWD_FILE" +truncate -s -1 "$DB_PWD_FILE" # Run database on a COPY of the database cp -r "$DB_PATH" "$OLD_DB_PATH" -# Start the database in the background -/postgres/16/bin/postgres -D /tmp/old_db/ & - -while true; -do - echo Waiting for database... - if echo "\q" | /postgres/16/bin/psql -U "$POSTGRES_USER"; - then - break - fi -done - -# Perform dump +# Initialize NEW database +mkdir "$NEW_DB_PATH" +/postgres/17/bin/initdb -D "$NEW_DB_PATH" --username "$POSTGRES_USER" --pwfile="$DB_PWD_FILE" || exit 1 -# Stop database -#pkill postgres +# Perform migration +cd /tmp +/postgres/17/bin/pg_upgrade -b /postgres/16/bin/ -d "$OLD_DB_PATH" -D "$NEW_DB_PATH" -U "$POSTGRES_USER" || exit 2 -bash \ No newline at end of file +# TODO: replace database \ No newline at end of file