ExAudit.Repo behaviour (ex_audit v0.10.0) View Source
Adds ExAudit version tracking to your Ecto.Repo actions. The following functions are extended to detect if the given struct or changeset is in the list of :tracked_schemas given in :ex_audit config:
insert: 2, update: 2, insert_or_update: 2, delete: 2, insert!: 2, update!: 2, insert_or_update!: 2, delete!: 2
If the given struct or changeset is not tracked then the original function from Ecto.Repo is
executed, i.e., the functions are marked as overridable and the overrided implementations
call Kernel.super/1
when the given struct or changeset is not tracked.
How to use it.
Just use ExAudit.Repo
after Ecto.Repo
defmodule MyApp.Repo do
use Ecto.Repo,
otp_app: :my_app,
adapter: Ecto.Adapters.Postgres
use ExAudit.Repo
end
Shared options
All normal Ecto.Repo options will work the same, however, there are additional options specific to ex_audit:
:ex_audit_custom
- Keyword list of custom data that should be placed in new version entries. Entries in this list overwrite data with the same keys from the ExAudit.track call:ignore_audit
- If true, ex_audit will not track changes made to entities
Link to this section Summary
Callbacks
Gathers the version history for the given struct, ordered by the time the changes happened from newest to oldest.
Returns a query that gathers the version history for the given struct, ordered by the time the changes happened from newest to oldest.
Undoes the changes made in the given version, as well as all of the following versions.
Inserts a new version entry in the process, with the :rollback
flag set to true
Link to this section Callbacks
Specs
Gathers the version history for the given struct, ordered by the time the changes happened from newest to oldest.
Options
:render_struct
if true, renders the resulting struct of the patch for every version in its history. This will shift the ids of the versions one down, so visualisations are correct and corresponding "Revert" buttons revert the struct back to the visualized state. Will append an additional version that contains the oldest ID and the oldest struct known. In most cases, theoriginal
will benil
which means if this version would be reverted, the struct would be deleted.false
by default.
Specs
history_query(struct()) :: Ecto.Query.t()
Returns a query that gathers the version history for the given struct, ordered by the time the changes happened from newest to oldest.
Specs
revert(version :: struct(), opts :: list()) :: {:ok, struct()} | {:error, changeset :: Ecto.Changeset.t()}
Undoes the changes made in the given version, as well as all of the following versions.
Inserts a new version entry in the process, with the :rollback
flag set to true
Options
:preload
if your changeset depends on assocs being preloaded on the struct before updating it, you can define a list of assocs to be preloaded with this option