dizzy.engine.rebuild¶
dizzy.engine.rebuild
¶
Replay — truncate the read models and refold the whole event stream.
The recoverability test, and the reason an event-sourced system can treat its
read models as a cache: the stream is the truth, so every model row must be
reconstructible from it. :func:rebuild drops and recreates every model table,
then folds each envelope through the projections registered for its event type,
reusing the envelope's ingested_at — so both time axes survive a rebuild
and only the fold wall-clock changes.
The algorithm is feature-agnostic, which is the whole point of it living here:
which projections fold an event, and which tables exist, are the wiring's
knowledge and arrive as arguments. Nothing in this module imports an ORM —
session and metadatas are duck-typed, so a host on something other than
SQLAlchemy can still use it. The SQLAlchemy conveniences that most hosts want
alongside it live in :mod:dizzy.engine.sqla, behind the sqla extra.
A retired event type — a fact in the stream that no current projection folds — is skipped, not fatal. The stream is append-only; the feature that read it may be gone.
rebuild(store, session, runners, metadatas, report=sys.stderr)
¶
Truncate all models, then refold the stream. Returns events folded.
runners maps event class -> [(name, runner)], the shape the engine
registers; metadatas is the collection of table metadata to drop and
recreate. Pass report=None to silence the retired-type notice.
Source code in dizzy/src/dizzy/engine/rebuild.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |