For a schema to be soft-deletable, it needs a deleted_at field.

You can use the schema helper to include deleted_at and deletion_reason fields.

Example

use Lazarus.Schema
schema "posts" do
  soft_deletes()
end

Options

You can configure the following :

  • include_reason - determines whether or not to include deletion_reason field. Set to true by default
  • deleted_at_type - determines the type of deleted_at field. Set to :utc_datetime_usec by default

Supported options:

  • include_reason - true, false
  • deleted_at_type - :utc_datetime, :utc_datetime_usec, :naive_datetime, :naive_datetime_usec

Per-call options

soft_deletes([
  include_reason: false,
  deleted_at_type: :utc_datetime
])

Module options

@soft_deletes_opts [
  include_reason: false,
  deleted_at_type: :utc_datetime
]

Set up migrations

Make sure your migrations and schema match. Learn more from Migration Setup guide.