Entities 0.2.0: A trash for records, with restore and delete forever
Entities 0.2.0 adds a trash for entity records. Deleting a record now moves it to the trash, where it can be restored or deleted for good, so records that other parts of your app point at are not lost by mistake.
The trash in the data navigator
The data navigator gets a Trash filter with a count of trashed records. Records get a Move to trash button, and each trashed record has Restore from trash and Delete forever buttons. The bulk action bar changes with the view: on the normal views it offers Archive, Restore and Trash, and in the trash it offers Restore and Delete forever. Every bulk button now shows that it is working while the action runs.
Trashed records are left out of the normal lists, searches and counts, and out of mirror exports, so they do not come back on the next export. A trashed record keeps its slug, so a new record cannot take it while the old one is in the trash. A record restored from the trash returns as a draft. Toggling a record’s status skips the trashed state; restoring is the only way out.
The message after trashing a record says to restore it within 90 days, but this release has nothing that empties the trash on its own.
When other tables point at a record
Your app may keep foreign keys to entity records, for example an order’s status. Deleting such a record forever used to fail with a server error. It now returns a clear message instead. An app can also list, in the :reverse_references setting of :phoenix_kit_entities, functions that count the rows using a record, to show “used by” hints; they do not block a delete.
Other changes
The public form’s check for private network addresses no longer accepts values like 123abc, and the sitemap source now logs the errors it used to hide.
Upgrading
No migration: the trash is a new record status. Code that calls delete/2 or bulk_delete/2 and matches only {:ok, _} and a changeset error should also handle {:error, :referenced_by_external}. Bulk delete in the navigator now moves records to the trash; deleting forever happens from the trash view.
Full release notes: Entities 0.2.0
0.2.0 · 4 May 2026
Added
- Soft-delete for
EntityData(issue #12) — keeps rows alive when parent apps hold FK references (e.g.orders.status_uuid→phoenix_kit_entity_data.uuid). New status sentinel"trashed"joins the existing{draft, published, archived}set; no migration required. - New public API on
PhoenixKitEntities.EntityData:trash/2,restore_from_trash/2,bulk_trash/2,bulk_restore_from_trash/2,list_trashed_by_entity/2,trashed_count/1. count_external_references/1andcount_external_references/2— readsApplication.get_env(:phoenix_kit_entities, :reverse_references, [])(a list of{entity_name, count_fn}tuples) so parent apps can surface “used by N rows” hints. The 2-arity form takes a pre-loaded entity to skip the per-call preload when rendering many records. Informational only — not a delete-blocker.- Three new error atoms in
PhoenixKitEntities.Errors::already_trashed,:not_trashed,:referenced_by_externalwith localized messages. - DataNavigator admin UX: Trash filter view with count badge, per-row Restore-from-trash + Delete-forever buttons on trashed records, bulk-action bar branches by view (Archive/Restore/Trash on default views; Restore/Delete-forever on the Trash view).
- 130 net new tests —
entity_data_trash_test.exs(49 tests) builds transient_trash_test_parenttables that mirror issue #12’s exactNOT NULL REFERENCES … ON DELETE RESTRICTshape, exercising FK-violation paths against a real parent FK. New describe block indata_navigator_live_test.exs(18 tests) covers all event handlers + authorization + bulk-bar branching. - AGENTS.md gained a “Soft-delete (trash) for EntityData” section documenting the parent-app FK motivation, public API, default-list filtering rules, slug uniqueness rationale, and the
:reverse_referencesconfig hook.
Changed
delete/2andbulk_delete/2now catchEcto.ConstraintError(foreign-key) andPostgrex.Error(SQLSTATE23503/23502) and return{:error, :referenced_by_external}instead of raising. The admin UI flashes a friendly message rather than a 500. Soft return-shape change — callers exhaustively pattern-matching{:ok, _} | {:error, %Ecto.Changeset{}}should add a clause for the new atom.- Default-list queries (
list_all/1,list_by_entity/2,search_by_title/3,count_by_entity/2) exclude trashed records by default. Passinclude_trashed: trueto opt in (admin trash views, reverse-reference checks). Mirror exporter inherits this exclusion — trashed records won’t resurrect on re-export. get_data_stats/1now returnstrashed_recordsseparately;total_recordsreflects the visible (non-trashed) count.get_by_slug/2deliberately surfaces trashed rows so slug uniqueness is preserved across the trash bin.- DataNavigator bulk Delete repurposed → soft-trash; permanent delete is a separate action available only from the Trash filter view.
toggle_statuscycle skips trashed (Restore is the only escape).phx-disable-withadded to all 8 bulk-action buttons (3 from soft-delete additions + 5 pre-existing oversights).entity_form_controller.exprivate_or_local_ip?/1swapped fromString.to_integer + rescue _toInteger.parse/1with explicitwith/elsechain — pins{int, ""}so"123abc"no longer slips through as123.sitemap_source.exsub_sitemaps/1rescue _ -> nilnow logs the error inspect, matching the canonical pattern at the other two rescues in the file.sitemap_source.exenabled?/0gainedcatch :exit, _ -> falseto match the boot-resilience shape fromphoenix_kit_entities.ex(sandbox-shutdown signals).@specbackfill onlist_trashed_by_entity/2andtrashed_count/1.
Entities 0.2.0. Install or update: {:phoenix_kit_entities, "~> 0.2"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.