Compare commits

..

2 Commits

Author SHA1 Message Date
306413ca56 update setup script 2026-03-10 20:33:13 +02:00
b1453ff249 Fix MySQL connection refused - add proper database readiness check
The previous 5-second fixed wait was insufficient for MySQL 8.0 to fully
initialize, causing migrations and seeders to fail with 'Connection refused'.

Changes:
- Replace 'sleep 5' with active connection polling
- Try to connect every second for up to 30 seconds
- Use PHP PDO to test actual database connectivity
- Only proceed when database accepts connections
- Show clear status when database is ready

This ensures migrations and seeders run only after database is fully ready,
preventing 'Connection refused' errors on fresh setup.

Fixes the issue where Laravel loads but shows MySQL connection error.
2026-03-10 20:31:51 +02:00
2 changed files with 51 additions and 10 deletions

View File

@@ -147,15 +147,41 @@ echo.
REM Step 6: Wait for database
if "%DB%"=="mysql" (
echo Waiting for database...
timeout /t 5 /nobreak >nul
echo Database ready
echo Waiting for MySQL to be ready...
set DB_READY=0
for /L %%i in (1,1,30) do (
docker-compose exec -T app php -r "new PDO('mysql:host=mysql;dbname=laravel', 'laravel', 'secret');" >nul 2>&1
if !errorlevel! equ 0 (
set DB_READY=1
goto :mysql_ready
)
timeout /t 1 /nobreak >nul
)
:mysql_ready
if !DB_READY! equ 1 (
echo MySQL ready
) else (
echo WARNING: MySQL may not be fully ready yet
)
echo.
)
if "%DB%"=="pgsql" (
echo Waiting for database...
timeout /t 5 /nobreak >nul
echo Database ready
echo Waiting for PostgreSQL to be ready...
set DB_READY=0
for /L %%i in (1,1,30) do (
docker-compose exec -T app php -r "new PDO('pgsql:host=pgsql;dbname=laravel', 'laravel', 'secret');" >nul 2>&1
if !errorlevel! equ 0 (
set DB_READY=1
goto :pgsql_ready
)
timeout /t 1 /nobreak >nul
)
:pgsql_ready
if !DB_READY! equ 1 (
echo PostgreSQL ready
) else (
echo WARNING: PostgreSQL may not be fully ready yet
)
echo.
)

View File

@@ -138,10 +138,25 @@ echo -e "${GREEN}✓ App container ready${NC}"
echo ""
# Step 6: Wait for database
if [ "$DB" = "mysql" ] || [ "$DB" = "pgsql" ]; then
echo -e "${YELLOW}→ Waiting for database...${NC}"
sleep 5
echo -e "${GREEN}✓ Database ready${NC}"
if [ "$DB" = "mysql" ]; then
echo -e "${YELLOW}→ Waiting for MySQL to be ready...${NC}"
for i in {1..30}; do
if docker-compose exec -T app php -r "new PDO('mysql:host=mysql;dbname=laravel', 'laravel', 'secret');" >/dev/null 2>&1; then
echo -e "${GREEN}✓ MySQL ready${NC}"
break
fi
sleep 1
done
echo ""
elif [ "$DB" = "pgsql" ]; then
echo -e "${YELLOW}→ Waiting for PostgreSQL to be ready...${NC}"
for i in {1..30}; do
if docker-compose exec -T app php -r "new PDO('pgsql:host=pgsql;dbname=laravel', 'laravel', 'secret');" >/dev/null 2>&1; then
echo -e "${GREEN}✓ PostgreSQL ready${NC}"
break
fi
sleep 1
done
echo ""
fi