Skip to content

Commit b520b73

Browse files
committed
Fix Set-PgSqlTestEnvironment for windows 2025
1 parent 7ae7132 commit b520b73

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

php/BuildPhp/private/Set-PgSqlTestEnvironment.ps1

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ function Set-PgSqlTestEnvironment {
1313
$env:PGPASSWORD = 'Password12!'
1414

1515
if(-not(Test-Path pgsql_init)) {
16-
Set-Service -Name "postgresql-x64-14" -StartupType manual -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
17-
Start-Service -Name "postgresql-x64-14" -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
18-
$service = Get-Service -Name "postgresql-x64-14" -ErrorAction SilentlyContinue
16+
$service = Get-Service -Name "postgresql-x64-*" -ErrorAction SilentlyContinue |
17+
Sort-Object -Property @{ Expression = { if ($_.Name -match '^postgresql-x64-(\d+)$') { [int]$Matches[1] } else { 0 } } } -Descending |
18+
Select-Object -First 1
1919
if ($service) {
20+
Write-Host "Using PostgreSQL service $($service.Name)."
21+
Set-Service -Name $service.Name -StartupType manual -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
22+
Start-Service -Name $service.Name -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
2023
$service.WaitForStatus('Running', [TimeSpan]::FromSeconds(60))
24+
} else {
25+
Write-Warning "No PostgreSQL service matching postgresql-x64-* was found."
2126
}
2227
Set-Content -Path pgsql_init -Value "initialized" -Encoding ASCII
2328
}

0 commit comments

Comments
 (0)