Lazarus.Schema (lazarus v1.0.0)

Copy Markdown View Source

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 the deleted_at field and optional deletion_reason field
  • @soft_deletes_opts - module-level defaults for soft_deletes/1
  • @hard_delete_on_cascade - associations that should hard-delete during parent cascades
  • @hard_delete_on_replace - associations that should hard-delete during on_replace flows

Example

defmodule MyApp.Post do
  use Ecto.Schema
  use Lazarus.Schema

  schema "posts" do
    soft_deletes()
  end
end

Module 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()
end

Per-call options

schema "posts" do
  soft_deletes(
    include_reason: true,
    deleted_at_type: :utc_datetime_usec
  )
end

The 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

soft_deletes(opts \\ [])

(macro)

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.