我有一张这样的桌子:
CREATE TYPE action_types AS ENUM ('VIEW', 'INSERT', 'UPDATE', 'DELETE');
CREATE TABLE resources(
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
name text NOT NULL
);
CREATE TABLE roles(
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
name text NOT NULL
);
CREATE TABLE users(
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
role_id uuid REFERENCES roles(id) NOT NULL ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE permissions(
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
action action_types NOT NULL,
resource_id uuid REFERENCES resources(id) NOT NULL ON DELETE CASCADE ON UPDATE CASCADE,
UNIQUE(action, resource_id)
);
CREATE TABLE access(
role_id uuid REFERENCES roles(id) ON DELETE CASCADE ON UPDATE CASCADE,
permission_id uuid REFERENCES permissions(id) NOT NULL ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY(role_id, permission_id)
);
(类似于这个数据模型)
桌子:
问题:
我有两个关键问题:
显然在实践中处理权限将需要RLS或其他方式,这只是一个数据建模问题。
J