diff --git a/images/win/scripts/Installers/Install-PostgreSQL.ps1 b/images/win/scripts/Installers/Install-PostgreSQL.ps1 index 8fe78c7f..9e6a435e 100644 --- a/images/win/scripts/Installers/Install-PostgreSQL.ps1 +++ b/images/win/scripts/Installers/Install-PostgreSQL.ps1 @@ -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 diff --git a/images/win/scripts/Tests/Databases.Tests.ps1 b/images/win/scripts/Tests/Databases.Tests.ps1 index 6737eb1f..adf8c983 100644 --- a/images/win/scripts/Tests/Databases.Tests.ps1 +++ b/images/win/scripts/Tests/Databases.Tests.ps1 @@ -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" { diff --git a/images/win/toolsets/toolset-2016.json b/images/win/toolsets/toolset-2016.json index 9cce92d0..a0d119a3 100644 --- a/images/win/toolsets/toolset-2016.json +++ b/images/win/toolsets/toolset-2016.json @@ -432,5 +432,8 @@ }, "llvm": { "version": "13" + }, + "postgresql": { + "version": "14" } } diff --git a/images/win/toolsets/toolset-2019.json b/images/win/toolsets/toolset-2019.json index 1670e986..3fbafade 100644 --- a/images/win/toolsets/toolset-2019.json +++ b/images/win/toolsets/toolset-2019.json @@ -464,5 +464,8 @@ }, "llvm": { "version": "13" + }, + "postgresql": { + "version": "14" } } diff --git a/images/win/toolsets/toolset-2022.json b/images/win/toolsets/toolset-2022.json index 796fcfdb..a05ec312 100644 --- a/images/win/toolsets/toolset-2022.json +++ b/images/win/toolsets/toolset-2022.json @@ -313,5 +313,8 @@ }, "php": { "version": "8.0" + }, + "postgresql": { + "version": "14" } }