Skip to content

Storage Layer

Responsibility

internal/store defines the Store interface and two implementations: MemoryStore (dev/tests) and PostgresStore (production). Handlers depend on the interface, so storage is swappable and degraded mode is possible.

Store interface

Methods: Migrate, Create, Get, List, Update, Delete, Close. Errors use sentinel values from internal/model (ErrNotFound, ErrAlreadyExists).

MemoryStore

In-memory map guarded by sync.RWMutex. Migrate and Close are no-ops. Used for STORE=memory and for tests. Not persistent across restarts.

PostgresStore

  • NewPostgres opens a pgxpool.Pool and pings it.
  • Migrate creates the flags table if missing.
  • CRUD via parameterized SQL; unique violations map to ErrAlreadyExists; pgx.ErrNoRows maps to ErrNotFound.
  • Close closes the pool.

Degraded mode

If connection or migration fails, main.go leaves st nil, sets readiness false, and omits flag routes. The process still serves health and metrics.

  • openwiki/api/control-plane-api.md
  • openwiki/operations/health-and-readiness.md
  • openwiki/runtime/lifecycle.md
  • openwiki/testing/test-strategy.md