[Windows] Pin PostgreSQL version installed in the toolset (#4492)

This commit is contained in:
Maksim Shilov
2021-11-16 11:38:03 +03:00
committed by GitHub
parent d3e74a5d7d
commit ff41a760f0
5 changed files with 32 additions and 9 deletions

View File

@@ -1,23 +1,27 @@
#Define user and password for PostgreSQL database
# Define user and password for PostgreSQL database
$pgUser = "postgres"
$pgPwd = "root"
#Prepare environment variable for validation
# Prepare environment variable for validation
Set-SystemVariable -SystemVariable PGUSER -Value $pgUser
Set-SystemVariable -SystemVariable PGPASSWORD -Value $pgPwd
#Install latest PostgreSQL
Choco-Install -PackageName postgresql -ArgumentList "--params", "'/Password:$pgPwd /NoPath'", "--params-global"
# Define latest available version to install based on version specified in the toolset
$toolsetVersion = (Get-ToolsetContent).postgresql.version
$latestChocoPackage = Get-LatestChocoPackageVersion -TargetVersion $toolsetVersion -PackageName "postgresql"
#Get Path to pg_ctl.exe
# Install latest PostgreSQL
Choco-Install -PackageName postgresql -ArgumentList "--params", "'/Password:$pgPwd /NoPath'", "--params-global", "--version=$latestChocoPackage"
# Get Path to pg_ctl.exe
$pgPath = (Get-CimInstance Win32_Service -Filter "Name LIKE 'postgresql-%'").PathName
#Parse output of command above to obtain pure path
# Parse output of command above to obtain pure path
$pgBin = Split-Path -Path $pgPath.split('"')[1]
$pgRoot = Split-Path -Path $pgPath.split('"')[5]
$pgData = Join-Path $pgRoot "data"
#Validate PostgreSQL installation
# Validate PostgreSQL installation
$pgReadyPath = Join-Path $pgBin "pg_isready.exe"
$pgReady = Start-Process -FilePath $pgReadyPath -Wait -PassThru
$exitCode = $pgReady.ExitCode
@@ -28,12 +32,12 @@ if ($exitCode -ne 0)
exit $exitCode
}
#Added PostgreSQL environment variable
# Added PostgreSQL environment variable
Set-SystemVariable -SystemVariable PGBIN -Value $pgBin
Set-SystemVariable -SystemVariable PGROOT -Value $pgRoot
Set-SystemVariable -SystemVariable PGDATA -Value $pgData
#Stop and disable PostgreSQL service
# Stop and disable PostgreSQL service
$pgService = Get-Service -Name postgresql*
Stop-Service -InputObject $pgService
Set-Service -InputObject $pgService -StartupType Disabled

View File

@@ -51,6 +51,16 @@ Describe "PostgreSQL" {
$StartType | Should -Be "Disabled"
}
}
Context "PostgreSQL version" {
It "PostgreSQL version should correspond to the version in the toolset" {
$toolsetVersion = (Get-ToolsetContent).postgresql.version
# Client version
(&$Env:PGBIN\psql --version).split()[-1] | Should -BeLike "$toolsetVersion*"
# Server version
(&$Env:PGBIN\pg_config --version).split()[-1] | Should -BeLike "$toolsetVersion*"
}
}
}
Describe "MySQL" {

View File

@@ -432,5 +432,8 @@
},
"llvm": {
"version": "13"
},
"postgresql": {
"version": "14"
}
}

View File

@@ -464,5 +464,8 @@
},
"llvm": {
"version": "13"
},
"postgresql": {
"version": "14"
}
}

View File

@@ -313,5 +313,8 @@
},
"php": {
"version": "8.0"
},
"postgresql": {
"version": "14"
}
}