多用户数据库设计

发布于 2024-10-16 03:53:02 字数 346 浏览 3 评论 0原文

我必须出于学术目的开发一个基本的社交网络;但我需要一些用户管理的技巧。

用户分为 3 个具有不同权限的组:管理员、分析师和标准用户。 对于每个用户,应将以下信息存储到数据库中:姓名、姓氏、电子邮件、年龄、密码。

我不太确定应该如何在这两个解决方案之间设计数据库:

1)一个名为“用户”的表,其中包含“角色”属性,解释用户可以做什么和不能做什么,并管理权限通过 php

2)每个应用程序用户都是使用查询“CREATE ROLE”创建的数据库用户(这是一个 postgres 数据库),并且他对使用“GRANT”语句授予的某些表具有权限

您应该考虑到该项目是针对数据库考试..

谢谢

I have to develop a basic social network for an academic purpose; but I need some tips for the users management..

The users are subdivided into 3 groups with different privilege: admins,analysts and standards users.
For every user should be stored into the database the following information: name,lastname,e-mail,age,password.

I'm not quite sure how I should design the database between theese two solutions:

1)one table called 'users' with the 'role' attribute that explain what a user can do and what can't do, and the permissions are managed via php

2)every application user is a database user created with the query 'CREATE ROLE' (It's a postgres database) and he has permissions on some tables granted with the 'GRANT' statement

You should take into account that the project is for a database exam..

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

怀中猫帐中妖 2024-10-23 03:53:02

不要使用数据库的授权机制作为应用程序的授权系统。三个主要原因:

A) 如果不重建整个应用程序,您将永远无法更改到不同的数据库。

B) 您想要在应用程序中授予用户的事物类型可能与数据库的 ACL 系统允许的事物类型不同。

最重要的是:

C) 您不想让应用程序用户直接对数据库执行任何操作。曾经。

所以你的第二个选择是正确的。因此,为每个用户记录存储一个用户类型字段,然后“该用户类型允许的内容”就成为用 PHP 计算的业务逻辑的一部分。

Don't use the database's authorization mechanism to be your application's authorization system. Three main reasons:

A) You'll never be able to change to a different database without rebuilding the whole app.

B) The types of things you want to grant the users in the app might differ from what the db's ACL system allows.

And most importantly:

C) You don't want to give an application user the ability to do anything directly to your database. Ever.

So your #2 option is right out. Thus, store a user type field with each user record, and then "what that user type allows" becomes part of your business logic that is calculated in PHP.

星星的轨迹 2024-10-23 03:53:02

每次都使用解决方案 1,因为您不想限制自己只能在每个表的基础上分配权限。使用数据库用户会很麻烦而且不太实用。

Solution 1 every time as you don't want to restrict yourself to only assign permissions on a per-table basis. Using database users would be cumbersome and not very practical.

羁〃客ぐ 2024-10-23 03:53:02

选择选项 1。从长远来看,它会更加灵活,可能更容易编码,并且您不希望将应用程序逻辑与特定实现联系得太紧密。如果您稍后想要移植应用程序以在 SQL-Server 上运行怎么办?如果数据库用户的实现方式不同,选项 2 可能会给您带来严重的痛苦。

Go with Option 1. It will be much more flexible in the long run, probably easier to code, and you don't want to tie your application logic too closely to a specific implementation. What if you later on want to port the application to run on SQL-Server? If database users are implemented differently, Option 2 could give you serious pains.

欲拥i 2024-10-23 03:53:02

选择第一个替代方案(使用 PHP 管理权限)。原因如下:

  1. 数据库没有为您需要管理的权限提供足够的选择和粒度(允许谁发送电子邮件、允许访问哪些组等)。
  2. 通常与数据库的连接相当有限 。昂贵,因此您需要连接一次并尽可能长时间地保持连接(使用相同的数据库用户)
  3. 所有数据库在创建时都以处理用户帐户的方式相同。通过在 SQL 之上构建自己的用户系统,您可以希望更加独立于数据库。
  4. 在现实世界中,管理数据库和开发程序的任务是由完全不同的人完成的,并且程序无权创建或更改数据库用户

Go with your first alternative (manage permissions with PHP). Here are the reasons:

  1. The database does not give you enough choices and granularity in the permissions you'll need to manage (who is allowed to send emails, to what groups people are allowed access, etc.)
  2. Typically connections to the database are rather expensive so you'll want to connect once and stay connected as long as possible (with the same database user)
  3. All databases are not created equal in the way they handle user accounts. By building your own user system above SQL you can hope to be more database independant
  4. In the real world the tasks of administering the database and developping programs are done by completely different people and the program does not have the right to create or alter database users
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文