Documentation
¶
Overview ¶
Package postgres is Harbor's Postgres-backed `memory.MemoryStore` driver (Phase 25). 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.
Memory state lives in its OWN `memory_state` table — the Postgres memory driver does NOT piggyback on the Postgres StateStore driver's `state_records` table. The injected `state.StateStore` dep is accepted to satisfy the shared `memory.Deps` contract but is unused; the `events.EventBus` dep IS used (for the fail-closed identity-rejection emit path).
Internal model:
- One row per `(tenant_id, user_id, session_id, run_id, kind)`. `run_id` may be empty (session-scoped); the column is NOT NULL but accepts the empty string.
- `bytes` is BYTEA — opaque JSON-serialised `memory.Record` envelope (see `internal/memory/wire.go`).
- `strategy` is denormalised onto its own column for grep-ability; the same value lives inside `bytes`.
- `Close(ctx)` flips an atomic flag BEFORE `db.Close()` so subsequent calls fast-fail with `ErrStoreClosed` even while in-flight queries are draining.
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.
Strategy unsupported at Phase 23/25 (anything other than `StrategyNone` or empty-equivalent) returns `ErrStrategyNotImplemented`. Phase 24 widens the supported set; the Postgres driver will inherit that widening automatically through the shared conformance suite.
`deps.Bus` is required. `deps.State` is accepted but unused.
Types ¶
This section is empty.