feat(persistence): SQLite EventStore and migrations #24
Labels
No labels
area:config
area:contracts
area:engine
area:eventsourcing
area:frontend
area:git
area:ipc
area:persistence
area:provider
area:scaffold
area:terminal
type:user-story
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
charles/peon!24
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "peon/5"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #5
Summary
migrations/001_initial.sql— complete schema from spec §12.1:eventstable (append-only event log), denormalized projection tables (projection_projects,projection_threads,projection_turns,projection_messages,checkpoints,settings), and the three required indexes (idx_events_sequence,idx_turns_thread,idx_messages_turn)persistence/migrations.rs—open_or_create_db(data_dir)creates the DB file and parent dirs if absent;run_migrationsruns sqlx embedded migrations at startup viasqlx::migrate!()persistence/event_store.rs—EventStore::new(pool),append_all(atomic batch insert withlast_insert_rowid),replay_all,replay_from(sequence); all four acceptance-criteria tests pass against in-memory SQLiteorchestration/events.rs—OrchestrationEventenum (all variants from spec §5.2),event_type_name()helper,StoredEventenvelope; defined here as required by the EventStore (blocking dependency on #4)Test plan
replay_all_on_empty_db_returns_emptyappend_single_event_replay_verifies_sequence_and_payloadappend_batch_has_contiguous_sequencesreplay_from_filters_correctlycargo fmt --checkpassescargo clippy --workspace -- -D warningspassescargo test --workspacepasses (4 new + all existing tests green)All acceptance criteria from #5 are met. Schema matches spec §12.1 exactly, all 17 event variants match spec §5.2, atomicity is correctly implemented with the transaction + rollback-on-drop pattern, and all four required tests are present and correct. One comment below on a future maintenance trap — not a blocker.
@ -0,0 +111,4 @@git_ref: String,message: String,at: DateTime<Utc>,},Maintenance trap: two sources of truth for the event type name.
event_type_name()is a manual match that returns the variant name as a&'static str.#[serde(tag = "type")]independently embeds the same string in the JSON payload. They're in sync today, but if a variant is ever renamed with#[serde(rename = "...")], the two will silently diverge: theevent_typecolumn will hold the old name while the JSON payload holds the new one, breaking any SQL query filtered by type.Suggested fix — add a unit test that cross-checks them for every variant:
This makes the CI gate catch any future drift the moment a variant is renamed.
91409319ea2c6f007713