Schema macros for soft-delete-enabled Ecto schemas.
This is the schema-facing part of Lazarus. Use it in any schema that should carry soft-delete fields or schema-level deletion metadata.
What it provides
soft_deletes/1- adds thedeleted_atfield and optionaldeletion_reasonfield@soft_deletes_opts- module-level defaults forsoft_deletes/1@hard_delete_on_cascade- associations that should hard-delete during parent cascades@hard_delete_on_replace- associations that should hard-delete duringon_replaceflows
Example
defmodule MyApp.Post do
use Ecto.Schema
use Lazarus.Schema
schema "posts" do
soft_deletes()
end
endModule defaults
Configure defaults for every soft_deletes/1 call in the module:
@soft_deletes_opts [
include_reason: true,
deleted_at_type: :utc_datetime_usec
]
schema "posts" do
soft_deletes()
endPer-call options
schema "posts" do
soft_deletes(
include_reason: true,
deleted_at_type: :utc_datetime_usec
)
endThe exact cascade and association-replacement rules are covered in the "Cascade Soft-Deletes" and "Assoc Replace" guides.
Summary
Functions
Adds soft-delete fields inside a schema block.
Functions
Adds soft-delete fields inside a schema block.
Options:
:deleted_at_type- field type for the deleted-at field. Supported values::utc_datetime,:utc_datetime_usec,:naive_datetime,:naive_datetime_usec(default::utc_datetime_usec):include_reason- adds the deletion-reason field when true (default:true)
Options passed here are merged on top of any @soft_deletes_opts configured
in the schema module.