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

Add soft-deletion to companies, jobs, industries #488

Merged
merged 3 commits into from
Dec 19, 2019

Conversation

brain-geek
Copy link
Contributor

@brain-geek brain-geek commented Mar 8, 2019

The first version, feel free to give comments.

@doomspork doomspork added the enhancement A new feature or enhancement to the existing functionality label Mar 8, 2019
@doomspork doomspork requested review from doomspork and gemantzu March 8, 2019 19:23
@brain-geek
Copy link
Contributor Author

@doomspork @tajchumber @gemantzu @burden Guys, what do you think about this?

In context of #483 I believe having soft-delete will improve traceability a lot.

@doomspork
Copy link
Member

@brain-geek I will look today! Sorry for the delay. I hope that's okay. What do you say?

@brain-geek
Copy link
Contributor Author

@doomspork Thanks, no worries!

Just trying to push it out before beginning the next thing. 😄

@doomspork
Copy link
Member

You're the best @brain-geek! 😁

Copy link
Member

@doomspork doomspork left a comment

Choose a reason for hiding this comment

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

Super stuff @brain-geek! Some thoughts and a few changes. Happy to discuss any of them 😁

@brain-geek
Copy link
Contributor Author

@doomspork Thanks for the feedback, I will be applying it in the following days.

@Nitrino
Copy link
Contributor

Nitrino commented Mar 12, 2019

Recently, Devon C. Estes has written the article about soft deletion using the PostgreSQL schema.
http://devonestes.herokuapp.com/soft-delete-with-ecto-3-and-postgres

May use a similar approach, then we will not have to worry about the where(is_deleted: false) conditions.
What do you think about it?

@doomspork
Copy link
Member

Good point @Nitrino!

When we retweet that article on Elixir School someone had responded suggesting this was not an ideal approach. It might be worth looking into their feedback: https://twitter.com/atomkirk/status/1101566414668869637

@brain-geek
Copy link
Contributor Author

@Nitrino Thanks for the link. I've looked through the article and found it interesting. However, I believe that this project is also intended to be checked out by new Elixir devs, and having some magic inside the postgresql would be hard to follow.

However, it may be better to change is_deleted field to something like removed_pending_change_id to always have a pending change which led to this deletion.

What do you think?

@brain-geek
Copy link
Contributor Author

@doomspork well, I don't agree with like UNIQUE of only live records part in this comment, as you can do unique index with where attached, so it's not a big deal.

@doomspork
Copy link
Member

However, I believe that this project is also intended to be checked out by new Elixir devs, and having some magic inside the postgresql would be hard to follow.

💯 — very good point. I think this is reason enough not to use it.

However, it may be better to change is_deleted field to something like removed_pending_change_id to always have a pending change which led to this deletion.

Are you suggesting ditching the boolean is_deleted in favor of just checking for the existence of an associated pending change here? I could get behind that 👍

@Nitrino
Copy link
Contributor

Nitrino commented Mar 12, 2019

@brain-geek I agree, the approach with schemas is opaque for new developers.

@brain-geek
Copy link
Contributor Author

@doomspork Please review again. I believe I fixed all the issues. 😄

@gemantzu
Copy link
Collaborator

gemantzu commented Mar 14, 2019

Can I add my two cents, as I am not totally behind doing this this way right now?

My take on this issue would be to add an active field on companies, jobs (idk about industries, still trying to figure out what we should do with industries) and let pending_changes do it's job here (make the field active or inactive per request).

Also, to add full trackability on what changes we have, we could change pending_changes to have an record id field (we already have the corresponding table name on it), so we can track ( and probably show? ) what changes and on what date have occured on a record.

I am not saying we should not do it like this, I am just stating some thoughts out loud.

@doomspork
Copy link
Member

@gemantzu / @brain-geek where are we with this? Do we want to move ahead with this approach and come back to @gemantzu's comments or look at incorporating that now?

Happy to help with the work 😁

@brain-geek
Copy link
Contributor Author

@doomspork I'll have comments fixed today.

@brain-geek
Copy link
Contributor Author

brain-geek commented Mar 25, 2019

Hm, @doomspork , I don't think this approach differs much from one proposed by @gemantzu .

This change only adds a field to mark a record as deleted. Only data attached there is why (pending change reference). My take on this issue would be to add an active field would basically do the same as the current implementation.

Also, if someone deleted a company - that's for a good reason. Let them create a new one instead, IMO.

Having full accountability would be nice, and I agree that would be a useful feature.

@brain-geek brain-geek force-pushed the soft_deletion branch 2 times, most recently from 6ebe4d2 to 027d3c3 Compare March 25, 2019 20:49
Copy link
Member

@doomspork doomspork left a comment

Choose a reason for hiding this comment

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

One small change and this looks good to me @brain-geek. I'd love to get at least one other set of eyes on this before merging though.

cc @tajchumber / @gemantzu / @Nitrino

@brain-geek
Copy link
Contributor Author

@doomspork Fixed. Let's wait for other reviews.

@gemantzu
Copy link
Collaborator

I see an error when trying to manually test the functionality.
Creating a company and approving it works.
If I make an edit or a delete pending change (both companies and jobs), when I try to view it to either approve or reject, it fails with the following error:
cannot encode association :removed_pending_change from Companies.Schema.Company to JSON because the association was not loaded.
cannot encode association :removed_pending_change from Companies.Schema.Job to JSON because the association was not loaded.

Do you see them in your local repo?

@doomspork
Copy link
Member

I will test this out this weekend @brain-geek and see if I can reproduce @gemantzu's aforementioned errors 👍

@brain-geek
Copy link
Contributor Author

Sorry for slow responses. I've seen the feedback, will be fixing it this or next weekend.

@doomspork
Copy link
Member

No worries @brain-geek, take your time. Thanks again for the help! Happy Friday 😁

@brain-geek brain-geek requested a review from a team as a code owner November 20, 2019 17:40
@doomspork
Copy link
Member

@maartenvanvliet do you mind taking a peek at this PR? @brain-geek is getting back into open source and wants to wrap up these two outstanding out PRs of his (the other is draft #483). Thank you again for all your help 💜

@doomspork
Copy link
Member

doomspork commented Dec 7, 2019

@brain-geek I fixed the failing tests and the conflict locally. If you give me contributor access to your fork I can push the commit over to ya so we can get this merged 😁

You may also be able to cherry-pick it:
928e858

@brain-geek
Copy link
Contributor Author

@doomspork Wow, thanks a lot! Cherry picked and merged.

maartenvanvliet
maartenvanvliet previously approved these changes Dec 8, 2019
Copy link
Member

@maartenvanvliet maartenvanvliet left a comment

Choose a reason for hiding this comment

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

A few comments but looks good

@doomspork
Copy link
Member

doomspork commented Dec 8, 2019

Thank you so much for taking a look @maartenvanvliet 💜

@brain-geek you're most welcome buddy! Always happy to help ya 😁 Let me know if you want a hand with @maartenvanvliet's comment

@brain-geek 6696915

@maartenvanvliet maartenvanvliet self-requested a review December 8, 2019 22:04
@brain-geek
Copy link
Contributor Author

@doomspork Thanks for help! It feels like cheating. 🔥

@brain-geek
Copy link
Contributor Author

@maartenvanvliet Could you look at this PR once again? I've applied your changes.

@doomspork Thanks for the help! Any ideas what also needs to be changed before merging?

Copy link
Member

@maartenvanvliet maartenvanvliet left a comment

Choose a reason for hiding this comment

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

LGTM

@doomspork doomspork merged commit b9cb801 into beam-community:master Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new feature or enhancement to the existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants