From f4b21da24da381db1bae9e6aa6980ca0852c59e7 Mon Sep 17 00:00:00 2001 From: Frank Tovar Date: Thu, 5 Feb 2026 00:26:17 +0100 Subject: [PATCH] Add optional remote EF migration step to deploy script --- scripts/deploy-ftp.ps1 | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/scripts/deploy-ftp.ps1 b/scripts/deploy-ftp.ps1 index 63ac061..e43a474 100644 --- a/scripts/deploy-ftp.ps1 +++ b/scripts/deploy-ftp.ps1 @@ -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