pub type AuditEntry = Model;Expand description
One persisted row of the audit_log table.
Type-aliased to the SeaORM Model so query helpers can return
Vec<AuditEntry> directly without an intermediate conversion.
Aliased Type§
pub struct AuditEntry {
pub id: Uuid,
pub tenant_id: Option<String>,
pub actor_kind: String,
pub actor_id: Option<String>,
pub action: String,
pub target_kind: Option<String>,
pub target_id: Option<String>,
pub before: Option<Value>,
pub after: Option<Value>,
pub reason: Option<String>,
pub correlation_id: Option<Uuid>,
pub created_at: NaiveDateTime,
}Fields§
§id: UuidClient-generated UUIDv4 — set at write() time so the caller can
reference the entry before it hits the DB (D-21).
tenant_id: Option<String>Multi-tenant scoping; stringly-typed because ferro has no first-class tenant primitive (D-13).
actor_kind: StringSnake_case actor kind — see AuditActor::kind() in actor.rs.
actor_id: Option<String>Stringly-typed actor id; NULL for System and Anonymous (D-05).
action: StringRequired dotted-namespace action verb (e.g. "inventory.stock.adjust").
target_kind: Option<String>Target kind — NULL allowed because pure events have no target (D-10).
target_id: Option<String>Target id (consumer-stringified primary key).
before: Option<Value>JSON snapshot of the target’s state BEFORE the action. None for
creations and pure events.
after: Option<Value>JSON snapshot of the target’s state AFTER the action. None for
deletions and pure events.
reason: Option<String>Free-text reason / cause (e.g. "order_committed",
"stripe_webhook_payment_failed").
correlation_id: Option<Uuid>Caller-supplied correlation id; future framework plumbing may populate this automatically (D-12 — deferred to a later phase).
created_at: NaiveDateTimeDB-stamped timestamp (D-22); set by DEFAULT CURRENT_TIMESTAMP and
re-fetched after INSERT per RESEARCH Pitfall 1 / F-12.
Implementations§
Source§impl AuditEntry
impl AuditEntry
Sourcepub fn record(action: impl Into<String>) -> AuditEntryBuilder
pub fn record(action: impl Into<String>) -> AuditEntryBuilder
Entry point. Returns a chainable builder for an audit entry.
action is the only required field (D-10). The builder defaults
actor to AuditActor::System (D-10) and leaves every other field
at None until set. Call .write(&conn) to persist.
§Example
use ferro_audit::{AuditEntry, AuditActor, AuditTarget};
use serde_json::json;
AuditEntry::record("inventory.stock.adjust")
.actor(AuditActor::User("u_42".into()))
.target(AuditTarget::new("inventory.unit", "abc"))
.before(json!({ "quantity": 5 }))
.after(json!({ "quantity": 4 }))
.write(&conn)
.await?;