数据库架构:用户团队管理
我有用户,他们通过成员资格表成为许多团队的成员。每个团队有一名管理员。
我的问题是:
admin 列 应该是 membership 表中的布尔值,还是 team 表中的整数(用户 ID)?
I have users, who are members of many teams through a membership table. Each team has one administrator.
My question is:
Should the admin column be a boolean in the membership table, or an integer (id of user) in the team table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的是,是的:在成员资格表中,因为这是用户和团队之间的链接。在这种情况下,您可以更灵活地添加例如 2 个管理员。考虑到明确拥有 1 个管理员是安全的,另一种方法也是有效的。
缺点是,例如,您应该强制执行一种关系,因此 admin_id 始终链接到实际上是团队成员的用户。因此,在删除时,您应该检查该管理员是否确实仍然可用。
进一步思考:考虑一下您是否有多个角色,如果是这种情况,您可能会使用更复杂但更灵活的解决方案,例如 ACL 等。
Most simple is, yes: in membership table as that is the link between a User and a Team. In that case you would be more flexible to add for example 2 administrators. The other way around is also a valid one, considering it secures to have explicitly 1 administrator.
The disadvantage is for example that there is a relation which you should enforce so admin_id always links to a User which is really a member of the Team. So on delete you should check whether this admin is really still available.
A bit further thinking: Consider whether you have multiple roles, if that's the case you might use a more complex but flexible solution like ACL's and things.