Here are three tables
Table users {
id uuid [pk, default: `gen_random_uuid()`]
auth_id uuid [ref: - auths.id]
org_id uuid [ref: - orgs.id]
access_group text [default: 'DEFAULT']
created_at int [default: `now()::int`]
updated_at int
age int
status text
}
Table op_user_access_groups {
op_id uuid [pk, ref: > ops.id]
access_group text [pk, default: 'DEFAULT']
}
Table op_users {
op_id uuid [pk, ref: > ops.id]
user_id uuid [pk, ref: > users.id]
access boolean [default: false]
}
- The table
usershas user info and he/she belongs to certain organization (org_id) - The table
op_user_access_groupshas the information regarding an operator having access to what all access_groups. Theop_idbelongs to theorg_id - The table
op_usershas information about users (user_id) that can be accessed byop_idirrespective of which group a user belongs to.
I want to create a view such that if I do
select * from <that view> where op_id = ?
I should get the users the operator has access to.
Any help is appreciated :)