草稿/直播内容系统数据库设计
我一直在从事一个需要草稿/实时版本内容的项目,并想到了如下设计:
Article
ID
Creator
CreationDate
DraftContent(fk to ArticleContent)
PublicContent(fk to ArticleContent)
IsPendingApproval
ArticleContent
Title
Body
我想知道在发布文章时更改外键是否会更好,或者是否更好只需将草稿表中的内容复制到实时表中即可。
有什么建议吗?
编辑:草稿版本和实时版本同时存在,尽管实时版本是唯一对公众可见的版本。只能有一份草稿和一张直播表,
这种设计的部分原因是为了强制用户的文章在上线之前获得批准。
更新:
我们决定使用 Kieren 的解决方案并稍作修改。我们决定使用单个状态列,而不是对 IsPublished IsLive 之类的项目使用列。除此之外,设计保持不变。
I've been working on a project that requires draft/live versions of content and have thought of a design such as below:
Article
ID
Creator
CreationDate
DraftContent(fk to ArticleContent)
PublicContent(fk to ArticleContent)
IsPendingApproval
ArticleContent
Title
Body
I am wondering if it would be better to change the foreign keys upon an article being published or if it is better to just copy the contents from the draft table to the live table.
Any suggestions?
Edit: Both draft and live versions exist at once although the live version is the only one that is visible to the public. There can only be one draft and one live table
Part of the reason for this design is to force users to have their articles approved before they go live.
Update:
We decided to use Kieren's solution with a slight modification. Instead of using a column for items like IsPublished IsLive we decided to use a single state column. Otherwise the design remained the same.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
草稿文章开始生效,然后“发布”
通常的情况是在文章表上有一个状态/类型标志 -
IsLive
。使用单独的表是不必要且多余的;更改外键也没有多大意义。将文章视为有效对象,无论是草稿还是实时。唯一的区别是,在大多数情况下,您只想显示实时文章。在将来的某些情况下,您可能希望同时显示两者。
最初发布后可能会被编辑并具有新草稿版本的文章
就一篇文章而言,同时具有实时版本和草稿版本 - 最常见的模式是拥有主
文章< /code> 实体/对象,然后说来自该实体/对象的
ArticleVersion
。ArticleVersion
将具有IsLive
属性,或者更好的是,Article
本身将具有一个属性CurrentLiveVersionId
。这样就可以存在实时版本和草稿版本,但您通常只需通过CurrentLiveVersionId
将Article
加入到ArticleVersion
即可获得当前的现场版本。使用
ArticleVersion
表的优点包括可以存储文章的整个历史记录(更改日志),因此您可以根据需要恢复到以前的版本,或查看更改。所有这些都是为了非常低的实施成本。如果我可以澄清这个方法,请告诉我。
Draft articles that become live and then are 'published'
The usual thing would be to have a status/type flag on the article table -
IsLive
.Using separate tables is unnecessary and redundant; changing foreign keys doesn't make much sense either. Think of the article as a valid object, whether its draft or live. The only difference is, in most cases you only want to display live articles. In some cases in the future, you might want to display both.
Articles that might be edited and have a new draft version after initially becoming live
In terms of one article having both a live and draft version - the most common pattern would be to have a master
Article
entity/object, and then sayArticleVersion
coming from that. TheArticleVersion
would have theIsLive
property, or even better, theArticle
itself would have a property,CurrentLiveVersionId
. That way there can be a live and draft versions lying around, but you'd only usually joinArticle
onto theArticleVersion
by thatCurrentLiveVersionId
to get the current live version.Advantages of having the
ArticleVersion
table include the fact that the entire history of an article, a changelog, can be stored, so you can revert to previous versions if needed, or review changes. All for a very low implementation cost..Let me know if I can clarify this method.
你的设计看起来很适合我。当新版本上线时,我会:
UPDATE
PublicContent
键指向(以前的)草稿文章。删除
不再引用的以前发布的文章。NULL
DraftContent 键,或者,如果您的模型要求始终拥有草稿版本,INSERT
将新的空草稿插入ArticleContent
并将DraftContent
键指向它。Your design looks appropriate to me. When a new version goes live, I would:
UPDATE
thePublicContent
key to point to the (formerly) draft article.DELETE
the no-longer-referenced formerly-published article.NULL
the DraftContent key or, if your model calls for always having a draft version,INSERT
a new, empty draft intoArticleContent
and point theDraftContent
key to it.