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

Feat/soft delete #166

Open
wants to merge 22 commits into
base: release/0.2.0
Choose a base branch
from
Open

Feat/soft delete #166

wants to merge 22 commits into from

Conversation

lesagi
Copy link
Contributor

@lesagi lesagi commented Mar 23, 2021

Hi,

I added the option for soft for both InMemory and Relational, need to add Redis

I made it optional, and also I prevent getting the URL if the URL was soft deleted, please let me know what you think

I've merged the release branch to prevent conflicts in the future, that made the PR a bit hard to follow, my new Impl starts at:

"Merge remote-tracking branch 'origin/release/0.2.0' into release/0.2.0"

#79

lesagi and others added 18 commits March 10, 2021 16:12
destructuring function argument

Co-authored-by: Snir Shechter <[email protected]>
Co-authored-by: Snir Shechter <[email protected]>
throwing an error when non-privileged user trying to create a custom id
@codecov
Copy link

codecov bot commented Mar 23, 2021

Codecov Report

Merging #166 (df3172f) into release/0.2.0 (ededa7b) will decrease coverage by 0.54%.
The diff coverage is 0.00%.

Impacted file tree graph

@@                Coverage Diff                @@
##           release/0.2.0     #166      +/-   ##
=================================================
- Coverage          17.52%   16.98%   -0.55%     
=================================================
  Files                 40       41       +1     
  Lines               1335     1378      +43     
  Branches              50       51       +1     
=================================================
  Hits                 234      234              
- Misses              1069     1111      +42     
- Partials              32       33       +1     
Impacted Files Coverage Δ
src/routes/url.ts 0.00% <0.00%> (ø)
src/services/auth/drivers/bearerToken/index.ts 0.00% <ø> (ø)
src/services/storage/drivers/inMemory/index.ts 0.00% <0.00%> (ø)
src/services/storage/drivers/relational/index.ts 0.00% <0.00%> (ø)
...relational/migrations/20210401143602_softDelete.ts 0.00% <0.00%> (ø)
src/services/storage/index.ts 0.00% <0.00%> (ø)
src/services/storage/types/url.ts 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ededa7b...df3172f. Read the comment docs.

@@ -69,15 +70,15 @@ export class RelationalStorage implements StorageDriver {
url = new (class RelationalUrlStorage {
constructor(public storage: RelationalStorage) { }

public async get(id: string, options = { withInfo: false }): Promise<StoredUrl | UrlWithInformation> {
public async get(id: string, options = { withInfo: false, isAuthorized: false }): Promise<StoredUrl | UrlWithInformation> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The storage service should not be aware of any authorization checks. Change isAuthorized to a different name (probably something such as includeDeleted or so).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took the name you suggested

.select('*')
.where('id', id)
.first()
if (storedUrl?.deletedAt && !options.isAuthorized) throw new UnauthorizedError();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a user asks for a URL with id=4 (doesn't exist), it'll receive a 404. If they request a URL with id=3 (deleted), they'll receive an UnauthorizedError. This gives away the fact we use soft-delete instead of hard-delete (bad).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed both to 404

await this.storage.db.table<StoredUrl>('urls').where('id', id).delete()
} else {
await this.storage.db.table<StoredUrl>('urls').update({ deletedAt: new Date().toISOString() }).where('id', id)
}
}

public async deleteOverdue(timespanMs: number): Promise<number> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about deleteOverdue? We need it to soft-delete too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a deleteOverdue + migration to support the soft delete in postgres

Copy link
Contributor

@Danielg212 Danielg212 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lesagi please see Snir comments

- Add a migration for the new 'deletedAt' Column

- Define a default SOFT delete method for deleteOverdue

- Change the 'options' parameter passed to the drivers' functions
@lesagi lesagi requested a review from SnirShechter April 1, 2021 11:50
@lesagi
Copy link
Contributor Author

lesagi commented Apr 1, 2021

@lesagi please see Snir comments

Hi, Snir was updated yesterday, it was WIP, now can be reviewed again, thanks for the heads up!

@lesagi lesagi requested a review from Danielg212 April 1, 2021 11:52
@SnirShechter SnirShechter changed the base branch from release/0.2.0 to main April 17, 2021 21:19
@SnirShechter SnirShechter changed the base branch from main to release/0.2.0 April 17, 2021 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow for soft cleanup (use deleted_at instead of deleting the row) for info for admins later on
3 participants