Skip to content

test(indexer): add database integration suite and migration runner - #29

Open
plbogen2 wants to merge 1 commit into
YieldAnchor:mainfrom
plbogen2:test/indexer-database-integration
Open

plbogen2 wants to merge 1 commit into
YieldAnchor:mainfrom
plbogen2:test/indexer-database-integration

Conversation

@plbogen2

@plbogen2 plbogen2 commented Oct 19, 2026 •

Copy link
Copy Markdown

Summary

Closes #9.

This pull request adds an integration testing tier for database migrations and indexer projections against PostgreSQL. The suite exercises event ingestion, foreign key tolerance, and checkpoint persistence to verify that the indexer handles out-of-order streams without corrupting ledger state. All tests pass.

Key Changes

  • Add migration runner script pnpm run db:migrate. It applies database/migrations/001_create_tables.sql and database/migrations/002_create_protocol_tables.sql in numeric sequence.
  • Add integration test suite in services/indexer/test/database-integration.test.ts. Tests require PostgreSQL.
  • Export projectEvents in services/indexer/src/watcher.ts. This allows testing multi-event batches that write to vaults and vault_events.
  • Update database/schema/README.md. The document explains migration commands and integration test execution.

Test Coverage

  • Idempotent replay: Replaying duplicate Soroban event_id records ignores redundant writes and preserves exact 128-bit base unit amounts (numeric(40,0)).
  • Batch coherence: Processing an initialize event alongside a deposit event in a single batch populates both vaults and vault_events records.
  • Foreign key tolerance: Events arriving before the corresponding vault row project successfully into the database without dropping records.
  • Checkpoint persistence: Checkpoint save and load cycles round-trip through indexer_checkpoints at Number.MAX_SAFE_INTEGER (9_007_199_254_740_991). Out-of-range ledgers narrow to 0.
  • Hermetic default: The integration suite skips execution when database environment variables are unset. Offline runs remain hermetic.

Add integration test suite in services/indexer/test/database-integration.test.ts
exercising event projection, multi-event batch writes, foreign key tolerance,
and checkpoint resume against PostgreSQL. Add db:migrate script to run SQL
migrations in sequence and export projectEvents from watcher for test execution.

Closes YieldAnchor#9
@plbogen2 plbogen2 changed the title test(indexer): add database-backed integration tests for projection and checkpoint resume test(indexer): add database integration suite and migration runner Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: add database-backed integration tests for the indexer projection and checkpoint resume

2 participants