我正在尝试创建一个基于角色的访问控制系统,但问题出现在我接近数据库部分时 .

我应该制作两个模型,角色和权限,然后在角色和权限之间 Build 多对多的关系或者什么?

我的用户模型看起来像这样:

Column   |            Type             | Collation | Nullable |      Default
------------+-----------------------------+-----------+----------+--------------------
 id         | uuid                        |           | not null | uuid_generate_v4()
 name       | character varying(50)       |           | not null |
 email      | character varying(320)      |           | not null |
 avatar     | text                        |           |          |
 password   | text                        |           | not null |
 phone      | character varying(30)       |           |          |
 created_at | timestamp without time zone |           | not null | now()
 updated_at | timestamp without time zone |           |          | now()
 companyId  | uuid                        |           |          |
 roleId     | uuid                        |           |          |

所以我在用户和角色之间只有一对多的关系 .