feat(persistence): EventStore & SQLite migrations #29

Closed
claude-desktop wants to merge 1 commit from dev/5 into main
Collaborator

Summary

  • Add crates/backend/migrations/001_initial.sql with the full initial schema: append-only events table, denormalised projection tables (projection_projects, projection_threads, projection_turns, projection_messages), checkpoints, settings, and covering indexes.
  • Add crates/backend/src/orchestration/events.rs defining OrchestrationEvent (all variants with #[serde(tag = "type")]), event_type_name() discriminant helper, and StoredEvent wrapper.
  • Implement crates/backend/src/persistence/event_store.rs with EventStore:
    • open(path) — creates DB file if missing and runs migrations via sqlx::migrate!().
    • new(pool) — thin constructor for in-memory test pools.
    • append_all(events) — atomic transaction; returns Vec<StoredEvent> with auto-assigned sequence numbers.
    • replay_all() — reads all events in sequence order for startup read-model reconstruction.
    • 6 unit tests (in-memory SQLite) covering empty replay, single append, batch sequencing, ordering, content round-trip, and sequence continuity.

Closes #5

## Summary - Add `crates/backend/migrations/001_initial.sql` with the full initial schema: append-only `events` table, denormalised projection tables (`projection_projects`, `projection_threads`, `projection_turns`, `projection_messages`), `checkpoints`, `settings`, and covering indexes. - Add `crates/backend/src/orchestration/events.rs` defining `OrchestrationEvent` (all variants with `#[serde(tag = "type")]`), `event_type_name()` discriminant helper, and `StoredEvent` wrapper. - Implement `crates/backend/src/persistence/event_store.rs` with `EventStore`: - `open(path)` — creates DB file if missing and runs migrations via `sqlx::migrate!()`. - `new(pool)` — thin constructor for in-memory test pools. - `append_all(events)` — atomic transaction; returns `Vec<StoredEvent>` with auto-assigned sequence numbers. - `replay_all()` — reads all events in sequence order for startup read-model reconstruction. - 6 unit tests (in-memory SQLite) covering empty replay, single append, batch sequencing, ordering, content round-trip, and sequence continuity. Closes #5
feat(persistence): implement EventStore and SQLite migrations
Some checks failed
qa / qa (pull_request) Has been cancelled
377db167b1
Adds the event-sourcing persistence layer (issue #5):

- `crates/backend/migrations/001_initial.sql` — initial schema with
  `events` table (append-only, AUTOINCREMENT sequence), denormalised
  projection tables for projects / threads / turns / messages,
  checkpoints, settings, and covering indexes.
- `orchestration/events.rs` — `OrchestrationEvent` enum (all domain
  event variants with serde `#[serde(tag = "type")]`), `event_type_name()`
  discriminant helper, and `StoredEvent` wrapper.
- `persistence/event_store.rs` — `EventStore` with:
  - `open(path)` — creates DB file if missing and runs migrations via
    `sqlx::migrate!()`.
  - `new(pool)` — thin constructor for testing with in-memory pools.
  - `append_all(events)` — atomic transaction, returns `StoredEvent`
    slice with auto-assigned sequence numbers.
  - `replay_all()` — reads every event in sequence order for startup
    read-model reconstruction.
  - 6 unit tests covering empty replay, single append, batch sequencing,
    ordering, content round-trip, and sequence continuity.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
claude-desktop closed this pull request 2026-04-16 21:55:04 +00:00
Some checks failed
qa / qa (pull_request) Has been cancelled
Required
Details

Pull request closed

Sign in to join this conversation.
No description provided.