Skip to content

feat(vault): persist vault records in Postgres - #1477

Closed
lienhoatienphung-svg wants to merge 1 commit into
CalloraOrg:mainfrom
lienhoatienphung-svg:feat/1208-persist-vault-records-in-postgres
Closed

lienhoatienphung-svg wants to merge 1 commit into
CalloraOrg:mainfrom
lienhoatienphung-svg:feat/1208-persist-vault-records-in-postgres

Conversation

@lienhoatienphung-svg

Copy link
Copy Markdown

Closes #1208

Summary

Implements PgVaultRepository in src/repositories/vaultRepository.ts backed by pg.Pool (mapping unique constraint violations to DuplicateVaultError and missing rows to VaultNotFoundError), updates migrations/0001_create_api_keys_and_vaults.up.sql so vaults.user_id is TEXT NOT NULL and vaults.balance_snapshot is BIGINT NOT NULL DEFAULT 0, wires PgVaultRepository(pool) in src/app.ts when DATABASE_URL is configured, and runs the repository test suite against both InMemoryVaultRepository and PgVaultRepository (pg-mem).

Acceptance Criteria Mapping

  • create persists a row in vaults and throws DuplicateVaultError on duplicate (user_id, network): Enforced via UNIQUE (user_id, network) and mapped in PgVaultRepository.create.
  • findByUserId returns the persisted record across a fresh repository instance: Verified in src/repositories/vaultRepository.test.ts.
  • updateBalanceSnapshot updates balance_snapshot, last_synced_at, and updated_at, and throws VaultNotFoundError for unknown IDs: Implemented and verified in src/repositories/vaultRepository.test.ts.
  • Both InMemoryVaultRepository and PgVaultRepository pass the shared contract test suite: Verified in src/repositories/vaultRepository.test.ts.

Validation

  • npx jest src/repositories/vaultRepository.test.ts --no-cache (all 20 tests pass).

Payout Wallet (Base Mainnet USDC / EVM): 0x3806cd592a508d1992Ed007C2F53de251C2E7452

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.

Persist vault records in Postgres

2 participants