0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-23 20:33:16 -05:00
logto/packages/schemas/tables/roles.sql

26 lines
830 B
MySQL
Raw Normal View History

2023-01-19 07:27:01 -05:00
/* init_order = 1 */
create type role_type as enum ('User', 'MachineToMachine');
create table roles (
2023-01-19 07:27:01 -05:00
tenant_id varchar(21) not null
references tenants (id) on update cascade on delete cascade,
id varchar(21) not null,
name varchar(128) not null,
description varchar(128) not null,
type role_type not null default 'User',
/** If the role is the default role for a new user. Should be ignored for `MachineToMachine` roles. */
is_default boolean not null default false,
2023-01-19 07:27:01 -05:00
primary key (id),
constraint roles__name
unique (tenant_id, name)
);
2023-01-19 07:27:01 -05:00
create index roles__id
on roles (tenant_id, id);
create function public.check_role_type(role_id varchar(21), target_type role_type) returns boolean as
$$ begin
return (select type from public.roles where id = role_id) = target_type;
end; $$ language plpgsql;