SPB Git

spb/autoscholar

Public
1.4 KB · 20 lines shellscript
1#!/bin/bash2# Restore test in an isolated database: creates autoscholar_restore, restores the dump, checks counts and 20 artifact digests, drops it.3#   DATABASE_URL (admin-capable, e.g. local socket) ARTIFACT_ROOT ; usage: restore-test.sh <dump.dump>4set -euo pipefail5DUMP="${1:?dump path}"; : "${ARTIFACT_ROOT:?}"6export PATH=/opt/homebrew/opt/postgresql@17/bin:/opt/homebrew/bin:/usr/bin:/bin7ADMIN_URL="${PG_ADMIN_URL:-postgresql:///postgres}"8psql "$ADMIN_URL" -qc "drop database if exists autoscholar_restore" ; psql "$ADMIN_URL" -qc "create database autoscholar_restore"9pg_restore --no-owner -d "${ADMIN_URL%/postgres}/autoscholar_restore" "$DUMP"10R="${ADMIN_URL%/postgres}/autoscholar_restore"11echo "papers=$(psql "$R" -Atc 'select count(*) from papers') runs=$(psql "$R" -Atc 'select count(*) from research_runs') artifacts=$(psql "$R" -Atc 'select count(*) from artifacts') events=$(psql "$R" -Atc 'select count(*) from stage_events')"12FAIL=0; N=013while IFS='|' read -r key sha; do14  [ -z "$key" ] && continue; N=$((N+1))15  got=$(shasum -a 256 "$ARTIFACT_ROOT/$key" 2>/dev/null | cut -d' ' -f1 || true)16  [ "$got" = "$sha" ] || { echo "DIGEST MISMATCH $key"; FAIL=$((FAIL+1)); }17done < <(psql "$R" -Atc "select storage_key, sha256 from artifacts order by random() limit 20")18psql "$ADMIN_URL" -qc "drop database autoscholar_restore"19echo "verified $N artifacts, $FAIL mismatches"; [ "$FAIL" = 0 ]20
Files · 0d8280a29f83e41fbeda1fded3fa94709eba2e7d
Menu

Theme