Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Soft deleting #41

Closed
26 tasks done
ozziest opened this issue Jun 3, 2021 · 1 comment · Fixed by #139
Closed
26 tasks done

Soft deleting #41

ozziest opened this issue Jun 3, 2021 · 1 comment · Fixed by #139
Labels
discussion Something that should be discussed documentation Improvements or additions to documentation enhancement New feature or request
Projects

Comments

@ozziest
Copy link
Member

ozziest commented Jun 3, 2021

What is a soft delete?

A soft delete marks a record as no longer active or valid without actually deleting it from the database. Soft deletes can improve performance, and can allow “deleted” data to be recovered. [*]

Motivations

Developers should be able to add soft-delete features to the models.

Implementation

To add a soft-delete feature to a model, developers must add the following code to the model file;

class User extends Model {
  get deletedAtColumn(): string {
    return "deleted_at";
  }
}

deletedAtColumn should return NULL from the base Model. If developers add a database field name, it means that we have a soft-deleting feature for this model. Developers must create a timestamps data field on the database via migrations.

Soft-Deleting Record

The DELETE handler must work as the soft-deleting if there is soft-deleting support. Otherwise, it must work like a normal delete.

On the other hand, developers should be able to add FORCE_DELETE handler to models like the following example to support the force delete feature;

const { INSERT, PAGINATE, DELETE, FORCE_DELETE } = HandlerTypes;

class User extends Model {
  get handlers(): HandlerTypes[] {
    return [INSERT, PAGINATE, DELETE, FORCE_DELETE];
  }
}

Queries

Clients should not be able to see the soft-deleted records in queries (PAGINATE, SHOW). Also, clients should not be able to manipulate the soft-deleted records (UPDATE, PATCH).

In addition, the with keyword that fetches the related data should work with the soft-deleting feature perfectly.

Also, related data fetch must work perfectly with soft deleting. For example; the /api/users/1/posts request should check if the user 1 is soft-deleted or not. (#132)

Force Delete Handler

This would be a new handler for force deleting.

DELETE /api/users/:id/force

Listing deleted values

Clients should be able to fetch soft-deleted records from a database. To do that, they must use the following command;

/api/users?trashed=true

This should be configurable. By default, it should be false.

Hooks & Events

The following hooks and events should be supported for the force-delete handler;

  • onBeforeForceDeleteQuery
  • onAfterForceDeleteQuery
  • onBeforeForceDelete
  • onAfterForceDelete

Todo List

  • Add the deletedAtColumn column to the base Model
  • Change the DELETE handler works.
  • Add the FORCE_DELETE handler.
  • Change the basic queries.
  • Change the with operator works.
  • Add the trashed parameter to the queries.
  • Check the soft-deleting feature for PUT, PATCH
  • Add new hooks.
  • Add the related query checks for the soft-deleting feature (/api/users/1/posts)

Acceptance Criteria

  • Users should be able to soft delete (DELETE)
  • Users should not be able to see the soft-deleted records (PAGINATE, SHOW, ALL)
  • Users should not be able to update the soft-deleted records (PUT, PATCH)
  • Users should be able to force-delete a record (FORCE_DELETE)
  • Users should be able to see all records for non-soft-delete models (PAGINATE, SHOW, ALL)
  • Users should not be able to see soft deleted records (/api/users/1/customers => Customer)
  • Users should not be able to see soft deleted records (/api/users?with=customers => Customer)
  • Users should not be able to handle child element if the parent record has been soft-deleted (/api/customers/1/phones => Customer)
  • Users should not be able to handle records if related-parent elements (/api/phones?with=customer => Customer)
  • Users should be able to use force-delete hooks
  • Users should be able to see the trashed record by the query parameters (PAGINATE, SHOW, ALL)

Documentation Change

  • Models -> Soft Deleting
  • Handlers
  • Queries -> trashed
  • Queries -> related data
  • Hooks
  • DB Analyzer
@ozziest ozziest added enhancement New feature or request need detail Something that needs more detail to work on it labels Jun 3, 2021
@ozziest ozziest added this to To do in v1.0.0 via automation Dec 26, 2022
@ozziest ozziest added discussion Something that should be discussed documentation Improvements or additions to documentation and removed need detail Something that needs more detail to work on it labels Dec 26, 2022
@ozziest ozziest moved this from Backlog to Planned in v1.0.0 Dec 31, 2022
@ozziest ozziest moved this from Planned to In progress in v1.0.0 Jan 28, 2023
@ozziest
Copy link
Member Author

ozziest commented Jan 28, 2023

#38 , trashed flag should be limited.

ozziest added a commit that referenced this issue Jan 29, 2023
@ozziest ozziest mentioned this issue Jan 29, 2023
7 tasks
ozziest added a commit that referenced this issue Jan 29, 2023
ozziest added a commit that referenced this issue Jan 29, 2023
@ozziest ozziest moved this from In progress to Pull Request in v1.0.0 Jan 29, 2023
ozziest added a commit that referenced this issue Jan 29, 2023
ozziest added a commit that referenced this issue Jan 30, 2023
v1.0.0 automation moved this from Pull Request to Done! Jan 30, 2023
ozziest added a commit that referenced this issue Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Something that should be discussed documentation Improvements or additions to documentation enhancement New feature or request
Projects
No open projects
v1.0.0
Done!
Development

Successfully merging a pull request may close this issue.

1 participant