feat(store): draft states and discards are journaled, posted_seq is kept (P4)
Accounting reason: a draft that waits on its receipt, and one thrown
away, are facts about the books' working papers that must survive a
restart and replay identically, or a discarded draft would come back and
hold its period open. entry.draft_state_set and entry.draft_discarded are
drafts_v2's (an older version stops at the declaration instead of
misreading them); no figure moves. Schema 19 (taken at merge as the next
after the current last): entries.posted_seq, and a draft_states table
(drafts are not rows of entries, so the plan's entries.draft_state column
has nowhere to live). posted_seq is the journal line that posted each
entry (entry.posted, entry.reversed, the line that closed a period or
posted a schedule month), identical live and on replay.
8.0.6: a hand-written line of each new shape in
books_written_under_older_rules_still_open; fixture old-books/p4_before
written by 25b52580 (hand entries posted late, a reversal, a document, a
schedule month, a recurring draft, open drafts, a close) opens to the
same figures (serialized entries omit a building state, so no golden
moved); drafts_v2_is_its_own_feature; the fuzzer and GUI journal know the
types.
Tests: draft_states_replay_and_project, drafts_v2_waits_for_the_upgrade,
posted_seq_is_the_posting_lines_seq, an_older_version_stops_at_the_draft_events.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HS8WZziDnyxunC23MUxrLp
This commit is contained in:
1 parent
be8bcf340e
commit
28d46332e4
18 files changed
+1455
-24
No files matched your search
@@ -20,7 +20,7 @@ use ledger_core::arap::{SendKind, Sent, SentVia};
|
||||
use ledger_core::conventions::{Approval, ConventionKind, NewConvention, NewDecision, NewOpenItem};
|
||||
use ledger_core::settings::{Change, Source};
|
||||
use ledger_core::{
|
||||
Annotation, AnnotationFields, ClassId, ProjectFacts, ProjectKind, ProjectStatus,
|
||||
Annotation, AnnotationFields, ClassId, DraftState, ProjectFacts, ProjectKind, ProjectStatus,
|
||||
};
|
||||
use serde_json::{Map, Value, json};
|
||||
|
||||
@@ -624,6 +624,44 @@ pub fn entry_settles_of(p: &Value) -> Result<(u64, Vec<u64>), StoreError> {
|
||||
Ok((u64_of(p, E, "entry_id")?, settles))
|
||||
}
|
||||
|
||||
/// `entry.draft_state_set {id, state, note?}` (plan P4): where a draft
|
||||
/// stands. A state is a note on the draft; it moves no figure.
|
||||
pub fn draft_state_set(id: u64, state: &DraftState) -> Value {
|
||||
let mut o = Map::new();
|
||||
o.insert("id".into(), json!(id));
|
||||
o.insert("state".into(), json!(state.key()));
|
||||
if !state.note().is_empty() {
|
||||
o.insert("note".into(), json!(state.note()));
|
||||
}
|
||||
Value::Object(o)
|
||||
}
|
||||
|
||||
/// Read an `entry.draft_state_set`: `(draft, state)`. A state this
|
||||
/// version doesn't know is newer, never corrupt (rules.md B-27).
|
||||
pub fn draft_state_set_of(line: &JournalLine) -> Result<(u64, DraftState), StoreError> {
|
||||
const E: &str = "entry.draft_state_set";
|
||||
let p = &line.payload;
|
||||
let key = str_of(p, E, "state")?;
|
||||
let note = opt_str(p, E, "note")?.unwrap_or_default();
|
||||
Ok((
|
||||
u64_of(p, E, "id")?,
|
||||
DraftState::parse(&key, ¬e).ok_or_else(|| {
|
||||
crate::format::newer_content(line, format!("the draft state {key:?}"))
|
||||
})?,
|
||||
))
|
||||
}
|
||||
|
||||
/// `entry.draft_discarded {id, reason}` (plan P4): a draft thrown away.
|
||||
pub fn draft_discarded(id: u64, reason: &str) -> Value {
|
||||
json!({"id": id, "reason": reason})
|
||||
}
|
||||
|
||||
/// Read an `entry.draft_discarded`: `(draft, reason)`.
|
||||
pub fn draft_discarded_of(p: &Value) -> Result<(u64, String), StoreError> {
|
||||
const E: &str = "entry.draft_discarded";
|
||||
Ok((u64_of(p, E, "id")?, str_of(p, E, "reason")?))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in new issue
Block a user