@echo off

set POSTGRES_APP=psql
where %POSTGRES_APP%>nul
if %ERRORLEVEL% equ 0 goto enter_params

set /p "POSTGRES_APP_PATH=PostgreSQL client application is not found. Enter the path to application: "
if "%POSTGRES_APP_PATH%"=="" goto failed
set POSTGRES_APP=%POSTGRES_APP_PATH%

:enter_params
set /p DB_HOST="Enter database host ip [127.0.0.1]: "
if "%DB_HOST%"=="" set "DB_HOST=127.0.0.1"

:enter_port
set /p DB_PORT="Enter database port [5432]: "
if "%DB_PORT%"=="" set "DB_PORT=5432"

set /p PACS_USER="Enter postgres user name for PACS db scheme (existing user) [PACS_USER]: "
if "%PACS_USER%"=="" set "PACS_USER=PACS_USER"

set /p PACS_PASS="Enter password for user %PACS_USER%: "

set PGPASSWORD=%PACS_PASS%
%POSTGRES_APP% -U %PACS_USER% -h %DB_HOST% -p %DB_PORT% -d pacs -f "update_to_2.4.0.sql"
if ERRORLEVEL 1 goto failed

echo Updating database schema completed.
goto end

:failed
echo Updating database schema failed.

:end
pause
