3 -- Run this script to create the Jibu database tables in your database.
5 -- *****************************************************
6 -- Create the tables and indices
8 -- ------------------------------------------------------
9 CREATE TABLE userbase (
10 id integer NOT NULL PRIMARY KEY,
11 username varchar(128) NOT NULL,
12 password varchar(64) NOT NULL,
13 fullname varchar(128) NOT NULL,
14 emailaddress varchar(128),
15 enabled number(1) default 1 NOT NULL
17 ALTER TABLE userbase ADD CONSTRAINT userbase_username_uq UNIQUE ( username );
19 CREATE sequence userbase_seq;
20 CREATE OR REPLACE trigger trg_userbase before insert on userbase for each row
21 BEGIN select userbase_seq.nextval into :new.id from dual; END;
24 -- ------------------------------------------------------
26 id integer NOT NULL PRIMARY KEY,
27 name varchar(128) NOT NULL,
30 description varchar(512) NOT NULL
32 ALTER TABLE roles ADD CONSTRAINT roles_name_uq UNIQUE ( name );
34 CREATE sequence roles_seq;
35 CREATE OR REPLACE trigger trg_roles before insert on roles for each row
36 BEGIN select roles_seq.nextval into :new.id from dual; END;
39 -- ------------------------------------------------------
40 CREATE TABLE user_role_map (
41 user_id integer NOT NULL,
42 role_id integer NOT NULL
44 ALTER TABLE user_role_map ADD CONSTRAINT urmap_user_id_role_id_uq UNIQUE ( user_id,role_id );
45 ALTER TABLE user_role_map ADD CONSTRAINT urmap_role_id_fk FOREIGN KEY (role_id) REFERENCES roles (id);
46 ALTER TABLE user_role_map ADD CONSTRAINT urmap_user_id_fk FOREIGN KEY (user_id) REFERENCES userbase (id);
48 -- ------------------------------------------------------
49 CREATE TABLE authorities (
50 id integer NOT NULL PRIMARY KEY,
51 name varchar(128) NOT NULL,
52 value varchar(128) NOT NULL
54 ALTER TABLE authorities ADD CONSTRAINT authorities_value_uq UNIQUE ( value );
56 CREATE sequence authorities_seq;
57 CREATE OR REPLACE trigger trg_authorities before insert on authorities for each row
58 BEGIN select authorities_seq.nextval into :new.id from dual; END;
61 -- ------------------------------------------------------
62 CREATE TABLE role_authority_map (
63 role_id integer NOT NULL,
64 authority_id integer NOT NULL
66 ALTER TABLE role_authority_map ADD CONSTRAINT ramap_role_id_authority_id_uq UNIQUE ( role_id,authority_id );
67 ALTER TABLE role_authority_map ADD CONSTRAINT ramap_role_id_fk FOREIGN KEY (role_id) REFERENCES roles (id);
68 ALTER TABLE role_authority_map ADD CONSTRAINT ramap_authority_id_fk FOREIGN KEY (authority_id) REFERENCES authorities (id);
70 -- ------------------------------------------------------
71 CREATE TABLE settings(
72 id integer NOT NULL PRIMARY KEY,
73 name varchar(32) NOT NULL,
74 value varchar(32) NOT NULL,
75 sortindex integer default 0 NOT NULL,
76 enabled number(1) default 1 NOT NULL
78 ALTER TABLE settings ADD CONSTRAINT setting_name_sortindex_uq UNIQUE ( name,sortindex );
79 ALTER TABLE settings ADD CONSTRAINT setting_name_value_uq UNIQUE ( name,value );
81 CREATE sequence settings_seq;
82 CREATE OR REPLACE trigger trg_settings before insert on settings for each row
83 BEGIN select settings_seq.nextval into :new.id from dual; END;
86 -- ------------------------------------------------------
87 CREATE TABLE user_setting_map(
88 user_id integer NOT NULL,
89 setting_id integer NOT NULL
91 ALTER TABLE user_setting_map ADD CONSTRAINT usmap_user_id_setting_id_uq UNIQUE ( user_id,setting_id );
92 ALTER TABLE user_setting_map ADD CONSTRAINT usmap_user_id_fk FOREIGN KEY (user_id) REFERENCES userbase (id);
93 ALTER TABLE user_setting_map ADD CONSTRAINT usmap_setting_id_fk FOREIGN KEY (setting_id) REFERENCES settings (id);
95 -- ------------------------------------------------------
97 id integer NOT NULL PRIMARY KEY,
98 value varchar(64) NOT NULL,
99 type varchar(16) NOT NULL,
100 expiration timestamp NOT NULL,
101 user_id integer NOT NULL
103 ALTER TABLE tokens ADD CONSTRAINT tokens_value_uq UNIQUE ( value );
104 ALTER TABLE tokens ADD CONSTRAINT tokens_user_id_fk FOREIGN KEY (user_id) REFERENCES userbase (id);
106 CREATE sequence tokens_seq;
107 CREATE OR REPLACE trigger trg_tokens before insert on tokens for each row
108 BEGIN select tokens_seq.nextval into :new.id from dual; END;