AuroraMeter. Schema. CreditAllocation
(Aurora Meter v1.0.0)
View Source
One movement of value between two buckets of one
AuroraMeter.Schema.CreditLot, naming the ledger entry that caused it.
The allocation trail is what makes a lot's quantities reconstructible rather
than merely asserted: folding a lot's allocations in seq order reproduces
its available, reserved, consumed, reversed and expired exactly.
kind | Movement |
|---|---|
reserve | available to reserved (a hold) |
unreserve | reserved to available (a release, or a settlement below its hold) |
consume | available or reserved to consumed (a debit, a settlement, a debt repayment) |
expire | available or reserved to expired |
reverse | available, consumed or reserved to reversed (a refund or a chargeback) |
restore | reversed back to available |
from_bucket and to_bucket record the movement exactly, and they are not
redundant with kind: a consume can come out of available (a debit) or
out of reserved (a settlement against its own hold), an expire out of
either, and a reverse out of any of three. Folding a lot's allocations back
into its five quantities needs the source, and kind alone would leave it
guessing.
There is deliberately no uniqueness on (transaction_id, lot_id, kind): one
transaction legitimately produces several allocations of the same kind on
different lots, and a settlement produces both a consume and an unreserve
on the same lot. Idempotency lives on the ledger entry's
(kind, reference), which is decided before any allocation is written.
seq is the order, not inserted_at: see AuroraMeter.Schema.CreditLot.
Summary
Functions
The buckets a movement can run between.
Builds a changeset for an allocation.
The allocation kinds.
Types
@type bucket() :: :available | :reserved | :consumed | :reversed | :expired
@type kind() :: :reserve | :unreserve | :consume | :expire | :reverse | :restore
Functions
@spec buckets() :: [bucket()]
The buckets a movement can run between.
Examples
iex> AuroraMeter.Schema.CreditAllocation.buckets()
[:available, :reserved, :consumed, :reversed, :expired]
@spec changeset(t(), map()) :: Ecto.Changeset.t()
Builds a changeset for an allocation.
@spec kinds() :: [kind()]
The allocation kinds.
Examples
iex> :unreserve in AuroraMeter.Schema.CreditAllocation.kinds()
true