-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit-db.ps1
More file actions
63 lines (54 loc) · 2.12 KB
/
Copy pathinit-db.ps1
File metadata and controls
63 lines (54 loc) · 2.12 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
#!/usr/bin/env pwsh
# Quick database initialization script
# Usage: .\init-db.ps1 [-DatabaseUrl "connection-string"]
param(
[Parameter(Mandatory=$false)]
[string]$DatabaseUrl = $env:DATABASE_URL
)
if ([string]::IsNullOrEmpty($DatabaseUrl)) {
Write-Error "❌ DATABASE_URL not provided. Use -DatabaseUrl parameter or set DATABASE_URL environment variable."
Write-Host ""
Write-Host "Example:" -ForegroundColor Yellow
Write-Host ' .\init-db.ps1 -DatabaseUrl "postgresql://user:pass@localhost:5432/agentpress"'
exit 1
}
Write-Host "🚀 AgentPress Database Initialization" -ForegroundColor Cyan
Write-Host ""
# Test connection
Write-Host "📡 Testing database connection..." -ForegroundColor Yellow
$testResult = & psql $DatabaseUrl -c "SELECT version();" 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Error "❌ Database connection failed"
Write-Host $testResult
exit 1
}
Write-Host "✅ Connection successful" -ForegroundColor Green
Write-Host ""
# Run initialization
Write-Host "📦 Creating tables and schema..." -ForegroundColor Yellow
$initScript = Join-Path $PSScriptRoot "database-init.sql"
& psql $DatabaseUrl -f $initScript
if ($LASTEXITCODE -ne 0) {
Write-Error "❌ Database initialization failed"
exit 1
}
Write-Host "✅ Schema created" -ForegroundColor Green
Write-Host ""
# Verify tables
Write-Host "🔍 Verifying tables..." -ForegroundColor Yellow
$tables = & psql $DatabaseUrl -t -c "SELECT table_name FROM information_schema.tables WHERE table_schema='public' ORDER BY table_name;" | Where-Object { $_.Trim() -ne "" }
$tableCount = ($tables | Measure-Object).Count
if ($tableCount -eq 0) {
Write-Error "❌ No tables found"
exit 1
}
Write-Host "✅ Found $tableCount tables:" -ForegroundColor Green
$tables | ForEach-Object { Write-Host " - $($_.Trim())" -ForegroundColor Gray }
Write-Host ""
Write-Host "🎉 Database initialization complete!" -ForegroundColor Green
Write-Host ""
Write-Host "Next steps:" -ForegroundColor Cyan
Write-Host " 1. Configure environment variables in .env"
Write-Host " 2. Run: npm install"
Write-Host " 3. Run: npm run build"
Write-Host " 4. Run: npm start"