PhoenixKitCRM.SoftDelete (PhoenixKitCRM v0.2.4)

Copy Markdown View Source

Status-column soft-delete shared by Contacts and Companies.

Trashing stashes the record's current status in metadata["trashed_from_status"] and sets status to the schema's soft-delete sentinel; restoring reverses it (falling back to "active" if the stashed status is no longer valid). Works on any schema with a status string column and a metadata map column. The contexts keep the already-trashed/not-trashed guards and the repo().update/1 call; only the changeset-building lives here.

Summary

Functions

Changeset that restores record: pop the stashed status (or "active" if it isn't one of valid_statuses), clearing the stash key.

Changeset that trashes record: stash the current status, set sentinel.

Functions

restore_changeset(record, valid_statuses)

@spec restore_changeset(
  struct(),
  [String.t()]
) :: Ecto.Changeset.t()

Changeset that restores record: pop the stashed status (or "active" if it isn't one of valid_statuses), clearing the stash key.

trash_changeset(record, sentinel)

@spec trash_changeset(
  struct(),
  String.t()
) :: Ecto.Changeset.t()

Changeset that trashes record: stash the current status, set sentinel.