From 0ea8e5aa1ee40883b51db1e07b070d6affd21da5 Mon Sep 17 00:00:00 2001 From: handsomezhuzhu <2658601135@qq.com> Date: Mon, 1 Dec 2025 13:58:08 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Fix=20alembic=20config=20and=20a?= =?UTF-8?q?dd=20Docker=20database=20support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix: - Fix alembic.ini version_path_separator syntax error - Add scripts to start with Docker database - Add automatic fix and start script New files: - start_with_docker_db.bat: Start with Docker PostgreSQL - fix_and_start.bat: Auto-fix and start with options 🚀 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- backend/alembic.ini | 3 +- fix_and_start.bat | 140 +++++++++++++++++++++++++++++++++++++++ start_with_docker_db.bat | 73 ++++++++++++++++++++ 3 files changed, 215 insertions(+), 1 deletion(-) create mode 100644 fix_and_start.bat create mode 100644 start_with_docker_db.bat diff --git a/backend/alembic.ini b/backend/alembic.ini index acd21c1..a9c89ef 100644 --- a/backend/alembic.ini +++ b/backend/alembic.ini @@ -35,7 +35,8 @@ version_locations = %(here)s/alembic/versions # version path separator; As mentioned above, this is the character used to split # version_locations. The default within new alembic.ini files is "os", which uses os.pathsep. # If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas. -version_path_separator = os # Use os.pathsep. Default configuration used for new projects. +# Use os.pathsep. Default configuration used for new projects. +version_path_separator = os # set to 'true' to search source files recursively # in each "version_locations" directory diff --git a/fix_and_start.bat b/fix_and_start.bat new file mode 100644 index 0000000..1b1e108 --- /dev/null +++ b/fix_and_start.bat @@ -0,0 +1,140 @@ +@echo off +title QQuiz - Fix and Start +color 0E + +echo. +echo ======================================== +echo QQuiz - Automatic Fix and Start +echo ======================================== +echo. + +cd /d "%~dp0" + +REM Check if .env exists +if not exist ".env" ( + echo Creating .env file... + copy .env.example .env >nul + echo. + echo IMPORTANT: Edit .env and set your OPENAI_API_KEY + echo Opening .env file... + timeout /t 2 /nobreak >nul + notepad .env + echo. + echo Save and close .env, then press any key to continue... + pause >nul +) + +echo. +echo Choose database option: +echo. +echo [1] Use Docker (Recommended - Easy) +echo [2] Use Local PostgreSQL (Advanced) +echo. +choice /C 12 /M "Select option" + +if %errorlevel% equ 1 ( + echo. + echo Using Docker PostgreSQL... + echo. + + REM Check Docker + docker --version >nul 2>&1 + if %errorlevel% neq 0 ( + echo ERROR: Docker not found! + echo. + echo Please install Docker Desktop: + echo https://www.docker.com/products/docker-desktop/ + echo. + echo After installing Docker, run this script again. + pause + exit /b 1 + ) + + echo Starting PostgreSQL in Docker... + docker-compose up -d postgres + + if %errorlevel% neq 0 ( + echo. + echo Docker failed to start. Trying to fix... + docker-compose down + docker-compose up -d postgres + ) + + echo Waiting for database... + timeout /t 8 /nobreak >nul + +) else ( + echo. + echo Using Local PostgreSQL... + echo. + echo Make sure PostgreSQL is running on port 5432 + echo. + echo If you see connection errors, you need to: + echo 1. Start PostgreSQL service + echo 2. Or install PostgreSQL from https://www.postgresql.org/download/ + echo 3. Or choose option 1 to use Docker instead + echo. + pause +) + +echo. +echo ======================================== +echo Starting Backend... +echo ======================================== +echo. + +cd backend + +if not exist "venv\Scripts\activate.bat" ( + echo Creating virtual environment... + python -m venv venv +) + +echo Installing dependencies... +call venv\Scripts\activate.bat +pip install -q -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple + +echo. +echo Running database migrations... +alembic upgrade head + +if %errorlevel% neq 0 ( + echo. + echo WARNING: Database migration failed + echo The app will try to create tables automatically + echo. +) + +cd .. + +echo. +echo Starting services... +echo. + +start "QQuiz Backend" cmd /k "cd /d %~dp0backend && call venv\Scripts\activate.bat && echo Backend: http://localhost:8000 && echo Docs: http://localhost:8000/docs && echo. && uvicorn main:app --reload" + +timeout /t 8 /nobreak >nul + +start "QQuiz Frontend" cmd /k "cd /d %~dp0frontend && echo Frontend: http://localhost:3000 && echo. && npm start" + +echo. +echo ======================================== +echo SUCCESS! QQuiz is starting... +echo ======================================== +echo. +echo Frontend: http://localhost:3000 +echo Backend: http://localhost:8000 +echo. +echo Login: admin / admin123 +echo. +echo ======================================== +echo. + +timeout /t 5 /nobreak >nul +start http://localhost:3000 + +echo. +echo System is running... +echo Close backend/frontend windows to stop +echo. +pause diff --git a/start_with_docker_db.bat b/start_with_docker_db.bat new file mode 100644 index 0000000..aacec59 --- /dev/null +++ b/start_with_docker_db.bat @@ -0,0 +1,73 @@ +@echo off +title QQuiz - Start with Docker Database +color 0B + +echo. +echo ======================================== +echo QQuiz - Starting with Docker DB +echo ======================================== +echo. + +cd /d "%~dp0" + +echo [1/4] Checking Docker... +docker --version >nul 2>&1 +if %errorlevel% neq 0 ( + echo ERROR: Docker not found! + echo Please install Docker Desktop from https://www.docker.com/ + pause + exit /b 1 +) +echo OK - Docker installed +echo. + +echo [2/4] Starting PostgreSQL in Docker... +docker-compose up -d postgres + +if %errorlevel% neq 0 ( + echo ERROR: Failed to start PostgreSQL + echo Try: docker-compose down + echo Then run this script again + pause + exit /b 1 +) + +echo OK - PostgreSQL started +echo Waiting for database to be ready... +timeout /t 5 /nobreak >nul +echo. + +echo [3/4] Starting Backend... +start "QQuiz Backend" cmd /k "cd /d %~dp0backend && call venv\Scripts\activate.bat && echo ======================================== && echo QQuiz Backend Server && echo ======================================== && echo. && echo API: http://localhost:8000 && echo Docs: http://localhost:8000/docs && echo. && alembic upgrade head && echo. && uvicorn main:app --reload" + +echo Waiting for backend to start... +timeout /t 8 /nobreak >nul +echo. + +echo [4/4] Starting Frontend... +start "QQuiz Frontend" cmd /k "cd /d %~dp0frontend && echo ======================================== && echo QQuiz Frontend Server && echo ======================================== && echo. && echo URL: http://localhost:3000 && echo. && npm start" + +echo. +echo ======================================== +echo SUCCESS! QQuiz is starting... +echo ======================================== +echo. +echo Frontend: http://localhost:3000 +echo Backend: http://localhost:8000 +echo Database: Running in Docker +echo. +echo Login: +echo Username: admin +echo Password: admin123 +echo. +echo ======================================== +echo. + +timeout /t 5 /nobreak >nul +start http://localhost:3000 + +echo System running... +echo To stop: Close the backend/frontend windows +echo To stop database: docker-compose down +echo. +pause