#!/bin/bash # Creates the personal_test database and copies the production schema into it. # Run once (and after any migration) before integration tests: npm run test:setup # # It no longer writes a host into .env.test. That was the #161 defect: the file # was written once with the container's bridge IP and then rotted as the IP was # reassigned. scripts/resolve-test-db.sh now re-derives the DSN before every # integration run (wired as `pretest:integration`), and this script just calls it # at the end so a fresh setup leaves a usable .env.test behind. set -e PG_CONTAINER=${PG_CONTAINER:-postgres-personal} PG_USER=${PG_USER:-personal} TEST_DB=${TEST_DB:-personal_test} if ! docker inspect "$PG_CONTAINER" >/dev/null 2>&1; then echo "ERROR: Could not find container '$PG_CONTAINER'" exit 1 fi # Create test database (ignore error if it already exists) docker exec "$PG_CONTAINER" psql -U "$PG_USER" -d postgres \ -c "CREATE DATABASE $TEST_DB;" 2>/dev/null || true # Wipe and rebuild schema from production (schema only, no data) echo "Copying schema from $PG_USER to $TEST_DB..." docker exec "$PG_CONTAINER" pg_dump -U "$PG_USER" --schema-only "$PG_USER" \ | docker exec -i "$PG_CONTAINER" psql -U "$PG_USER" -d "$TEST_DB" -q echo "Schema ready." bash "$(dirname "$0")/resolve-test-db.sh" echo "Integration tests can now run with: npm run test:integration"