Re: storing access rights in a postgres database

Поиск
Список
Период
Сортировка
От Dirk Jagdmann
Тема Re: storing access rights in a postgres database
Дата
Msg-id 5d0f60990610101457w36b0a3f5r9e4110c7194fd14c@mail.gmail.com
обсуждение исходный текст
Ответ на storing access rights in a postgres database  (tv@fuzzy.cz)
Список pgsql-sql
Hello tv,

I think in your case the PostgreSQL array column type really fits
well. I would just add an array of type integer (or whatever your
primary key in your role table is) to your company, project, module,
... tables. Then you can easy check if a role has access to the
project row by checking if the roles primary key is contained in the
role array. And you can easily select over the entire project table
and matching any values in the role array.

Here are some (untested) SQL statements to clarify my suggestion:

create table role ( id serial primary key, name text );
create table project ( id serial primary key, name text, roles int[] );
create table company ( id serial primary key, name text, roles int[] );
insert into role values(1,'you');
insert into role values(2,'me');
insert into project values(1,'a',{1,2});
insert into project values(2,'b',{2});
-- check if I can access a project
select id from project where name='a' and 2=ANY(roles); -- 2 is 'my' role id
-- get all companies I have access to
select id,name from company where 2=ANY(roles);

I think the foreign key constraints can not be enforced with the
standard foreign key triggers/functions so you would have to write
your own plpgsql triggers if this is a mandatory requirement.

-- 
---> Dirk Jagdmann
----> http://cubic.org/~doj
-----> http://llg.cubic.org


В списке pgsql-sql по дате отправления:

Предыдущее
От: "Dirk Jagdmann"
Дата:
Сообщение: Re: optimal insert
Следующее
От: "Jim C. Nasby"
Дата:
Сообщение: Re: Temp tables and functions