seed-fixture.sh 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env bash
  2. # Loads scripts/fixture.sql into the LOCAL .wrangler D1 (never the remote one:
  3. # --local is on every command here, and nothing in this repo writes production).
  4. #
  5. # The schema comes from the writer, telemetry-worker/migrations/, because that
  6. # is where it belongs — D1 is read-only from this worker.
  7. #
  8. # ./scripts/seed-fixture.sh (or: npm run seed)
  9. set -uo pipefail
  10. cd "$(dirname "$0")/.."
  11. DB=codegraph-telemetry
  12. MIGRATION=../telemetry-worker/migrations/0001_init.sql
  13. if [[ ! -f "$MIGRATION" ]]; then
  14. echo "seed: cannot find $MIGRATION — run this from a full checkout" >&2
  15. exit 1
  16. fi
  17. # The migration is plain CREATE TABLE, so a second run fails on "table already
  18. # exists". That is the expected steady state here, hence the swallowed output —
  19. # the fixture load below is the step whose failure actually matters.
  20. npx wrangler d1 execute "$DB" --local --file="$MIGRATION" >/dev/null 2>&1
  21. if ! npx wrangler d1 execute "$DB" --local --file=scripts/fixture.sql >/dev/null; then
  22. echo "seed: loading scripts/fixture.sql failed" >&2
  23. exit 1
  24. fi
  25. echo "seed: fixture loaded into the local $DB (12 machines, 2026-07-01 … 2026-07-10)"