For a schema to be soft-deletable, it needs a deleted_at field, and
corresponding fields in the database.
You can use the migration helper to include deleted_at and deletion_reason
fields.
Example
use Lazarus.Migrations
create table(:my_table) do
soft_deletes()
endOptions
You can configure the following :
include_reason- determines whether or not to includedeletion_reasonfield. Set totrueby defaultdeleted_at_type- determines the type ofdeleted_atfield. Set to:utc_datetime_usecby default
Supported options:
include_reason-true,falsedeleted_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
])Project repo config
config :my_app, MyApp.Repo,
migration_soft_deletes: [
include_reason: false,
deleted_at_type: :utc_datetime
]Set up schemas
Make sure your migrations and schema match. Learn more from Schema Setup guide.