
&"$PSScriptRoot\..\vars.ps1"

if (-Not(Test-Path "$ROOT/Var/Upgrade/$version.scripts.zip" -PathType Leaf))
{
    Write-Host "Downloading $version.scripts.zip"
    [void](Invoke-WebRequest -Uri "$CedarReleases/$version.scripts.zip" -OutFile "$ROOT/Var/Upgrade/$version.scripts.zip" -ErrorAction SilentlyContinue -SkipCertificateCheck)
}

Write-Host "Extracting $version.scripts.zip"
Expand-Archive -Force "$ROOT/Var/Upgrade/$version.scripts.zip" -DestinationPath "$ROOT/Var/Upgrade/" -ErrorAction SilentlyContinue

Write-Host ""
Write-Host "upgrade SQL scripts"
&"$PHPexe" "$ROOT/src/bootstrap.php" upgrade:scripts $version --live --single
Write-Host ""
Write-Host 'upgrade PS1 scripts'
Get-ChildItem "$ROOT\Var\Upgrade\*.ps1" | ForEach-Object {
    $fName = $_.FullName
    Write-Host "Running ... $fName"
    &"$fName"
    [void](Remove-Item -Force "$fName")
}
