Help us shape the future of Go! Take the 2026 Go Developer Survey

postgres

package
v1.30.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

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

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` (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, the driver is safe for concurrent reuse across N goroutines.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

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`: `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.

func NewWithDB added in v1.29.1

func NewWithDB(cfg memory.ConfigSnapshot, deps memory.Deps, db *sql.DB) (memory.MemoryStore, error)

NewWithDB constructs a memory store over a runtime-owned PostgreSQL pool. The returned store borrows db; the runtime pool manager closes it.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL