-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate.ps1
More file actions
26 lines (21 loc) · 877 Bytes
/
Copy pathmigrate.ps1
File metadata and controls
26 lines (21 loc) · 877 Bytes
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
# Run all pending migrations in order
# Usage: .\migrate.ps1 -DatabaseUrl "postgresql://user:pass@host:5432/db"
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."
exit 1
}
$MigrationsDir = Join-Path $PSScriptRoot "migrations"
Write-Host "Running migrations from $MigrationsDir" -ForegroundColor Cyan
Get-ChildItem -Path $MigrationsDir -Filter "*.sql" | Sort-Object Name | ForEach-Object {
Write-Host "Applying: $($_.Name)" -ForegroundColor Yellow
& psql $DatabaseUrl -f $_.FullName
if ($LASTEXITCODE -ne 0) {
Write-Error "Migration failed: $($_.Name)"
exit 1
}
}
Write-Host "All migrations completed successfully" -ForegroundColor Green