2024-06-21 20:29:50 -05:00
|
|
|
/* init_order = 1.1 */
|
2023-10-07 04:49:28 -05:00
|
|
|
|
|
|
|
/** The roles defined by the organization template. */
|
|
|
|
create table organization_roles (
|
|
|
|
tenant_id varchar(21) not null
|
|
|
|
references tenants (id) on update cascade on delete cascade,
|
|
|
|
/** The globally unique identifier of the organization role. */
|
|
|
|
id varchar(21) not null,
|
|
|
|
/** The organization role's name, unique within the organization template. */
|
|
|
|
name varchar(128) not null,
|
|
|
|
/** A brief description of the organization role. */
|
2023-10-08 00:47:22 -05:00
|
|
|
description varchar(256),
|
2024-06-21 20:29:50 -05:00
|
|
|
/** The type of the organization role. Same as the `type` field in the `roles` table. */
|
|
|
|
type role_type not null default 'User',
|
2023-10-07 04:49:28 -05:00
|
|
|
primary key (id),
|
|
|
|
constraint organization_roles__name
|
|
|
|
unique (tenant_id, name)
|
|
|
|
);
|
|
|
|
|
|
|
|
create index organization_roles__id
|
|
|
|
on organization_roles (tenant_id, id);
|
2024-06-21 20:29:50 -05:00
|
|
|
|
|
|
|
create function check_organization_role_type(role_id varchar(21), target_type role_type) returns boolean as
|
|
|
|
$$ begin
|
|
|
|
return (select type from organization_roles where id = role_id) = target_type;
|
2024-06-24 05:11:43 -05:00
|
|
|
end; $$ language plpgsql set search_path = public;
|