Implement PostgreSQL storage, sessions and persistence checks
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
$ErrorActionPreference = 'Stop'
|
||||
Set-Location (Split-Path -Parent $PSScriptRoot)
|
||||
|
||||
function Read-Containers {
|
||||
$result = @()
|
||||
foreach ($service in @('api', 'postgres')) {
|
||||
$containerID = docker compose ps -q $service
|
||||
if ($LASTEXITCODE -ne 0 -or -not $containerID) { throw "Cannot find $service container" }
|
||||
$json = docker inspect --format '{{json .}}' $containerID
|
||||
if ($LASTEXITCODE -ne 0) { throw "Cannot inspect $service container" }
|
||||
$container = $json | ConvertFrom-Json
|
||||
# Only retain safe lifecycle fields; never write Config.Env or secrets.
|
||||
$result += [pscustomobject]@{
|
||||
service = $service
|
||||
id = $container.Id
|
||||
started_at = $container.State.StartedAt
|
||||
status = $container.State.Status
|
||||
data_volumes = @($container.Mounts | Where-Object Type -eq 'volume' | ForEach-Object Name)
|
||||
}
|
||||
}
|
||||
return $result
|
||||
}
|
||||
|
||||
$before = @(Read-Containers)
|
||||
docker compose stop api postgres
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Stop failed' }
|
||||
docker compose up -d --wait postgres
|
||||
if ($LASTEXITCODE -ne 0) { throw 'PostgreSQL restart failed' }
|
||||
docker compose up -d --wait api
|
||||
if ($LASTEXITCODE -ne 0) { throw 'API restart failed' }
|
||||
$after = @(Read-Containers)
|
||||
foreach ($old in $before) {
|
||||
$new = $after | Where-Object service -eq $old.service
|
||||
if ($new.started_at -eq $old.started_at -or $new.status -ne 'running') {
|
||||
throw "Restart not confirmed for $($old.service)"
|
||||
}
|
||||
if (($new.data_volumes -join ',') -ne ($old.data_volumes -join ',')) {
|
||||
throw "Volume changed for $($old.service)"
|
||||
}
|
||||
}
|
||||
$evidence = [ordered]@{ before = $before; after = $after; volumes_preserved = $true }
|
||||
$path = Join-Path $PWD 'evidence/restart-containers.json'
|
||||
[System.IO.File]::WriteAllText($path, ($evidence | ConvertTo-Json -Depth 5), [System.Text.UTF8Encoding]::new($false))
|
||||
Write-Output 'PASS: API and PostgreSQL restarted; named volumes preserved.'
|
||||
Reference in New Issue
Block a user