forked from OWASP/rbac
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Postgres NST schema to repository.
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Create Tables for PostgreSQL | ||
* | ||
* Default prefix is 'phprbac_'. To change the prefix, you must do a | ||
* search & replace before running this script. | ||
* | ||
* To change the default schema (depends on your account, but usually things | ||
* will default to the 'public' schema), you'll have to search & replace | ||
* 'phprbac_' to be something like 'myschema.myprefix_' and add the line: | ||
* | ||
* CREATE SCHEMA myschema; | ||
*/ | ||
|
||
CREATE TABLE phprbac_permissions ( | ||
id SERIAL, | ||
lft INTEGER NOT NULL, | ||
rgt INTEGER NOT NULL CHECK (rgt > Lft), | ||
title TEXT NOT NULL, | ||
description text NOT NULL, | ||
PRIMARY KEY (id) | ||
); | ||
CREATE INDEX perms_title_ndx ON phprbac_permissions (title); | ||
CREATE INDEX perms_lft_ndx ON phprbac_permissions (lft); | ||
CREATE INDEX perms_rgt_ndx ON phprbac_permissions (rgt); | ||
|
||
CREATE TABLE IF NOT EXISTS phprbac_roles ( | ||
id SERIAL, | ||
lft INTEGER NOT NULL, | ||
rgt INTEGER NOT NULL CHECK (rgt > lft), | ||
title TEXT NOT NULL, | ||
description TEXT NOT NULL, | ||
PRIMARY KEY (id) | ||
); | ||
CREATE INDEX roles_title_ndx ON phprbac_roles (title); | ||
CREATE INDEX roles_lft_ndx ON phprbac_roles (lft); | ||
CREATE INDEX roles_rft_ndx ON phprbac_roles (rgt); | ||
|
||
CREATE TABLE IF NOT EXISTS phprbac_rolepermissions ( | ||
roleid INTEGER NOT NULL, | ||
permissionid INTEGER NOT NULL, | ||
assignmentdate INTEGER NOT NULL, | ||
primarY KEY (roleid, permissionid) | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS phprbac_userroles ( | ||
userid INTEGER NOT NULL, | ||
roleid INTEGER NOT NULL, | ||
assignmentdate INTEGER NOT NULL, | ||
PRIMARY KEY (userid, roleid) | ||
); | ||
|
||
/* | ||
* Insert Initial Table Data | ||
*/ | ||
|
||
INSERT INTO phprbac_permissions (id, lft, rgt, title, description) | ||
VALUES (DEFAULT, 0, 1, 'root', 'root'); | ||
|
||
INSERT INTO phprbac_roles (id, lft, rgt, title, description) | ||
VALUES (DEFAULT, 0, 1, 'root', 'root'); | ||
|
||
INSERT INTO phprbac_rolepermissions (roleid, permissionid, assignmentdate) | ||
VALUES (1, 1, extract(epoch from now())); | ||
|
||
INSERT INTO phprbac_userroles (userid, roleid, assignmentdate) | ||
VALUES (1, 1, extract(epoch from now())); |