Documentation
¶
Overview ¶
Package postgres is Harbor's Postgres-backed `memory.MemoryStore` driver. It is the third leg of the memory persistence triad (in-memory, SQLite, Postgres) defined by RFC §6.6 + §9.
The driver uses `pgx/v5/stdlib` so the rest of Harbor sees a `database/sql.DB`. Parametric queries everywhere; no string concatenation into SQL (AGENTS.md §9). Advisory locks serialise the migration runner so multi-replica boots are race-free.
Strategy delegation (Phase 25a, D-174) ¶
All three memory strategies (`none`, `truncation`, `rolling_summary`) are implemented by the driver-agnostic `internal/memory/strategy` executor package; this driver is a thin shell that owns the boundary (identity validation + the `memory.identity_rejected` emit + the `closed` flag) and delegates every `MemoryStore` method to a `strategy.StrategyExecutor`. The executor persists state through the injected `state.StateStore` (D-027 typed wrapper, `Kind = "memory.state"`). When that StateStore is itself Postgres-backed (the operator's `state.driver: postgres`), the memory strategies persist durably — which is what makes `truncation` / `rolling_summary` survive a restart. No strategy algorithm is reimplemented in SQL here.
The driver still opens its own `*sql.DB` against `cfg.DSN` and runs its embedded `memory_state` migration so a misconfigured DSN fails loudly at boot, but the live read/write path rides entirely on the executor's `state.StateStore` writes. The driver's own `memory_state` table is vestigial under delegation; it is kept (never edited — migrations are forward-only, AGENTS.md §9 / §13) for back-compat with rows written by the pre-25a strategy=none path.
Per AGENTS.md §5 (D-025), the driver is safe for concurrent reuse across N goroutines.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(cfg memory.ConfigSnapshot, deps memory.Deps) (memory.MemoryStore, error)
New constructs a Postgres-backed `memory.MemoryStore` against `cfg.DSN`. Production callers go through `memory.Open`; tests may call `New` directly to skip the registry.
The configured strategy is resolved by the shared `strategy.StrategyExecutor` (Phase 25a, D-174): `none`, `truncation`, and `rolling_summary` all delegate to the executor, which persists through `deps.State`. `rolling_summary` requires a non-nil `deps.Summarizer`; the executor's `New` rejects a nil summariser for that strategy — fail loudly, never a stub fallback (AGENTS.md §13).
`deps.Bus` is required. `deps.State` is required — it is the persistence floor the strategy executor writes through.
Types ¶
This section is empty.