为未来值添加保留字段是个好主意

发布于 2024-10-08 07:26:07 字数 474 浏览 0 评论 0原文

我有像 CustomerPurchase 等表格,有时它们有关联的文档,我所说的文档是指某处的某些文件(例如扫描的驾驶执照或其他东西),

我们不能拥有应用程序将这些文档直接上传到数据库中,因此我有一个唯一标识符列(我应该有一个文件哈希吗?)

我的问题:
将来我们可能会有更多与表相关的文档,所以我正在考虑添加额外的字段,例如:

客户
+驱动程序许可证文档
+文档1//面向未来
+Document2 //将来使用

因此,将来如果他们决定需要另一个文档,我只需更新我的实体框架模型并重命名模型中的列,数据库就不必更改?

一般情况下是这样的吗?还有更好的想法吗?我看到的缺点是我必须将所有这些未来值保留为空?也许这不是缺点?
还想听听您通常如何应对部署后数据库架构变化的想法?

I have tables like Customer, Purchase etc which sometimes have associated documents with them, by documents I mean some file somewhere (like a scanned drivers license or something)

We cannot have the application upload these documents straight into the database so instead I have a uniqueidentifier column for these (Should I have a file hash instead?)

My question:
In the future we might have more documents associated with a table, so I was thinking of adding extra fields like:

Customer
+DriversLicenseDoc
+Document1//for the future
+Document2 //future use

So in the future if they do decide they want another document I will just have to update my entity-framework model and rename the column in my model and the database won't have to change?

Is this how its generally done? Any better ideas? The downside I see is I will have to keep all these future values nullable? Maybe thats not a downside?
Also wold like to hear thoughts on how you generally cope with changes in database schema after deployment?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丢了幸福的猪 2024-10-15 07:26:07

不,这实际上是一个非常糟糕的主意。要么您正确预见了用途,在这种情况下按原样添加它们,要么您只是猜测可能会发生什么,在这种情况下您应该等到知道为止。

处理部署后架构更改的方法是在部署后更改架构(以及任何相关代码)。您应该查看首字母缩略词“YAGNI”。在我看来,任何不是立即需要的努力都应该被视为为可能永远不需要的事情所做的努力。换句话说,就是白费力气。

如果您可能存在未知数量的文档,那么这是从客户表到文档表的简单一对多关系,表中的每个文档都带有文档类型和文档负载,类似于

customers:
    custid  primary key
    <all other customer data>
documents:
    docid primary key
    custid references customers(custid)
    <all other document data>

:每个客户都可以拥有任意数量的文档、任意类型的文档。

No, it's actually a really bad idea. Either you foresee the use correctly in which case add them as they are meant to be, or you're just guessing at what might happen in which case you should wait until you know.

The way to handle schema changes after deployment is to change the schema (and any related code) after deployment. You should look into the acronym "YAGNI". In my opinion, any effort that is not needed immediately should be viewed as effort carried out for something that may never be needed. In other words, wasted effort.

If you have a unknown number of documents that may exist, that's a simple one-to-many relationship from the customers table to the documents table, with each document in the table carrying the document type and document payload, something like:

customers:
    custid  primary key
    <all other customer data>
documents:
    docid primary key
    custid references customers(custid)
    <all other document data>

That way, each customer can have as many documents as you wish, of as many types as you need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文