Add optional remote EF migration step to deploy script
This commit is contained in:
@@ -14,6 +14,8 @@ $AppPoolName = "xTr1m.com(domain)(4.0)(pool)"
|
||||
$WinRmComputer = "xTr1m.com"
|
||||
$WinRmCredentialUser = "Administrator"
|
||||
$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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user