Skip to content

0.1.0-alpha.3: Postgres store

Pre-release
Pre-release

Choose a tag to compare

@Joshua-Fields Joshua-Fields released this 28 Oct 13:56
· 131 commits to main since this release
1008e32

[0.1.0-alpha.3] - 2026-10-28

The first release with the Postgres store.

Breaking

  • A write inside your own transaction returns a PendingRevision instead of a
    Revision (ADR-015): Python engine.write(..., conn=) and Rust Engine::write_in.
    Native writes still return Revision. On SQLite it is resolved at once.
    Migration: pass it as at_least=pending, or call pending.revision() after commit
    (Python); in Rust, tx.commit()? then engine.resolve(&pending)?.
    int(pending) and operator.index(pending) keep working for one release with a
    DeprecationWarning; comparisons and arithmetic do not. Rust has no transition aid.
  • For store implementers only: pemba_core::write::delete_matching returns Deleted and
    pemba_core::write::write_schema returns SchemaWritten, which carry an Applied
    (a revision, or a batch a commit trigger maps to one). Migration for stores that
    allocate revisions inside the write: .into_result() and .into_stored(source, hash).
    SqlDialect gains schema_lock, defaulting to none.
  • PendingRevision::resolved() is no longer a const fn. WritableStore gains
    resolve_batch, with a default for stores that number writes inside them.

Added

  • Postgres store (pemba-store-postgres, Postgres 15+): relationships in a schema of
    your database, revisions assigned at commit so concurrent writers stay in commit order,
    writes that join your transaction (Engine::write_in with PgTxn), GC that compacts
    and prunes, TLS through rustls. Wheels include it. See the README's Postgres section;
    benchmarks in benches/RESULTS.md.
  • PendingRevision (Rust and Python) and Engine::resolve. Python's at_least=
    accepts a PendingRevision.
  • Error codes REVISION_PENDING and WRITE_ROLLED_BACK, from Engine::resolve on a
    store that assigns revisions at commit (Python: RevisionPending and
    WriteRolledBack, both ConsistencyErrors).
  • Python: Engine.postgres(dsn, *, schema=None, pool_size=8, auto_migrate=False), whose
    calls release the GIL; write(conn=) on it joins a psycopg 3 or psycopg2 transaction,
    a SQLAlchemy Session / Connection, or django.db.connection, and works from async
    code through AsyncSession.run_sync. pemba.PembaWarning. Engine::store() in Rust.
  • Postgres: a prepared-statement cache per pooled connection (up to 256 statements,
    least recently used evicted and closed on the server). It is emptied on reconnect,
    after a schema write, and on every connection when the server reports a stale plan
    after DDL. It is not used inside your own transaction.
  • Postgres: batched writes. A write sends one statement per kind of operation (creates,
    touches, deletes), however many tuples it holds. If a create hits an existing tuple, the
    write is undone to pemba's savepoint and rerun one operation at a time, so
    AlreadyExists names the same tuple as before and your transaction stays usable. For
    store implementers: SqlDialect gains bulk_rows, defaulting to none (one statement
    per operation, as before; SQLite keeps that).
  • pemba check --color <auto|always|never>. auto, the default, is the previous
    behaviour: colour only on a terminal, and not when NO_COLOR is set. always colours
    even a pipe and overrides NO_COLOR (for less -R); never turns colour off.

Changed

  • --explain and CheckTrace::render(): when an exclusion denies because its subtracted
    side removed a granted base, both sides are now on the granting path, so the tree shows
    where the permission was granted and where it was removed. The base line is no longer
    marked (not needed).
  • --explain colour (CheckTrace::render_ansi()): evaluated nodes off the granting path,
    false ones included, are drawn in the terminal's normal colour instead of dimmed. Only
    skipped nodes and memo references are dimmed. (not needed) is printed in colour too,
    so the coloured text is the plain text plus styling.
  • --explain colour: a line on the granting path is coloured as a whole, not just its
    ✓/✗ mark: green where it granted, red where it denied (so the root of a denial is
    red), still bold. The denied: header is red. --color never output is unchanged.
  • Test-only: the cycle_passes tests read check_bulk stats from one global, always-on
    span recorder filtered to the calling thread, instead of a per-call scoped subscriber,
    the same capture as the lookup tests (#42, #43).
  • The README is written for newcomers: no internal task or decision numbers, the
    specification linked once under "Design documents", and a diagram comparing a separate
    authorisation service (two databases, dual writes) with pemba (one transaction).

Performance

  • On Postgres, latency is round trips. A direct check costs about 5 round trips. Each
    level of hierarchy it walks adds about 3, so a document 30 folders deep costs 99. A
    write costs 10 whatever its size. On a Linux CI runner where one round trip took about
    150 µs, p50 was 0.76 ms for a direct check (1.58 ms without the statement cache),
    16 ms for 30 folders (47 ms) and 19 ms for a 1,000-tuple write (407 ms). Full figures,
    with round trips for every scenario: benches/RESULTS.md. Fewer round trips for deep
    hierarchies is planned.

Fixed

  • Postgres: paging read_relationships at an older revision no longer sorts every tuple
    of the type for each page. The first 500-tuple page over 100,000 tuples went from
    106 ms to under 1 ms, because the planner had misjudged how many rows the
    older-revision filter keeps. Answers are unchanged.