#!/usr/bin/env bash # Runs the legacy-upgrade fixture against an isolated PostgreSQL instance. set -euo pipefail CONTAINER_NAME="hivegrid-shk-first-steps-migration-$$" POSTGRES_USER="migration_fixture" POSTGRES_PASSWORD="migration_fixture" POSTGRES_DB="migration_fixture" POSTGRES_IMAGE="${SHK_MIGRATION_PG_IMAGE:-postgres:16-alpine}" require_cmd() { if ! command -v "$1" >/dev/null 2>&1; then echo "MISSING $1: the SHK first-steps migration fixture requires it" >&2 exit 127 fi } require_cmd docker require_cmd pnpm cleanup() { docker rm -f "$CONTAINER_NAME" >/dev/null 2>&1 || true } trap cleanup EXIT docker run -d \ --name "$CONTAINER_NAME" \ -p 127.0.0.1::5432 \ -e POSTGRES_USER="$POSTGRES_USER" \ -e POSTGRES_PASSWORD="$POSTGRES_PASSWORD" \ -e POSTGRES_DB="$POSTGRES_DB" \ "$POSTGRES_IMAGE" >/dev/null PORT="$(docker port "$CONTAINER_NAME" 5432/tcp | awk -F: 'NR == 1 { print $NF }')" DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@127.0.0.1:${PORT}/${POSTGRES_DB}?schema=public" # A cold postgres:16-alpine init can exceed 30 seconds under parallel runner # I/O. Probe the final TCP server (not the temporary init socket) with the same # bounded headroom as the neighboring identity/invite migration fixture. for attempt in $(seq 1 90); do if docker exec "$CONTAINER_NAME" pg_isready -h 127.0.0.1 -U "$POSTGRES_USER" -d "$POSTGRES_DB" >/dev/null 2>&1; then break fi if [[ "$attempt" == "90" ]]; then echo "FAIL PostgreSQL did not become ready" >&2 docker logs "$CONTAINER_NAME" >&2 || true exit 1 fi sleep 1 done SHK_FIRST_STEPS_MIGRATION_TEST_DATABASE_URL="$DATABASE_URL" \ pnpm exec vitest run packages/db/src/shk-first-steps-migration.test.ts echo "PASS SHK first-steps clean contract and legacy-upgrade fixture"