feat(postgres): wire the State Store to Postgres — DB URL, fail-closed pool, composition seam

Wave 1 of the Postgres migration (archie-core-7r0x.9). This is the shared shape
every port lane builds on; nothing here switches a live path to Postgres yet.

- config: add `database_url` beside `db_path` (config.go), mark it bootstrap-only
  in denied_keys, expose it in the webui StorageView/config schema, and add it to
  config.example.toml plus all deployments/*.toml.
- docker-compose: add a postgres:18 service; `task dev` (dev:postgres) brings it
  up and waits for it before the State Store boots.
- archied: `openStateStore` now opens and migrates the process-scoped Postgres
  pool via `openStateStorePool`. The State Store fails closed (D1.2) when
  database_url is absent or invalid rather than fall back to SQLite; serving
  against Postgres later requires an import-completion record (D1.3), which is a
  later lane's gate, not this one.
- composition seam: task-store construction (state_store_task.go) and EDA-store
  construction (state_store_eda.go) are extracted from openStateStore, with the
  pool open in state_store_pool.go. This is a behaviour-preserving refactor only
  — no store, interface, error, ordering or logging change — so L1 and L2 build
  against separate files instead of sharing state_store.go.

Tests: fail-closed pool behaviour is pinned (absent/invalid URL); the State Store
boot/restart tests now run against a throwaway Postgres 18 container (pgtest
TestMain). Scoped test command and module-wide build pass; see lane report.
This commit is contained in:
sam committed 2026-09-24 02:18:56 +10:00
1 parent 05ee5eff31
commit 757b75de94
25 files changed
+294 -62

No files matched your search

+22
View File
@@ -387,6 +387,25 @@ tasks:
Ctrl-C stops all five.
deps: [dev:daemon, dev:gateway, dev:state-store, dev:dashboard, dev:ui]
dev:postgres:
desc: "Start the dev PostgreSQL 18 service and wait until it accepts connections (prefer `task dev`)"
cmds:
- docker compose up -d postgres
# `up -d` returns before the container is ready; wait for its
# healthcheck so the State Store (which fails closed on a bad URL) does
# not race the boot.
- |
set -eu
for _ in $(seq 1 60); do
status=$(docker inspect --format '{{.State.Health.Status}}' "$(docker compose ps -q postgres)" 2>/dev/null || true)
if [ "$status" = "healthy" ]; then
exit 0
fi
sleep 1
done
echo "postgres did not become healthy within 60s" >&2
exit 1
dev:daemon:
desc: archied only, live-reloading via air (prefer `task dev`)
cmds:
@@ -399,6 +418,9 @@ tasks:
dev:state-store:
desc: archie-state-store only, no live-reload (prefer `task dev`)
# The State Store fails closed without a PostgreSQL URL (Postgres-only
# epic), so bring the Compose service up and wait for it before booting.
deps: [dev:postgres]
cmds:
- go run ./cmd/archie-state-store -config-overlay deployments/dev.toml