Skip to main content
AccountBalance represents a time-bounded balance snapshot for a bank account, recording opening and closing booked/value figures in a specified currency alongside the valid-from/to period window. It is produced by the financial data ingestion pipeline (connector syncs) and acts as the join anchor for all Transactions, which reference the balance period they were captured within via a foreign key. Each AccountBalance belongs to exactly one Account (and transitively to one Workspace), and includes a suite of verification fields that the reconciliation pipeline populates to flag discrepancies between the bank-reported closing figure and the computed sum of transactions.

API operations

Data model

Attributes

Relationships

System-computed

  • account_balance_id: generated by PostgreSQL gen_random_uuid() on INSERT (defaultRaw). Unique constraint enforced at the database level.
  • created_at: set to new Date() by the MikroORM onCreate lifecycle hook; never writable by the API consumer.
  • updated_at: set to new Date() on both onCreate and onUpdate by MikroORM lifecycle hooks.
  • deleted_at: null on creation; set by the application soft-delete pattern. All active-record queries filter WHERE deleted_at IS NULL.
  • Partial index idx_account_balances_current on (account_pk, balance_at_from DESC, pk DESC) WHERE balance_at_to IS NULL AND deleted_at IS NULL β€” enables an index-only scan with LIMIT 1 for the β€˜current balance’ lookup pattern.
  • Partial index idx_account_balances_workspace_deleted on (workspace_pk, deleted_at) β€” optimises the Hasura permission filter (workspace_pk = $1 AND deleted_at IS NULL) on the hot read path.
  • verification_error, verification_error_detail, calculated_balance_diff, expected_balance_diff, verified_at, verification_last_run_at: all populated exclusively by the reconciliation pipeline; never set by the ingestion connector or by edge API writes.
  • raw_data: written once by the ingestion connector at sync time; treated as an immutable audit trail. Shape is connector-specific (e.g. Plaid account/balance JSON).
  • accounting_balance and foreign_exchange: written by the connector sync pipeline from provider-native balance data. Not editable via the public API.

Example

Source: apps/api/src/database/entities/AccountBalance.ts Β· domain: financial-graph Β· tier: Supporting