param([string]$Root = '')

. "$PSScriptRoot\db-local.ps1"

if (-not $Root) { $Root = Get-ProjectRoot -FromScript $PSScriptRoot }

$pgBin = Find-PgBin
if (-not $pgBin) { exit 0 }

$pgData = Get-PgDataDir -Root $Root
if (-not (Test-Path (Join-Path $pgData 'PG_VERSION'))) { exit 0 }

$pgCtl = Join-Path $pgBin 'pg_ctl.exe'
& $pgCtl -D $pgData stop -m fast 2>$null
exit 0
