-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-postgres.bat
More file actions
122 lines (114 loc) · 3.55 KB
/
Copy pathsetup-postgres.bat
File metadata and controls
122 lines (114 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
@echo off
REM Setup PostgreSQL Docker container for OpenTron (Windows)
REM Run this script to start PostgreSQL and configure the environment
setlocal enabledelayedexpansion
cls
echo ==========================================
echo OpenTron PostgreSQL Docker Setup (Windows)
echo ==========================================
echo.
REM Check if Docker is running
echo [1/5] Checking Docker daemon...
docker ps > nul 2>&1
if errorlevel 1 (
echo X Docker daemon is not running!
echo Please start Docker Desktop and try again.
exit /b 1
)
echo [OK] Docker daemon is running
echo.
REM Check if container already exists
echo [2/5] Checking for existing PostgreSQL container...
docker ps -a --format "{{.Names}}" | findstr /x "opentron-postgres" > nul
if errorlevel 1 (
echo Creating new PostgreSQL container...
docker run -d ^
--name opentron-postgres ^
-e POSTGRES_DB=opentron ^
-e POSTGRES_USER=opentron ^
-e POSTGRES_PASSWORD=opentron_secure_password ^
-p 5432:5432 ^
-v postgres_data:/var/lib/postgresql/data ^
postgres:16-alpine
if errorlevel 1 (
echo [FAIL] Failed to create container
exit /b 1
)
echo [OK] PostgreSQL container created
) else (
docker ps --format "{{.Names}}" | findstr /x "opentron-postgres" > nul
if errorlevel 1 (
echo Starting existing container...
docker start opentron-postgres > nul
if errorlevel 1 (
echo [FAIL] Failed to start container
exit /b 1
)
)
echo [OK] Container is running
)
echo.
REM Wait for PostgreSQL to be ready
echo [3/5] Waiting for PostgreSQL to be ready...
setlocal enabledelayedexpansion
for /L %%i in (1,1,30) do (
docker exec opentron-postgres pg_isready -U opentron > nul 2>&1
if errorlevel 0 (
echo [OK] PostgreSQL is ready
goto postgres_ready
)
if %%i lss 30 (
echo Waiting... (%%i/30)
timeout /t 1 /nobreak > nul
)
)
echo [FAIL] PostgreSQL failed to start within 30 seconds
exit /b 1
:postgres_ready
echo.
REM Verify connection
echo [4/5] Verifying connection...
docker exec opentron-postgres psql -U opentron -d opentron -c "SELECT version();" > nul 2>&1
if errorlevel 1 (
echo [FAIL] Connection failed
exit /b 1
)
echo [OK] Connection successful
echo.
REM Display connection information
echo [5/5] Configuration Summary
echo ==========================================
echo [SUCCESS] PostgreSQL is ready!
echo.
echo Connection Details:
echo Host: localhost
echo Port: 5432
echo Database: opentron
echo User: opentron
echo Password: opentron_secure_password
echo.
echo Docker Container:
echo Name: opentron-postgres
echo Image: postgres:16-alpine
echo Status: Running
echo.
echo Environment Variables (set these for your Java backend):
echo POSTGRES_URL=jdbc:postgresql://localhost:5432/opentron
echo POSTGRES_USER=opentron
echo POSTGRES_PASSWORD=opentron_secure_password
echo.
echo Useful Docker Commands:
echo docker logs opentron-postgres # View logs
echo docker ps # List running containers
echo docker stop opentron-postgres # Stop container
echo docker start opentron-postgres # Start container
echo docker rm opentron-postgres # Remove container
echo.
echo Next Steps:
echo 1. Set the environment variables above in PowerShell or CMD
echo 2. cd java\opentron-java\backend
echo 3. mvn clean package -DskipTests
echo 4. mvn spring-boot:run
echo.
echo ==========================================
pause