如何确保我的数据库设计可扩展?

时间:2010-10-14 12:28:46

标签: database-design cakephp relational-database

我有两个型号 - 用户和餐馆。他们可以设置状态消息等推文,并可以回复。我有以下设置,需要您的帮助来优化设计。

users(id, name, ......)
restaurants(id, name.....)
modules(id, name)  [this table stores the modules - (1,user) and (2,restaurant)

我的留言表

status_messages(id, pid, message, time, module_id, moduleID)

id - Uid, primary key
pid - self ID or parent ID - for accomodating the replies in to the same table.
message - the status message is stored here
time - the time the status message was set
module_id - refers to the module its pointing - Users or Restaurants
moduleID - the actual foreign key

这是正确的方法吗?

应用程序的规模:它将成为全球范围内的开放式应用程序,因此将对所有这些餐厅和用户进行一个表格缩放。

我希望有一个类似的评论模型,可以在一张桌子上迎合餐厅,菜肴,活动,自助餐。它有点矫枉过正吗?

1 个答案:

答案 0 :(得分:1)

是的,这个设计应该没问题,你可能想在status_messages.module_id列上放置某种索引,以便用户/餐馆可以过滤表上的选择。

通常在服务器端,您将为状态消息表

创建两个类

1类UserMessages 二等餐厅消息

并使用某种ORM工具将module_id定义为decriminator列。所以在数据库中它在一个表中最大化重用。但是在应用程序上它有两个不同的名称(逻辑名称)。不确定这在PHP中是如何工作的。