Owens

Owens

Application design: When to utilize cascade deletion?

Hello all, I’m curious how you all think about cascade deletion. E.g. when one table belongs_to another table and you specify in the migration “on_delete: delete_all”.

From an application design perspective, when is this the right thing vs wrong thing to do? This question may also relate to GDPR but I’m not sure. For example, I’m developing an education platform where users can take courses. The owner of a course may want to delete that course, but then the students who paid to take it would lose their information related to that course if I did cascade deletion for all the information. So it might be better to “archive” that information in some form to satisfy both parties.

What are your thoughts on striking the right balance?

Most Liked

mbuhot

mbuhot

I like to cascade deletes when deleting an Aggregate Root and having it cascade to the closely related entities encapsulated by the aggregate.

Associations between aggregates don’t need cascading deletes, or even necessarily foreign key constraints between them.

The question I ask myself is “could this group of tables be split off into a separate DB/service in future?” If so, then there can’t be cascading deletes or RI enforced if/when that happens, so try not to rely on it too heavily now.

Where Next?

Popular in Discussions Top

ricklove
I was just introduced to Elixir and Phoenix. I was told about the 2 million websocket test that was done 2 years ago. From my research, t...
New
AstonJ
If a newbie asked you about Phoenix Contexts, how would you explain the basics to them? Feel free to be as concise or in-depth as you li...
New
rower687
Hi all, I’ve been reading a lot about the “let it crash” term and how supervising processes and the whole messaging passing make an elixi...
New
rms.mrcs
A couple of days ago I was discussing with a friend about different approaches to write microservices. He said that if he was going to w...
New
mikl
I wanted to capitalize a string, and tried using String.capitalize(). That generally works well, until you try to capitalize a word like...
New
owaisqayum
I have a sample string sentence = "Hello, world ... 123 *** ^%&*())^% %%:>" From this string, I want to only keep the integers, ...
New
paulanthonywilson
I like Umbrella projects and pretty much always use them for personal Elixir stuff, especially Nerves things. But I don’t think this is ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 131117 1222
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31586 112
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

We're in Beta

About us Mission Statement