Expand description
Postgres backend for the audit log.
Wire-compatible with AWS RDS / Aurora, GCP Cloud SQL + AlloyDB, Azure Database for PostgreSQL Flexible Server, Supabase (direct + pooler), Neon (direct + pooler), and self-hosted Postgres.
§Connection lifecycle
PostgresStore::connect takes a PostgresConfig (URL plus pool +
statement-cache tuning) and returns a configured sqlx::PgPool. The
same pool is used for every request — sqlx handles connection reuse,
retry on broken connections, and TLS via rustls.
On connect, PostgresStore::initialize runs ordered, transactional schema
migrations under a database advisory lock. Existing installations created
before migration tracking are adopted by migration 1 without dropping or
rewriting rows. The schema mirrors SQLite field-for-field; the only dialect
difference is BIGINT NOT NULL UNIQUE for seq. created_at remains
TEXT (RFC 3339 with Z suffix) in both backends and is cast to
timestamptz for interval arithmetic.
§Concurrency
Like the SQLite path, the chain-hash + seq computation is wrapped in a
BEGIN ... COMMIT block. Postgres serialises this naturally via
row-level locks on the seq write; we use a SELECT … FOR UPDATE on
the most-recent row so concurrent writers see the same predecessor and
the second commit fails atomically rather than corrupting the chain.
Structs§
- Postgres
Config - Configuration for the Postgres backend. Built by
main.rsfrom[storage]inconfig.toml. - Postgres
Store - Postgres-backed
AuditStore.