diff --git a/package.json b/package.json index d19f62d14..a051effde 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,8 @@ "wait-until-postgres-is-ready:pg_isready": "until pg_isready -h localhost -p ${NEXT_PUBLIC_HEXCLAVE_PORT_PREFIX:-81}28 && pg_isready -h localhost -p ${NEXT_PUBLIC_HEXCLAVE_PORT_PREFIX:-81}34; do sleep 1; done", "wait-until-postgres-is-ready": "command -v pg_isready >/dev/null 2>&1 && pnpm run wait-until-postgres-is-ready:pg_isready || sleep 10", "wait-until-clickhouse-is-ready": "echo 'Waiting for ClickHouse to be ready...' && pnpm exec wait-on -t 10000 -v http-get://localhost:${NEXT_PUBLIC_HEXCLAVE_PORT_PREFIX:-81}36/ping || echo 'ClickHouse is not ready after 10 seconds (this is probably a problem with our wait-on setup TODO fix), continuing regardless...'", - "start-deps:no-delay": "pnpm pre && pnpm run deps-compose up --detach --build && pnpm run wait-until-postgres-is-ready && pnpm run wait-until-clickhouse-is-ready && pnpm run db:init && echo \"\\nDependencies started in the background as Docker containers. 'pnpm run stop-deps' to stop them\"", + "start-deps:no-delay": "pnpm pre && pnpm run deps-compose up --detach --build && pnpm run wait-until-postgres-is-ready && pnpm run wait-until-clickhouse-is-ready && pnpm run db:init && pnpm run reseed-bulldozer && echo \"\\nDependencies started in the background as Docker containers. 'pnpm run stop-deps' to stop them\"", + "reseed-bulldozer": "pnpm pre && bash scripts/reseed-bulldozer.sh", "start-deps": "POSTGRES_DELAY_MS=${POSTGRES_DELAY_MS:-0} pnpm run start-deps:no-delay", "restart-deps": "pnpm pre && pnpm run stop-deps && pnpm run start-deps", "restart-deps:no-delay": "pnpm pre && pnpm run stop-deps && pnpm run start-deps:no-delay", diff --git a/scripts/reseed-bulldozer.sh b/scripts/reseed-bulldozer.sh new file mode 100755 index 000000000..544d8f88d --- /dev/null +++ b/scripts/reseed-bulldozer.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +# Re-seed the bulldozer-js payments store from Postgres as part of restart-deps. +# +# Why this exists: bulldozer-js keeps its state in an on-disk LMDB store that +# lives OUTSIDE Docker, so stop-deps/start-deps (which only reset the Docker +# containers) leave a stale bulldozer store behind. After a fresh Postgres seed +# that store is inconsistent, which is why we previously had to manually wipe +# apps/bulldozer-js/.data and re-run db:backfill-bulldozer-from-prisma every +# time. This script does that automatically: wipe the store, boot a temporary +# bulldozer-js, run the one-way Postgres->bulldozer backfill against it, then +# shut it back down again. +set -euo pipefail + +PORT_PREFIX="${NEXT_PUBLIC_HEXCLAVE_PORT_PREFIX:-81}" +BULLDOZER_PORT="${PORT_PREFIX}46" +REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +BULLDOZER_DIR="$REPO_ROOT/apps/bulldozer-js" + +echo "Wiping bulldozer-js LMDB store at $BULLDOZER_DIR/.data ..." +rm -rf "$BULLDOZER_DIR/.data" + +echo "Starting temporary bulldozer-js on port $BULLDOZER_PORT ..." +# Run the server directly (single node process, so we can reliably kill it) via +# tsx's node loader — the same entrypoint the package's `start` script uses. +( + cd "$BULLDOZER_DIR" && exec node --import tsx --expose-gc src/index.ts +) & +BULLDOZER_PID=$! + +cleanup() { + echo "Shutting down temporary bulldozer-js (pid $BULLDOZER_PID) ..." + kill "$BULLDOZER_PID" 2>/dev/null || true + wait "$BULLDOZER_PID" 2>/dev/null || true +} +trap cleanup EXIT + +echo "Waiting for bulldozer-js to accept connections on port $BULLDOZER_PORT ..." +pnpm exec wait-on -t 60000 "tcp:localhost:$BULLDOZER_PORT" + +echo "Running Postgres->bulldozer backfill ..." +pnpm run db:backfill-bulldozer-from-prisma + +echo "Bulldozer re-seed complete."