Ecto schema for accrue_meter_events — the metered billing audit
ledger and transactional outbox.
One row per Accrue.Billing.report_usage/3 call. Lifecycle:
pending— inserted insideRepo.transact/2, committed before Stripe is ever called.reported— set after a successful processor call via theAccrue.Processor.report_meter_event/1callback.reported_atis stamped.failed— set either synchronously (when the first Stripe call returns{:error, _}) or asynchronously (when Stripe emits av1.billing.meter.error_report_triggeredwebhook).
The partial index accrue_meter_events_failed_idx on
stripe_status = 'failed' gives ops a free DLQ view.
Only derived error shapes are stored in stripe_error :map — never
the raw Stripe payload.
Summary
Functions
Flips a row to failed, storing a sanitized error map in
stripe_error. Never stores the raw Stripe payload.
Builds a changeset for inserting a pending meter-event row.
Flips a committed pending row to reported, stamping reported_at.
The Stripe event struct is accepted for symmetry but no fields are
pulled from it — the row already has everything we need.
Types
@type t() :: %Accrue.Billing.MeterEvent{ __meta__: term(), customer: term(), customer_id: term(), event_name: term(), id: term(), identifier: term(), inserted_at: term(), occurred_at: term(), operation_id: term(), reported_at: term(), stripe_customer_id: term(), stripe_error: term(), stripe_status: term(), updated_at: term(), value: term() }
Functions
@spec failed_changeset(t(), term()) :: Ecto.Changeset.t()
Flips a row to failed, storing a sanitized error map in
stripe_error. Never stores the raw Stripe payload.
@spec pending_changeset(map()) :: Ecto.Changeset.t()
Builds a changeset for inserting a pending meter-event row.
@spec reported_changeset(t(), map()) :: Ecto.Changeset.t()
Flips a committed pending row to reported, stamping reported_at.
The Stripe event struct is accepted for symmetry but no fields are
pulled from it — the row already has everything we need.