{"id":19984627,"url":"https://github.com/twilightcoders/deleted_at","last_synced_at":"2025-05-04T06:33:24.719Z","repository":{"id":20107023,"uuid":"23376674","full_name":"TwilightCoders/deleted_at","owner":"TwilightCoders","description":"Provides functionality to ActiveRecord::Base to delete records while keeping them in the database.","archived":false,"fork":false,"pushed_at":"2019-12-24T01:05:15.000Z","size":107,"stargazers_count":4,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2024-10-30T20:53:21.491Z","etag":null,"topics":["activerecord","postgresql","scopes","views"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/TwilightCoders.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-27T04:25:49.000Z","updated_at":"2023-08-10T16:26:35.000Z","dependencies_parsed_at":"2022-09-09T04:11:03.488Z","dependency_job_id":null,"html_url":"https://github.com/TwilightCoders/deleted_at","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TwilightCoders%2Fdeleted_at","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TwilightCoders%2Fdeleted_at/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TwilightCoders%2Fdeleted_at/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TwilightCoders%2Fdeleted_at/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TwilightCoders","download_url":"https://codeload.github.com/TwilightCoders/deleted_at/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224386495,"owners_count":17302676,"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":["activerecord","postgresql","scopes","views"],"created_at":"2024-11-13T04:19:41.940Z","updated_at":"2024-11-13T04:19:42.412Z","avatar_url":"https://github.com/TwilightCoders.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![License     ](https://img.shields.io/github/license/TwilightCoders/deleted_at.svg)]()\n[![Version     ](https://img.shields.io/gem/v/deleted_at.svg)](https://rubygems.org/gems/deleted_at)\n[![Build Status](https://travis-ci.org/TwilightCoders/deleted_at.svg)](https://travis-ci.org/TwilightCoders/deleted_at)\n[![Maintenence ](https://api.codeclimate.com/v1/badges/762cdcd63990efa768b0/maintainability)](https://codeclimate.com/github/TwilightCoders/deleted_at/maintainability)\n[![Coverage    ](https://codeclimate.com/github/TwilightCoders/deleted_at/badges/coverage.svg)](https://codeclimate.com/github/TwilightCoders/deleted_at/coverage)\n[![Dependencies](https://img.shields.io/librariesio/github/twilightcoders/deleted_at.svg)](https://depfu.com/github/TwilightCoders/deleted_at)\n\n# DeletedAt\n\nHide your \"deleted\" data (unless specifically asked for) [without resorting to](https://stackoverflow.com/a/25087337/1454158) `default_scope` by leveraging in-line sub-selects. (See the [Upgrading](#upgrading) section)\n\n## Requirements\n\n- Ruby 2.3+\n- ActiveRecord 4.1+\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'deleted_at'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install deleted_at\n\n## Usage\n\nInvoking `with_deleted_at` sets the class up to use the `deleted_at` functionality.\n\n```ruby\nclass User \u003c ActiveRecord::Base\n  with_deleted_at\n\n  # the rest of your model code...\nend\n```\n\nTo work properly, the tables that back these models must have a `deleted_at` timestamp column.\n\n```ruby\nclass AddDeletedAtColumnToUsers \u003c ActiveRecord::Migration\n\n  def change\n    add_column :users, :deleted_at, 'timestamp with time zone'\n  end\n\nend\n```\n\nIf you're starting with a brand-new table, the existing `timestamps` DSL has been extended to accept `deleted_at: true` as an option, for convenience. Or you can do it seperately as shown above.\n\n```ruby\nclass CreatCommentsTable \u003c ActiveRecord::Migration\n\n  def change\n    create_table :comments do |t|\n      # ...\n      #  to the `timestamps` DSL\n      t.timestamps null: false, deleted_at: true\n    end\n  end\n\nend\n```\n\n## Performance\n\nIt's recommended (if your database engine supports it) to add partial indexes to the `deleted_at` columns. Remember that indexes work best when they represent a minority of the rows. It's up to you to determine the best index for your table.\n\nExample 1:\n\nYou have a thriving business and your customers love your product and _rarely_ delete their account. You're likely to have way fewer rows `WHERE deleted_at IS NOT NULL`.\n\n```ruby\nclass IndexDeletedAtColumns \u003c ActiveRecord::Migration\n\n  def change\n    add_index :users, :deleted_at, where: \"deleted_at IS NOT NULL\"\n  end\n\nend\n```\n\nExample 2:\n\nYou use expiring OAuth2 tokens as part of your application's authentication process. As time grows without bound rows `WHERE deleted_at IS NULL` will pale in comparison.\n\n```ruby\nclass IndexDeletedAtColumns \u003c ActiveRecord::Migration\n\n  def change\n    add_index :oauth_tokens, :deleted_at, where: \"deleted_at IS NULL\"\n  end\n\nend\n```\n\n\n## [Upgrading](#upgrading)\n\nIf you've used `deleted_at` prior to v0.5.0, you'll need to migrate your schema. The new version of `deleted_at` no longer uses views, instead constructing a subselect on the relations. This significantly reduces code polution and monkey patching, as well as reducing the runtime memory usage for rails. Your Database will look (and be) a lot cleaner with no `deleted_at` views and your ERDs will be much cleaner as well.\n\nHere is an example of a migration for upgrading\n```ruby\nrequire 'deleted_at/legacy'\n\nDeletedAt.disable\n\nclass UpgradeDeletedAt \u003c ActiveRecord::Migration\n  def up\n    # hip hip hooray!\n    models.each do |model|\n      DeletedAt::Legacy.uninstall(model)\n    end\n  end\n\n  def down\n    # booo hiss\n    models.each do |model|\n      DeletedAt::Legacy.install(model)\n    end\n  end\n\n  private\n\n  def models\n    [\n      User,\n      Post\n    ]\n  end\nend\n\n```\n## Development\n\nAfter checking out the repo, run `bundle` to install dependencies. Then, run `bundle exec rspec` to run the tests.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/TwilightCoders/deleted_at. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwilightcoders%2Fdeleted_at","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwilightcoders%2Fdeleted_at","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwilightcoders%2Fdeleted_at/lists"}