This repository has been archived by the owner on Jan 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrbac.sql
55 lines (47 loc) · 1.48 KB
/
rbac.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* Create Tables
*/
drop table if exists rbac_permissions, rbac_rolepermissions, rbac_roles, rbac_userroles;
create table if not exists rbac_permissions (
id serial primary key,
lft integer not null,
rght integer not null,
title text not null,
description text not null
);
create index on rbac_permissions (lft);
create index on rbac_permissions (rght);
create index on rbac_permissions (title);
create table if not exists rbac_rolepermissions (
role_id integer not null,
permission_id integer not null,
assignment_date timestamptz not null,
primary key (role_id, permission_id)
);
create table if not exists rbac_roles (
id serial primary key,
lft integer not null,
rght integer not null,
title varchar not null,
description text not null
);
create index on rbac_roles (lft);
create index on rbac_roles (rght);
create index on rbac_roles (title);
create table if not exists rbac_userroles (
user_id integer not null,
role_id integer not null,
assignment_date timestamptz not null,
primary key (user_id, role_id)
);
/*
* Insert Initial Table Data
*/
insert into rbac_permissions (id, lft, rght, title, description)
values (1, 0, 1, 'root', 'root');
insert into rbac_rolepermissions (role_id, permission_id, assignment_date)
values (1, 1, current_timestamp);
insert into rbac_roles (id, lft, rght, title, description)
values (1, 0, 1, 'root', 'root');
insert into rbac_userroles (user_id, Role_id, assignment_date)
values (1, 1, current_timestamp);