AshVersioned. Resource. ManualIncrement
(ash_versioned v0.1.0)
Copy Markdown
Implements the core atomic primitive for AshVersioned.Resources: mark the current
latest row as stale and insert a new version in a single transaction. This works for all
update actions and, if the resource has archive set, destroy actions.
Increment is implemented as a bulk update scoped to the current row's primary key and
latest flag. This acts as an optimistic locking signal so that a concurrent update that
commits earlier will force this to fail with Ash.Error.Changes.StaleRecord instead of
reinserting on top of already-stale data.
AshVersioned performs the increment in a transaction that does the following:
- Captures the change timestamp
- Updates the old version latest flag (to false) and the update timestamp
- Clears the primary key
- Copies the versioned resource's identity field
- Increments the version number by 1
- Sets the latest flag to true
- Sets the creation and update timestamps to the captured change timestamp
- Applies the actor attributions from the context
- Copies all other writable or non-generated values from the old resource changeset or data to the new resource; this includes the archived field (if present)
Summary
Functions
Increments a new version for the resource on update.