|
| 1 | +/* |
| 2 | + * Create Tables |
| 3 | + */ |
| 4 | +drop table rbac_permissions, rbac_rolepermissions, rbac_roles, rbac_userroles; |
| 5 | + |
| 6 | +create table if not exists rbac_permissions ( |
| 7 | + id serial primary key, |
| 8 | + lft integer not null, |
| 9 | + rght integer not null, |
| 10 | + title text not null, |
| 11 | + description text not null |
| 12 | +); |
| 13 | +create index on rbac_permissions (lft); |
| 14 | +create index on rbac_permissions (rght); |
| 15 | +create index on rbac_permissions (title); |
| 16 | + |
| 17 | +create table if not exists rbac_rolepermissions ( |
| 18 | + role_id integer not null, |
| 19 | + permission_id integer not null, |
| 20 | + assignment_date timestamptz not null, |
| 21 | + primary key (role_id, permission_id) |
| 22 | +); |
| 23 | + |
| 24 | +create table if not exists rbac_roles ( |
| 25 | + id serial primary key, |
| 26 | + lft integer not null, |
| 27 | + rght integer not null, |
| 28 | + title varchar not null, |
| 29 | + description text not null |
| 30 | +); |
| 31 | +create index on rbac_roles (lft); |
| 32 | +create index on rbac_roles (rght); |
| 33 | +create index on rbac_roles (title); |
| 34 | + |
| 35 | +create table if not exists rbac_userroles ( |
| 36 | + user_id integer not null, |
| 37 | + role_id integer not null, |
| 38 | + assignment_date timestamptz not null, |
| 39 | + primary key (user_id, role_id) |
| 40 | +); |
| 41 | + |
| 42 | +/* |
| 43 | + * Insert Initial Table Data |
| 44 | + */ |
| 45 | +insert into rbac_permissions (id, lft, rght, title, description) |
| 46 | +values (1, 0, 1, 'root', 'root'); |
| 47 | + |
| 48 | +insert into rbac_rolepermissions (role_id, permission_id, assignment_date) |
| 49 | +values (1, 1, current_timestamp); |
| 50 | + |
| 51 | +insert into rbac_roles (id, lft, rght, title, description) |
| 52 | +values (1, 0, 1, 'root', 'root'); |
| 53 | + |
| 54 | +insert into rbac_userroles (user_id, Role_id, assignment_date) |
| 55 | +values (1, 1, current_timestamp); |
0 commit comments