Skip to main content

ChangeLogWrite

Struct ChangeLogWrite 

Source
pub struct ChangeLogWrite<'a> {
    pub object_type: &'a str,
    pub modification_type: &'a str,
    pub tenant_id: Option<Uuid>,
    pub trace_id: Option<&'a str>,
    pub schema_version: Option<&'a str>,
    pub trace_context: Option<&'a str>,
    pub actor_type: Option<&'a str>,
    pub acting_for: Option<Uuid>,
    pub pre_image: bool,
}
Expand description

The framework-owned change-log row the mutation executor writes in-txn.

Carries only the fields the adapter cannot derive from the app.mutation_response row it already holds: the DML verb and a NOT-NULL object_type fallback. The changed-entity identity + payload (object_id, object_data, updated_fields, cascade) are read from the function’s own returned row inside the same transaction (see DatabaseAdapter::execute_function_call_with_changelog).

This is the Change Spine transactional-outbox contract. Beyond the object_type/modification_type + changed-entity columns, it stamps the envelope: tenant_id (carried here, from SecurityContext), trace_id (the W3C trace id of the originating request), schema_version (the compiled schema’s content hash — a per-deployment constant), trace_context (the full W3C trace context as JSON), actor_type / acting_for (the request’s actor classification and, for a delegated agent, the underlying human — #390), commit_time (clock_timestamp() at INSERT), and seq (the table’s SEQUENCE default).

Fields§

§object_type: &'a str

NOT-NULL fallback for object_type when the row’s entity_type is NULL. Sourced from MutationDefinition.return_type (always present).

§modification_type: &'a str

The DML verb written to modification_type (e.g. "INSERT", "UPDATE", "DELETE", "CUSTOM"), from MutationOperation.

§tenant_id: Option<Uuid>

The tenant partition stamp written to the tenant_id UUID column — the Trinity public-facing identifier, read from SecurityContext.tenant_id at write time and never reconstructed from connection / RLS state (RLS is PG-only; out-of-session spine consumers bypass it, so the row must carry tenant identity explicitly). None (→ SQL NULL) for an unauthenticated request, a request with no tenant, or a tenant identifier that is not a UUID.

§trace_id: Option<&'a str>

The W3C trace id of the originating request, written to the trace_id column so an outbox row links back to its distributed trace (the #392 perf tooling surfaces it as the investigation handle). Read from the request’s traceparent header at write time; None (→ SQL NULL) for a request without a trace context — e.g. an unauthenticated mutation, which carries no SecurityContext to stamp.

§schema_version: Option<&'a str>

The compiled schema’s version written to the schema_version column so an outbox row records which deployment produced it — the replay / zero-downtime correctness handle for #378 (reject a row replayed under a different schema). A per-deployment constant derived from the compiled schema (CompiledSchema::content_hash()), not from the request, so it changes on any schema change. None (→ SQL NULL) for producers with no compiled schema in scope — cooperative external producers (ETL) and the non-PostgreSQL no-op path.

§trace_context: Option<&'a str>

The originating request’s full W3C trace context as a JSON object ({version, trace_id, parent_id, trace_flags, tracestate?}), written to the trace_context JSONB column so a row carries enough to re-propagate / reconstruct the distributed trace — not just the scalar trace_id. Carried here as pre-serialized JSON text (the adapter binds it to the JSONB column). Built from the request’s traceparent / tracestate headers at write time; None (→ SQL NULL) for a request without a valid trace context, consistent with trace_id.

§actor_type: Option<&'a str>

The request’s actor classification written to the actor_type column (the snake_case ActorType token: "human_user", "service_account", "ai_agent", "system_job"), from SecurityContext.actor_type() at write time (#390). None (→ SQL NULL) for a request with no SecurityContext to stamp (an unauthenticated mutation), or a cooperative external producer.

§acting_for: Option<Uuid>

For a delegated agent request, the underlying human the agent acts for — the public-facing UUID, written to the acting_for UUID column from SecurityContext.acting_for() (#390). Mirrors tenant_id’s UUID shape so it is stamped without a DB lookup. None (→ SQL NULL) for a non-delegated request, an unauthenticated mutation, or a subject that is not UUID-shaped.

§pre_image: bool

Whether this outbox write also records the changed entity’s pre-image (before-state) into the object_data_before JSONB column, sourced from the function’s own entity_before (the after-image comes from entity). Set from MutationDefinition.changelog_pre_image; false (the default) leaves object_data_before out of the INSERT entirely (NULL), byte-for-byte today’s behavior. The changed-entity payload itself is read from the returned row inside the outbox CTE, so this flag only selects which SQL form the adapter emits.

Implementations§

Source§

impl<'a> ChangeLogWrite<'a>

Source

pub const fn new(object_type: &'a str, modification_type: &'a str) -> Self

Build a change-log write descriptor with no envelope stamps (tenant_id, trace_id, schema_version, trace_context, actor_type and acting_for NULL). Chain with_tenant_id / with_trace_id / with_schema_version / with_trace_context / with_actor_type / with_acting_for to stamp them.

Source

pub const fn with_tenant_id(self, tenant_id: Option<Uuid>) -> Self

Stamp the tenant partition id (the Trinity public-facing UUID) onto the outbox row. None leaves tenant_id NULL — for system / unauthenticated rows, or a tenant identifier that is not UUID-shaped.

Source

pub const fn with_trace_id(self, trace_id: Option<&'a str>) -> Self

Stamp the originating request’s W3C trace id onto the outbox row. None leaves trace_id NULL — for a request with no trace context.

Source

pub const fn with_schema_version(self, schema_version: Option<&'a str>) -> Self

Stamp the compiled schema’s version (its content hash) onto the outbox row. None leaves schema_version NULL — for producers with no compiled schema in scope (cooperative external producers, the non-PostgreSQL no-op path).

Source

pub const fn with_trace_context(self, trace_context: Option<&'a str>) -> Self

Stamp the originating request’s full W3C trace context (pre-serialized JSON text) onto the outbox row’s trace_context JSONB column. None leaves it NULL — for a request with no valid trace context, or a non-PostgreSQL no-op / cooperative producer.

Source

pub const fn with_actor_type(self, actor_type: Option<&'a str>) -> Self

Stamp the request’s actor classification (the snake_case ActorType token) onto the outbox row’s actor_type column (#390). None leaves it NULL — for an unauthenticated mutation or a cooperative producer.

Source

pub const fn with_acting_for(self, acting_for: Option<Uuid>) -> Self

Stamp the delegated user’s UUID (the human a delegated agent acts for) onto the outbox row’s acting_for column (#390). None leaves it NULL — for a non-delegated request, an unauthenticated mutation, or a non-UUID subject.

Source

pub const fn with_pre_image(self, pre_image: bool) -> Self

Opt this outbox write into recording the changed entity’s pre-image into the object_data_before column (from the function’s entity_before). When false (the default), object_data_before is omitted from the INSERT entirely, byte-for-byte today’s behavior. Set from MutationDefinition.changelog_pre_image.

Trait Implementations§

Source§

impl<'a> Clone for ChangeLogWrite<'a>

Source§

fn clone(&self) -> ChangeLogWrite<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for ChangeLogWrite<'a>

Source§

impl<'a> Debug for ChangeLogWrite<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for ChangeLogWrite<'a>

§

impl<'a> RefUnwindSafe for ChangeLogWrite<'a>

§

impl<'a> Send for ChangeLogWrite<'a>

§

impl<'a> Sync for ChangeLogWrite<'a>

§

impl<'a> Unpin for ChangeLogWrite<'a>

§

impl<'a> UnsafeUnpin for ChangeLogWrite<'a>

§

impl<'a> UnwindSafe for ChangeLogWrite<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more