Skip to content

destroy

destroy

A destroy action on a store resource. Removes a record from the database. Destroy actions can be declared as named actions or included in the defaults shorthand. Compiles to an Ash Framework destroy action at runtime.

When to use

Use destroy when you need to:

  • Permanently delete a record from a store resource
  • Remove records as part of a machine’s workflow (e.g., cleanup, expiration)
  • Allow governed deletion with policy checks

For most resources, defaults: [destroy] is sufficient. Define a named destroy action when you need custom logic, such as soft-delete behavior or cascade restrictions.

Syntax

Using defaults shorthand

resource <resource_name>
defaults: [destroy]

Named destroy action

resource <resource_name>
destroy <action_name>

Parameters

ParameterRequiredDescription
action_nameYes (for named actions)Bare identifier naming this action. If using defaults: [destroy], the action is named destroy automatically.

Examples

Standard destroy via defaults

resource session
id as uuid, is primary_key
user_id as uuid, is required
expires_at as datetime
timestamps
defaults: [read, destroy]

Named destroy action

resource document
id as uuid, is primary_key
title as text, is required
archived as boolean, default: false
timestamps
destroy remove

Resource with policy-gated deletion

resource project
id as uuid, is primary_key
name as text, is required
owner_id as uuid, is required
timestamps
destroy delete_project
policy action_type(destroy)
authorize_if actor_attribute(role, "admin")
forbid_if always()

Only actors with the "admin" role can delete projects. All other actors are forbidden.

Governance

Destroy actions are governed effects. When a machine executes a destroy action:

  1. The governance interpreter checks the db capability
  2. The action is subject to any policy blocks on the resource
  3. The deletion is recorded in the behavioral ledger with the record identifier and action name
  4. The machine’s ensures > permissions section can restrict or require approval for deletions

Destroy is the most consequential data action. Consider using policies to restrict who can delete records, and consider soft-delete patterns (an archived boolean field with an update action) for data that should be recoverable.

Translations

LanguageKeyword
Englishdestroy
Spanishdestruir
Frenchsupprimer
Germanloeschen
Japanese削除
Chinese销毁
Korean삭제

See also

  • resource - Resource declarations
  • create - Create actions for inserting data
  • read - Read actions for querying data
  • update - Update actions for modifying records
  • policy - Authorization policies on actions