-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.ps1
More file actions
125 lines (104 loc) · 4.21 KB
/
Copy pathdeploy.ps1
File metadata and controls
125 lines (104 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<#
.SYNOPSIS
Publishes a SharpPostgres-hosted PG extension for win-x64 (Release config),
copies the AOT .dll + generator-emitted extension/ files into the local
PostgreSQL 18 install, and restarts the PG service.
.PARAMETER Extension
Which extension to deploy:
* JsonSchemaCheck (default) -- the JSON Schema validator extension
* Demos -- the synthetic sample-functions extension
* All -- both, in one service-restart cycle
.EXAMPLE
.\deploy.ps1
.\deploy.ps1 -Extension Demos
.\deploy.ps1 -Extension All
.NOTES
Run as administrator: copying into Program Files + restarting the
postgresql-x64-18 service both require elevation. The script will refuse
to run unelevated.
Restarting the service kicks all existing connections; that's required
for new backend processes to pick up the new .dll. Existing backends
hold the old image in memory and won't see your update.
#>
#requires -RunAsAdministrator
param(
[ValidateSet('Demos', 'JsonSchemaCheck', 'All')]
[string]$Extension = 'JsonSchemaCheck'
)
$ErrorActionPreference = 'Stop'
# Edit these two for your install: the EDB-installer defaults are
# 'postgresql-x64-18' / 'C:\Program Files\PostgreSQL\18'. If you used a
# different installer / version / path, update both before running.
$service = 'postgresql-x64-18'
$pgRoot = 'C:\Program Files\PostgreSQL\18'
$repo = $PSScriptRoot
$publishDir = Join-Path $repo 'artifacts\win-x64'
# Fail fast before doing any work if the install doesn't match.
if (-not (Get-Service -Name $service -ErrorAction SilentlyContinue)) {
throw "Service '$service' not found. Edit `$service in this script to match your PG install."
}
if (-not (Test-Path $pgRoot -PathType Container)) {
throw "PG install root '$pgRoot' not found. Edit `$pgRoot in this script to match your PG install."
}
$projects = [ordered]@{
'Demos' = @{
Csproj = 'SharpPostgres.Demos\SharpPostgres.Demos.csproj'
Folder = 'SharpPostgres.Demos'
DllBase = 'sharppostgres_demos'
}
'JsonSchemaCheck' = @{
Csproj = 'SharpPostgres.JsonSchemaCheck\SharpPostgres.JsonSchemaCheck.csproj'
Folder = 'SharpPostgres.JsonSchemaCheck'
DllBase = 'json_schema_check'
}
}
$toDeploy = if ($Extension -eq 'All') { @('Demos', 'JsonSchemaCheck') } else { @($Extension) }
# 1. Publish all selected extensions BEFORE stopping the service: any
# build failure should leave PG running.
foreach ($name in $toDeploy) {
$info = $projects[$name]
Write-Host ""
Write-Host "Publishing $name (win-x64, Release)..." -ForegroundColor Cyan
dotnet publish (Join-Path $repo $info.Csproj) `
-c Release -r win-x64 -o $publishDir --nologo
if ($LASTEXITCODE -ne 0) {
throw "dotnet publish failed for $name (exit $LASTEXITCODE)"
}
$dll = Join-Path $publishDir "$($info.DllBase).dll"
if (-not (Test-Path $dll)) {
throw "Expected $dll after publish, but it's missing"
}
$extDir = Join-Path $repo "$($info.Folder)\extension"
if (-not (Test-Path $extDir)) {
throw "Expected $extDir to exist (EmitSchema target should have populated it)"
}
}
# 2. Stop the service once, deploy everything, restart once -- minimizes
# downtime when deploying multiple extensions.
Write-Host ""
Write-Host "Stopping $service..." -ForegroundColor Cyan
Stop-Service $service
try {
foreach ($name in $toDeploy) {
$info = $projects[$name]
$dll = Join-Path $publishDir "$($info.DllBase).dll"
$extDir = Join-Path $repo "$($info.Folder)\extension"
Write-Host ""
Write-Host "Deploying $name..." -ForegroundColor Cyan
Write-Host " $dll -> $pgRoot\lib\"
Copy-Item $dll "$pgRoot\lib\" -Force
Write-Host " $extDir\* -> $pgRoot\share\extension\"
Copy-Item (Join-Path $extDir '*') "$pgRoot\share\extension\" -Force
}
}
finally {
Write-Host ""
Write-Host "Starting $service..." -ForegroundColor Cyan
Start-Service $service
}
Write-Host ""
Write-Host "Deploy OK. Run 'CREATE EXTENSION <name>;' from any client to load." -ForegroundColor Green
foreach ($name in $toDeploy) {
$sqlName = if ($name -eq 'JsonSchemaCheck') { 'json_schema_check' } else { 'sharppostgres_demos' }
Write-Host " CREATE EXTENSION $sqlName;"
}