@echo off
REM Fix organization table schema - extend VARCHAR fields
REM This applies the V2 migration manually if Flyway hasn't picked it up

echo Applying schema fix to ted.organization table...

set PGPASSWORD=PDmXRx0Rbk9OFOn9qO5Gm/mPCfqW8zwbZ+/YIU1lySc=

psql -h 94.130.218.54 -p 32333 -U postgres -d RELM -c "ALTER TABLE ted.organization ALTER COLUMN postal_code TYPE VARCHAR(255); ALTER TABLE ted.organization ALTER COLUMN street_name TYPE TEXT; ALTER TABLE ted.organization ALTER COLUMN city TYPE VARCHAR(255); ALTER TABLE ted.organization ALTER COLUMN phone TYPE VARCHAR(100); ALTER TABLE ted.organization ALTER COLUMN org_reference TYPE VARCHAR(100); ALTER TABLE ted.organization ALTER COLUMN role TYPE VARCHAR(100); SELECT 'Schema updated successfully!' AS result;"

if %ERRORLEVEL% EQU 0 (
    echo.
    echo Schema fix applied successfully!
    echo You can now restart the application.
) else (
    echo.
    echo ERROR: Failed to apply schema fix.
    echo Please check the error messages above.
)

pause
