草稿/直播内容系统数据库设计

发布于 2024-12-12 07:29:11 字数 515 浏览 0 评论 0原文

我一直在从事一个需要草稿/实时版本内容的项目,并想到了如下设计:

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 技术交流群。

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

发布评论

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

评论(2

扭转时空 2024-12-19 07:29:11

草稿文章开始生效,然后“发布”

通常的情况是在文章表上有一个状态/类型标志 - IsLive

使用单独的表是不必要且多余的;更改外键也没有多大意义。将文章视为有效对象,无论是草稿还是实时。唯一的区别是,在大多数情况下,您只想显示实时文章。在将来的某些情况下,您可能希望同时显示两者。

最初发布后可能会被编辑并具有新草稿版本的文章

就一篇文章而言,同时具有实时版本和草稿版本 - 最常见的模式是拥有主文章< /code> 实体/对象,然后说来自该实体/对象的 ArticleVersionArticleVersion 将具有 IsLive 属性,或者更好的是,Article 本身将具有一个属性 CurrentLiveVersionId。这样就可以存在实时版本和草稿版本,但您通常只需通过 CurrentLiveVersionIdArticle 加入到 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 say ArticleVersion coming from that. The ArticleVersion would have the IsLive property, or even better, the Article itself would have a property, CurrentLiveVersionId. That way there can be a live and draft versions lying around, but you'd only usually join Article onto the ArticleVersion by that CurrentLiveVersionId 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.

涙—继续流 2024-12-19 07:29:11

你的设计看起来很适合我。当新版本上线时,我会:

  1. UPDATE PublicContent 键指向(以前的)草稿文章。

  2. 删除不再引用的以前发布的文章。

  3. NULL DraftContent 键,或者,如果您的模型要求始终拥有草稿版本,INSERT 将新的空草稿插入 ArticleContent 并将 DraftContent 键指向它。

Your design looks appropriate to me. When a new version goes live, I would:

  1. UPDATE the PublicContent key to point to the (formerly) draft article.

  2. DELETE the no-longer-referenced formerly-published article.

  3. NULL the DraftContent key or, if your model calls for always having a draft version, INSERT a new, empty draft into ArticleContent and point the DraftContent key to it.

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