它是最好能有两个不同的用户表或一个? [英] Is it better to have two separate user tables or one?

查看:151
本文介绍了它是最好能有两个不同的用户表或一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Web应用程序都将有两种类型的100%用户的不同 - 在领域,功能和目的在网站​​上。一种类型的用户的目的是张贴博客,和其他的目的,是阅读并跟随海报

My web app is going to have two types of users that are 100% different - in fields, functions, and purpose on the site. The purpose of one type of user is to post blogs, and the purpose of the other is to read them and "follow" the posters.

他们所共有的唯一的东西是需要一个ID,电子邮件,密码和一些元数据,如日期等位加盟等。

The ONLY stuff they have in common are the need for an id, email, password and a couple other bits of meta data such as date joined, etc.

我应该尝试从同一帐户表干他们,或者做一个表中的每个?

Should I attempt to stem them from the same account table, or make one table for each?

注意

-One潜力的是,以prevent用户的困惑,我觉得这两种类型的账户之间的邮件应该是独一无二的。

-One potential thing to think about is that, to prevent user confusion, I think emails between the two types of accounts should be unique.

-Readers及作词家都会有不同的设置将需要从正常的账户元数据存储预留约它们。数据

-Readers and Authors will have different sets of data that will need to be stored about them aside from the normal "account" meta data.

推荐答案

我想将它们分开。

TABLE User {
    id
    email
    password
    salt
    created
    modified
}

TABLE follower {
    user_id
    ...
}

TABLE author {
    user_id
    ...
}

随着时间的推移你的应用将增长。也许现在你有两个destinct角色 - 但它可能在将来改变。你可能有作者也跟随其他作者,或已升级到作家的追随者。你也可以开始添加其他角色,并希望这样的事情:

Over time your application will grow. Perhaps now you have two destinct roles - but it may change in the future. You may have authors that also follow other authors, or followers that are "upgraded" to authors. You might also start adding other "roles" and want something like this:

TABLE user_role {
    user_id
    role_id
}

TABLE role {
    id
    name
}

这篇关于它是最好能有两个不同的用户表或一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆