@echo off

set MYSQL_APP=mysql
where %MYSQL_APP%>nul
if %ERRORLEVEL% equ 0 goto enter_params

set /p "MYSQL_APP_PATH=MySQL client application is not found. Enter the path to application: "
if "%MYSQL_APP_PATH%"=="" goto failed
set MYSQL_APP=%MYSQL_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 [3306]: "
if "%DB_PORT%"=="" set "DB_PORT=3306"

set /p PACS_USER="Enter mysql 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%: "

%MYSQL_APP% -u %PACS_USER% -p%PACS_PASS% -h %DB_HOST% -P%DB_PORT% -e "source update_to_1.4.1.sql"
if ERRORLEVEL 1 goto failed

echo Updating database schema completed.
goto end

:failed
echo Updating database schema failed.

:end

pause
