News for hackers. Stuff that matters.
Re:Instead of deleting account, NYT appends ‘1000’ to userna... by perl4ever on Tuesday April 28, 2020 @12:25PM (#23008594)
I used to work where (not a service for the general public) there was an "is deleted" flag for everything, but every now and then a client would insist that data be really deleted, and depending on who it was and how they asked, we might go and do it, which was a huge hassle and would cause no end of problems down the line.

On the other hand, "is deleted" flags end up causing issues when you forget to put "where not is_deleted" in your queries.

Lately I've faced kind of an inverse situation - I have a system that I can't control where things are permanently deleted once in a while for multiple reasons (rogue users, aging out of old versions) and so as I accumulate information in a little data warehouse for reporting, I decided to implement an "is deleted" flag there. Eventually though, deleting from the source was turned off because it's really not necessary.

Re:Instead of deleting account, NYT appends ‘1000’ to userna... by Terr_ on Tuesday April 28, 2020 @05:47PM (#23012516)
I also worked at a similar place, and fantasized about rewriting everything so that soft-deletion wasn't a per-row technical detail, but was instead an explicit modeled business-flow. Perhaps stored as a flag on an Aggregate Root (like "Customer" or "Project") at a much coarser level of detail. Sure, your queries still need to account for it, but at least you don't have a potential patchwork of inconsistent flags.

P.S.: Random advice to anybody working on enterprisey stuff:

1. "Deletion" is too vague and broad. I strongly suggest you call it "deactivation" and some other word like "purging."

2. Deactivation is typically what a company actually wants, even if they don't know to ask for it. By phrasing it that way you also encourage stakeholders to think about "reactivation" before it becomes an architectural problem.

3. True purging is rare, and tends to be related to either disk-space issues or legal requirements. In the latter case, you'll want an audit-trail or tombstone of some sort, meaning it's still a real workflow and not just an easy SQL DELETE statement or something.

Re:Instead of deleting account, NYT appends ‘1000’ to userna... by lostapathy on Tuesday April 28, 2020 @03:38PM (#23010919)
The discard gem for rails has put a lot of thought into this and works pretty well, all things considered.

It's not perfect, but I find using a library (either directly for inspiration) is often a shortcut to learning about a lot of edge cases from doing your own things.

https://github.com/jhawthorn/discard

Re:Instead of deleting account, NYT appends ‘1000’ to userna... by dorgo on Tuesday April 28, 2020 @01:13PM (#23009197)
>On the other hand, "is deleted" flags end up causing issues when you forget to put "where not is_deleted" in your queries.

My solution would be a view for every table. Are there drawbacks? Other solutions?

Re:Instead of deleting account, NYT appends ‘1000’ to userna... by perl4ever on Tuesday April 28, 2020 @01:53PM (#23009774)
Eh, the situation that I've been in, if I recall correctly, is that one has read/write access to all data for reporting, but not the ability to create views (or stored procedures etc) to share.

Where I am now, (as far as Oracle goes) you can't even create your own tables under your own schema. A view requires a meeting with a DBA and their manager and really special, compelling arguments.

Re:Instead of deleting account, NYT appends ‘1000’ to userna... by lilyball on Tuesday April 28, 2020 @05:39PM (#23012437)
Can you just have a general policy where every table that has an is_deleted flag also automatically gets a view, and clients must use the view unless they have a particular need to access deleted data?
Re:Instead of deleting account, NYT appends ‘1000’ to userna... by capableweb on Tuesday April 28, 2020 @01:25PM (#23009377)
Not sure about drawbacks but another solution would be to change the point where you do the queries instead. So you have a "user" object that is largely saved the same as most other "crud" objects, so you have a layer for those, add the flag there.
Re:Instead of deleting account, NYT appends ‘1000’ to userna... by dbbk on Wednesday April 29, 2020 @09:39AM (#23018969)
Most ORMs have built-in support for this. For example Laravel's Eloquent automatically filters out `deleted_at` records
Re:Instead of deleting account, NYT appends ‘1000’ to userna... by latch on Tuesday April 28, 2020 @12:29PM (#23008640)
You can use row level security so that forgetting the filter isn't an issue.
Re:Instead of deleting account, NYT appends ‘1000’ to userna... by dorgo on Tuesday April 28, 2020 @01:19PM (#23009288)
as far as I understand this would only work for users who don't have access to "deleted" rows. Are access rules a good way to handle this? Serious question. My solution would be to have views as "guards" for every table.
Re:Instead of deleting account, NYT appends ‘1000’ to userna... by latch on Tuesday April 28, 2020 @07:06PM (#23013219)
Views also work.

I don't understand what you mean re "access". RLS is what removes access to those rows, that's the point of RLS.

In postgresql, anyways, superusers aren't subject to RLS and the table owner, by default, isn't either. But RLS can be enforced for the table owner by a single alter statement.

Re:Instead of deleting account, NYT appends ‘1000’ to userna... by mekster on Wednesday April 29, 2020 @12:26AM (#23015350)
> would cause no end of problems down the line

That's just how badly the system is designed. Write a script to delete all relevant data and the user and it would be a simple op.

> forget to put "where not is_deleted"

Use views.

Re:Instead of deleting account, NYT appends ‘1000’ to userna... by netsharc on Tuesday April 28, 2020 @07:35PM (#23013474)
I've been on both sides of this insisting, if a company annoyed me too much (e.g. headhunters mailing too frequently) I'd drop the "data privacy laws" (nowadays GDPR) bomb and ask for my data to be deleted.

On the other side, a customer got really pissed off by an online shop we maintained for a client, and asked for his data to be annihilated, we thought "What a douche.".