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
| Parameter | Required | Description |
|---|---|---|
action_name | Yes (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 removeResource 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:
- The governance interpreter checks the
dbcapability - The action is subject to any
policyblocks on the resource - The deletion is recorded in the behavioral ledger with the record identifier and action name
- The machine’s
ensures > permissionssection 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
| Language | Keyword |
|---|---|
| English | destroy |
| Spanish | destruir |
| French | supprimer |
| German | loeschen |
| Japanese | 削除 |
| Chinese | 销毁 |
| Korean | 삭제 |