简体   繁体   English

从DB进行逻辑删除

[英]Logical delete from DB

I have a complex schema with many entitites and relations.I want to define a logical delete operation which can be undone. 我有一个复杂的模式,有许多权限和关系。我想定义一个可以撤消的逻辑删除操作。 I've considered adding 'isDeleted' flag to every table, but it seems bug-proned to me. 我考虑过为每个表添加'isDeleted'标志,但它似乎对我来说是错误的。 I've also considered adding an archive schema which is similar to the original schema, and on every delete operation to move the data there.That seems to require a lot of code to write for the "delete" and "undelete" operations (espacially since I want to emulate on delete casade for the logical delte). 我还考虑添加一个类似于原始模式的归档模式,并在每个删除操作上移动数据。这似乎需要大量代码来编写“删除”和“取消删除”操作(特别是因为我想在删除casade上模拟逻辑delte)。

Finally, I'm not sure where to handle the events of logical delete I'm using EF so I can do it in code, or maybe I can use the delete trigger in he DB. 最后,我不知道在哪里处理逻辑删除的事件我正在使用EF所以我可以在代码中执行它,或者我可以在数据库中使用删除触发器。

I would appreiciate any recomendations on how to implement the logical delete in an elegant way. 我会以优雅的方式表达关于如何实现逻辑删除的任何建议。 Thanks. 谢谢。

Every company I worked for has always used a logical delete flag and managed it through code. 我工作的每家公司都使用逻辑删除标志并通过代码进行管理。 Adding an archive schema is a huge overhead and IMO its added elegancy (both coding and performance wise) doesn't worth the extra effort. 添加归档架构是一个巨大的开销,IMO增加的优点(编码和性能方面)不值得额外的努力。

Since this is an OLTP database, I don't have issue using the IsDeleted flag. 由于这是一个OLTP数据库,我没有使用IsDeleted标志的问题。 If you are worried about performance, I will continue using the IsDeleted flag and move it to archive through a batch process, not online. 如果您担心性能,我将继续使用IsDeleted标志并通过批处理将其移动到存档,而不是在线。

One thing that I always keep in mind to avoid over-architecting something - It's not a problem unless it's a problem. 我总是记住一件事,以避免过度设计某些东西 - 这不是一个问题,除非它是一个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM