简体   繁体   English

PostgreSQL-在哪里存储所有者数据?

[英]PostgreSQL - Where to store owners data?

It is ok to store the owners (the ones who access the main project dashboards) in the same database schema where normal users are stored? 可以将所有者(访问主项目仪表板的所有者)存储在与存储普通用户相同的数据库模式中吗? If so, how it is best: in the same "users" table with a flag "role" or in an independent table "owners". 如果是这样,那么最好的方法是:在带有标志“ role”的同一“ users”表中,或者在一个“ owners”独立表中。

CREATE TABLE users (
    id BIGSERIAL NOT NULL PRIMARY KEY,
    email TEXT NOT NULL UNIQUE,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE owners (
    id BIGSERIAL NOT NULL PRIMARY KEY,
    email TEXT NOT NULL UNIQUE,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

or 要么

CREATE TABLE users (
    id BIGSERIAL NOT NULL PRIMARY KEY,
    email TEXT NOT NULL UNIQUE,
    role INT NOT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

I recommend to store the users in one table. 我建议将用户存储在一张表中。

Here is why: 原因如下:

  • One table storing very similar kind of data 一个表存储非常相似的数据
  • It's easier to upgrade a user to a superuser 将用户升级为超级用户更容易
  • Maintenance 保养
  • Follow up sql statements using users will be less complex 使用用户跟进sql语句将不太复杂

I would say that having only one table is easier to maintain and simplifies the logic of the app. 我想说只有一个表更容易维护,并简化了应用程序的逻辑。 The "role" field allows future expansion in case you'd like to add new role types. 如果您想添加新的角色类型,“角色”字段允许将来扩展。 Security-wise, having one or two tables should be very similar. 在安全方面,拥有一个或两个表应该非常相似。 But it depends of how you access the table, permissions, ... 但这取决于您如何访问表,权限,...
I'm not sure this answer is very helpful, but we would need a bit more of context to be able to help you further... 我不确定这个答案是否会很有帮助,但我们需要更多的背景信息才能进一步为您提供帮助...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM