Add optional remote EF migration step to deploy script

This commit is contained in:
2026-02-05 00:26:17 +01:00
parent 0c22821b56
commit f4b21da24d

View File

@@ -14,6 +14,8 @@ $AppPoolName = "xTr1m.com(domain)(4.0)(pool)"
$WinRmComputer = "xTr1m.com" $WinRmComputer = "xTr1m.com"
$WinRmCredentialUser = "Administrator" $WinRmCredentialUser = "Administrator"
$UseWinRmHttps = $true # set false if using HTTP + TrustedHosts $UseWinRmHttps = $true # set false if using HTTP + TrustedHosts
$RemoteSitePath = "C:\Inetpub\vhosts\xTr1m.com\httpdocs\picknplay"
$RunEfMigrations = $true # set to $false to skip remote database update
<#! <#!
.SYNOPSIS .SYNOPSIS
@@ -126,4 +128,30 @@ if ($RecycleAppPool) {
} }
} }
if ($RunEfMigrations) {
Write-Host "5) Running EF Core migrations on remote site..." -ForegroundColor Cyan
$sec = ConvertTo-SecureString $Password -AsPlainText -Force
$cred = New-Object pscredential($WinRmCredentialUser, $sec)
$invokeParams = @{
ComputerName = $WinRmComputer
Credential = $cred
ScriptBlock = {
param($sitePath)
Set-Location $sitePath
if (-not (Get-Command dotnet-ef -ErrorAction SilentlyContinue)) {
throw "dotnet-ef not available on remote host. Install SDK or set `$RunEfMigrations = $false."
}
dotnet-ef database update --no-build
}
ArgumentList = @($RemoteSitePath)
}
if ($UseWinRmHttps) { $invokeParams["UseSSL"] = $true }
if ($WinRmAuth) { $invokeParams["Authentication"] = $WinRmAuth }
try {
Invoke-Command @invokeParams
} catch {
Write-Warning "WinRM migrations failed: $($_.Exception.Message)."
}
}
Write-Host "Done." -ForegroundColor Green Write-Host "Done." -ForegroundColor Green