{"id":18895880,"url":"https://github.com/echobind/paranoid","last_synced_at":"2025-04-15T01:34:06.571Z","repository":{"id":62430271,"uuid":"122633613","full_name":"echobind/paranoid","owner":"echobind","description":"Providing soft delete and recovery capabilities for applications using Ecto. ","archived":false,"fork":false,"pushed_at":"2019-09-11T17:05:48.000Z","size":19,"stargazers_count":6,"open_issues_count":2,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-11T18:21:39.647Z","etag":null,"topics":["ecto","elixir"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/echobind.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-23T14:46:44.000Z","updated_at":"2023-09-05T12:36:33.000Z","dependencies_parsed_at":"2022-11-01T20:21:41.243Z","dependency_job_id":null,"html_url":"https://github.com/echobind/paranoid","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/echobind%2Fparanoid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/echobind%2Fparanoid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/echobind%2Fparanoid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/echobind%2Fparanoid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/echobind","download_url":"https://codeload.github.com/echobind/paranoid/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248989518,"owners_count":21194606,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ecto","elixir"],"created_at":"2024-11-08T08:30:58.348Z","updated_at":"2025-04-15T01:34:06.190Z","avatar_url":"https://github.com/echobind.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Paranoid\n\n[![CircleCI](https://circleci.com/gh/echobind/paranoid.svg?style=svg)](https://circleci.com/gh/echobind/paranoid)\n\n**Paranoid is a project providing soft delete capabilities**\n\nParanoid provides an easy mechanism for Ecto-driven projects to soft delete\nrecords in the database. This makes for easy recovery in case of accidental\ndeletion or to simply retain data.\n\n## Installation\n\n**To install simply add paranoid to your dependencies**\n\nUpdate `mix.exs` by adding Paranoid.\n\n```elixir\ndef deps() do\n  [\n    {:paranoid, \"~\u003e 0.1.4\"}\n  ]\n```\n\nOnce installed, a module must be created similar to the following.\n\n```elixir\n\ndefmodule MyApp.Paranoid do\n  use Paranoid.Ecto, repo: MyApp.Repo\nend\n```\n\nThis will become the primary method of interacting with the Ecto repo.\n\n### Setting up modules for soft delete\n\nIn order to support soft delete, each module requires a migration, an instance\nof the `use` macro, and updating the schema to include a `deleted_at`\nutc_datetime.\n\n**Migration**\n\nParanoid works by considering any non-null `deleted_at` timestamp to be\n\"deleted\". This migration adds this column.\n\n```elixir\nalter table(:your_table) do\n  add :deleted_at, :utc_datetime\nend\n```\n\n**Module Updates**\n\nParanoid makes available changesets for soft deleting and recovery of records. Leveraging `use`, we bring in these functions and make them overridable for any special use cases a project might have.\n\n```elixir\n  use Paranoid.Changeset\n```\n\nIn order to leverage the newly added field, the field must be added to your schema.\n\n```elixir\nfield(:deleted_at, :utc_datetime)\n```\n\n### Deleting Records ###\n\nDeleting records is as simple as calling `MyApp.Paranoid.delete(struct)`. If the\ngiven module has `deleted-at` as a column, it will be soft deleted. If it does not, it will simply delete the record.\n\n\n### Retrieving Soft Deleted Records\n\nBackups are only as good as their recovery. To retrieve soft deleted records, there are two steps.\n\n* Retrieve the deleted record\n* Undelete the record\n\n```elixir\n# retrieve soft deleted user by adding opts of `include_deleted: true`\nuser = MyApp.Paranoid.get(MyApp.User, 1, include_deleted: true)\n\n# undelete! the user by setting the deleted_at timestamp to nil\nMyApp.Paranoid.undelete!(user)\n\n```\n\nLeveraging `MyApp.Paranoid`, an application can call any of the available\n`Ecto.Repo` functions. These will respect the `deleted_at` flag wherever\nappropriate. Additionally, these functions will retrieve soft deleted records\nwhen the option `include_deleted` is present.\n\n## License\n\nParanoid is free software and distributed under the MIT license. More information can be found in the [LICENSE](/LICENSE) file.\n\n## About Echobind\n\nEchobind is a software development consultancy that specializes in Elixir. If you have a software project that needs another set of eyes, learn more at our\n[website][website].\n\n[website]: https://echobind.com?utm_source=paranoid\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fechobind%2Fparanoid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fechobind%2Fparanoid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fechobind%2Fparanoid/lists"}