-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-postgres.ps1
More file actions
84 lines (68 loc) · 3.04 KB
/
setup-postgres.ps1
File metadata and controls
84 lines (68 loc) · 3.04 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
# PostgreSQL Setup Script for File Upload Application (Windows)
# This script helps set up PostgreSQL for the file upload backend
Write-Host "=========================================" -ForegroundColor Cyan
Write-Host "PostgreSQL Setup for File Upload App" -ForegroundColor Cyan
Write-Host "=========================================" -ForegroundColor Cyan
Write-Host ""
# Check if PostgreSQL is installed
$psqlPath = Get-Command psql -ErrorAction SilentlyContinue
if (-not $psqlPath) {
Write-Host "❌ PostgreSQL is not installed!" -ForegroundColor Red
Write-Host ""
Write-Host "Please install PostgreSQL first:" -ForegroundColor Yellow
Write-Host " - Download from: https://www.postgresql.org/download/windows/" -ForegroundColor Yellow
Write-Host " - Or use Chocolatey: choco install postgresql" -ForegroundColor Yellow
exit 1
}
Write-Host "✅ PostgreSQL is installed" -ForegroundColor Green
Write-Host ""
# Get database credentials
$DB_USER = Read-Host "PostgreSQL username [postgres]"
if ([string]::IsNullOrWhiteSpace($DB_USER)) { $DB_USER = "postgres" }
$DB_PASSWORD = Read-Host "PostgreSQL password" -AsSecureString
$DB_PASSWORD_TEXT = [Runtime.InteropServices.Marshal]::PtrToStringAuto(
[Runtime.InteropServices.Marshal]::SecureStringToBSTR($DB_PASSWORD)
)
$DB_NAME = Read-Host "Database name [fileupload]"
if ([string]::IsNullOrWhiteSpace($DB_NAME)) { $DB_NAME = "fileupload" }
$DB_HOST = Read-Host "Database host [localhost]"
if ([string]::IsNullOrWhiteSpace($DB_HOST)) { $DB_HOST = "localhost" }
$DB_PORT = Read-Host "Database port [5432]"
if ([string]::IsNullOrWhiteSpace($DB_PORT)) { $DB_PORT = "5432" }
Write-Host ""
Write-Host "Creating database '$DB_NAME'..." -ForegroundColor Yellow
# Set password environment variable for psql
$env:PGPASSWORD = $DB_PASSWORD_TEXT
# Create database
try {
psql -U $DB_USER -h $DB_HOST -p $DB_PORT -c "CREATE DATABASE $DB_NAME;" 2>$null
Write-Host "✅ Database created successfully" -ForegroundColor Green
}
catch {
Write-Host "⚠️ Database might already exist or there was an error" -ForegroundColor Yellow
}
# Clear password from environment
$env:PGPASSWORD = $null
Write-Host ""
Write-Host "Creating .env file..." -ForegroundColor Yellow
# Create .env file
$envContent = @"
# PostgreSQL Database Configuration
DB_HOST=$DB_HOST
DB_PORT=$DB_PORT
DB_NAME=$DB_NAME
DB_USER=$DB_USER
DB_PASSWORD=$DB_PASSWORD_TEXT
"@
$envContent | Out-File -FilePath "backend\.env" -Encoding UTF8
Write-Host "✅ .env file created at backend\.env" -ForegroundColor Green
Write-Host ""
Write-Host "=========================================" -ForegroundColor Cyan
Write-Host "Setup Complete!" -ForegroundColor Green
Write-Host "=========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Next steps:" -ForegroundColor Yellow
Write-Host "1. Install dependencies: npm install" -ForegroundColor White
Write-Host "2. Start the backend: npm run dev:backend" -ForegroundColor White
Write-Host ""
Write-Host "The database tables will be created automatically on first run." -ForegroundColor Cyan