Implement PostgreSQL storage, sessions and persistence checks

This commit is contained in:
Daria0w0
2026-10-09 18:06:28 +03:00
parent 65003b6119
commit 83e3810d33
62 changed files with 4650 additions and 20 deletions
+27
View File
@@ -0,0 +1,27 @@
$ErrorActionPreference = 'Stop'
$repoRoot = Split-Path -Parent $PSScriptRoot
$secretsDirectory = Join-Path $repoRoot 'secrets'
$passwordPath = Join-Path $secretsDirectory 'postgres_password.txt'
New-Item -ItemType Directory -Path $secretsDirectory -Force | Out-Null
if (Test-Path -LiteralPath $passwordPath) {
if ((Get-Item -LiteralPath $passwordPath).Length -eq 0) {
throw 'Existing password file is empty. Supply a local password before starting PostgreSQL.'
}
Write-Output 'Existing PostgreSQL password preserved.'
exit 0
}
$randomBytes = New-Object byte[] 32
$generator = [System.Security.Cryptography.RandomNumberGenerator]::Create()
try {
$generator.GetBytes($randomBytes)
} finally {
$generator.Dispose()
}
$password = [Convert]::ToBase64String($randomBytes)
[System.IO.File]::WriteAllText($passwordPath, $password, [System.Text.Encoding]::ASCII)
Write-Output 'Local PostgreSQL password created in secrets/ (value not printed).'
+3
View File
@@ -0,0 +1,3 @@
@echo off
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0restart.ps1"
exit /b %errorlevel%
+44
View File
@@ -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.'
+18
View File
@@ -0,0 +1,18 @@
#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
snapshot() {
for service in api postgres; do
id=$(docker compose ps -q "$service")
test -n "$id"
docker inspect --format '{{.Name}} {{.Id}} {{.State.StartedAt}} {{.State.Status}} {{range .Mounts}}{{if eq .Type "volume"}}{{.Name}} {{end}}{{end}}' "$id"
done
}
snapshot > evidence/restart-containers-before.txt
docker compose stop api postgres
docker compose up -d --wait postgres
docker compose up -d --wait api
snapshot > evidence/restart-containers-after.txt
printf '%s\n' 'API and PostgreSQL restarted without removing volumes.'