-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-database.bat
More file actions
104 lines (90 loc) · 2.99 KB
/
setup-database.bat
File metadata and controls
104 lines (90 loc) · 2.99 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
@echo off
echo ====================================
echo SupremeScan Database Setup
echo ====================================
echo.
REM Check if PostgreSQL is installed
where psql >nul 2>nul
if %ERRORLEVEL% NEQ 0 (
echo PostgreSQL not found in PATH!
echo.
echo Please install PostgreSQL from:
echo https://www.postgresql.org/download/windows/
echo.
echo Or use Docker:
echo docker run --name supremescan-db -e POSTGRES_PASSWORD=supremescan123 -p 5432:5432 -d postgres
pause
exit /b 1
)
echo Step 1: Creating database...
echo.
REM Set PostgreSQL connection details
set PGPASSWORD=postgres
set PGUSER=postgres
set PGHOST=localhost
set PGPORT=5432
REM Create database
psql -U %PGUSER% -h %PGHOST% -p %PGPORT% -c "CREATE DATABASE supremescan;" 2>nul
if %ERRORLEVEL% EQU 0 (
echo ✓ Database 'supremescan' created
) else (
echo Database 'supremescan' may already exist or check your PostgreSQL installation
)
echo.
echo Step 2: Creating user...
echo.
REM Create user
psql -U %PGUSER% -h %PGHOST% -p %PGPORT% -c "CREATE USER supremescan_user WITH PASSWORD 'supremescan_password';" 2>nul
if %ERRORLEVEL% EQU 0 (
echo ✓ User 'supremescan_user' created
) else (
echo User 'supremescan_user' may already exist
)
echo.
echo Step 3: Granting privileges...
echo.
psql -U %PGUSER% -h %PGHOST% -p %PGPORT% -c "GRANT ALL PRIVILEGES ON DATABASE supremescan TO supremescan_user;" >nul
psql -U %PGUSER% -h %PGHOST% -p %PGPORT% -d supremescan -c "GRANT ALL ON SCHEMA public TO supremescan_user;" >nul
echo ✓ Privileges granted
echo.
echo Step 4: Running migrations...
echo.
set PGPASSWORD=supremescan_password
set PGUSER=supremescan_user
set PGDATABASE=supremescan
echo Running migration 001_extensions_rules.sql...
psql -U %PGUSER% -h %PGHOST% -p %PGPORT% -d %PGDATABASE% -f migrations\001_extensions_rules.sql >nul 2>&1
if %ERRORLEVEL% EQU 0 (
echo ✓ Migration 001 completed
) else (
echo ✗ Migration 001 failed or already applied
)
echo Running migration 002_projects_scans.sql...
psql -U %PGUSER% -h %PGHOST% -p %PGPORT% -d %PGDATABASE% -f migrations\002_projects_scans.sql >nul 2>&1
if %ERRORLEVEL% EQU 0 (
echo ✓ Migration 002 completed
) else (
echo ✗ Migration 002 failed or already applied
)
echo Running migration 003_users_github.sql...
psql -U %PGUSER% -h %PGHOST% -p %PGPORT% -d %PGDATABASE% -f migrations\003_users_github.sql >nul 2>&1
if %ERRORLEVEL% EQU 0 (
echo ✓ Migration 003 completed
) else (
echo ✗ Migration 003 failed or already applied
)
echo.
echo ====================================
echo Setup Complete!
echo ====================================
echo.
echo Database Connection String:
echo postgresql://supremescan_user:supremescan_password@localhost:5432/supremescan
echo.
echo Add this to your .env file:
echo SUPREMESCAN_DB_URL=postgresql://supremescan_user:supremescan_password@localhost:5432/supremescan
echo.
echo Also add ENCRYPTION_KEY (generate with):
echo node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
echo.
pause