Complete lab 2 PostgreSQL Redis implementation

This commit is contained in:
sinveria
2026-11-04 20:04:25 +03:00
parent 2410960d3c
commit b727fa922a
18 changed files with 942 additions and 67 deletions
+13
View File
@@ -0,0 +1,13 @@
-- Run with:
-- docker compose exec -T postgres psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" < scripts/explain_history.sql
-- This script selects an existing chat and explains the exact keyset history query.
-- For the required >=10,000-row experiment, seed the chosen chat first, then ANALYZE.
\pset pager off
SELECT count(*) AS total_messages FROM messages;
ANALYZE messages;
EXPLAIN (ANALYZE, BUFFERS)
SELECT id, chat_id, sender_id, text, created_at
FROM messages
WHERE chat_id = (SELECT chat_id FROM messages GROUP BY chat_id ORDER BY count(*) DESC LIMIT 1)
ORDER BY created_at ASC, id ASC
LIMIT 51;
+30
View File
@@ -0,0 +1,30 @@
$ErrorActionPreference = "Stop"
$ProjectRoot = Split-Path -Parent $PSScriptRoot
Push-Location $ProjectRoot
try {
Write-Host "Restarting API, PostgreSQL and Redis without removing volumes..."
docker compose restart api postgres redis
if ($LASTEXITCODE -ne 0) { throw "docker compose restart failed" }
$deadline = (Get-Date).AddSeconds(90)
do {
Start-Sleep -Seconds 2
$ready = $false
try {
$response = Invoke-RestMethod -Uri "http://127.0.0.1:8080/health/ready" -TimeoutSec 3
$ready = ($response.status -eq "ok")
} catch { }
if ($ready) {
$states = docker compose ps --format json | ConvertFrom-Json
$healthy = @($states | Where-Object { $_.Health -eq "healthy" })
if ($healthy.Count -ge 3) {
Write-Host "PASS: API and both stores are healthy. Named volumes were preserved."
exit 0
}
}
} while ((Get-Date) -lt $deadline)
throw "Stack did not become healthy within 90 seconds"
}
finally {
Pop-Location
}