@echo off
chcp 65001 >nul
cd /d "%~dp0"

set PATH=%~dp0Ruby32-x64\bin;%PATH%
set GEM_HOME=%~dp03.2.0
set GEM_PATH=%~dp03.2.0
set RACK_ENV=production
set DATABASE_PATH=%~dp0data\client.db

if not exist "%~dp0Ruby32-x64\bin\ruby.exe" (
    echo [ERROR] Ruby not found: %~dp0Ruby32-x64\bin\ruby.exe
    pause
    exit /b 1
)

cd /d "%~dp0src"

if not exist "run_migration.rb" (
    echo [ERROR] run_migration.rb not found
    pause
    exit /b 1
)

echo Running migration...
ruby run_migration.rb

if errorlevel 1 (
    echo.
    echo Migration failed
    pause
) else (
    echo.
    echo Migration done
    timeout /t 2 >nul
)
