3 -- Run this script to create the Gaixie database tables in your database.
5 -- *****************************************************
6 -- Create the tables and indices
8 -- ------------------------------------------------------
9 CREATE TABLE userbase (
10 id integer generated by default as identity 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 smallint default 1 NOT NULL
17 ALTER TABLE userbase ADD CONSTRAINT userbase_username_uq UNIQUE ( username );
19 -- ------------------------------------------------------
21 id integer generated by default as identity NOT NULL PRIMARY KEY,
22 name varchar(128) NOT NULL,
25 description varchar(512) NOT NULL
27 ALTER TABLE roles ADD CONSTRAINT roles_name_uq UNIQUE ( name );
29 -- ------------------------------------------------------
30 CREATE TABLE user_role_map (
31 user_id integer NOT NULL,
32 role_id integer NOT NULL
34 ALTER TABLE user_role_map ADD CONSTRAINT user_role_map_ur_id_uq UNIQUE ( user_id,role_id );
35 ALTER TABLE user_role_map ADD CONSTRAINT urmap_role_id_fk FOREIGN KEY (role_id) REFERENCES roles (id);
36 ALTER TABLE user_role_map ADD CONSTRAINT urmap_user_id_fk FOREIGN KEY (user_id) REFERENCES userbase (id);
38 -- ------------------------------------------------------
39 CREATE TABLE authorities (
40 id integer generated by default as identity NOT NULL PRIMARY KEY,
41 name varchar(128) NOT NULL,
42 value varchar(128) NOT NULL
44 ALTER TABLE authorities ADD CONSTRAINT authorities_value_uq UNIQUE ( value );
46 -- ------------------------------------------------------
47 CREATE TABLE role_authority_map (
48 role_id integer NOT NULL,
49 authority_id integer NOT NULL
51 ALTER TABLE role_authority_map ADD CONSTRAINT role_authority_map_ra_id_uq UNIQUE ( role_id,authority_id );
52 ALTER TABLE role_authority_map ADD CONSTRAINT rrmap_role_id_fk FOREIGN KEY (role_id) REFERENCES roles (id);
53 ALTER TABLE role_authority_map ADD CONSTRAINT rrmap_authority_id_fk FOREIGN KEY (authority_id) REFERENCES authorities (id);
55 -- ------------------------------------------------------
56 CREATE TABLE settings(
57 id integer generated by default as identity NOT NULL PRIMARY KEY,
58 name varchar(32) NOT NULL,
59 value varchar(32) NOT NULL,
60 sortindex integer default 0 NOT NULL,
61 enabled smallint default 1 NOT NULL
63 ALTER TABLE settings ADD CONSTRAINT setting_name_sortindex_uq UNIQUE ( name,sortindex );
64 ALTER TABLE settings ADD CONSTRAINT setting_name_value_uq UNIQUE ( name,value );
66 -- ------------------------------------------------------
67 CREATE TABLE user_setting_map(
68 user_id integer NOT NULL,
69 setting_id integer NOT NULL
71 ALTER TABLE user_setting_map ADD CONSTRAINT usm_user_id_setting_id_uq UNIQUE ( user_id,setting_id );
73 -- ------------------------------------------------------
75 id integer generated by default as identity NOT NULL PRIMARY KEY,
76 value varchar(64) NOT NULL,
77 type varchar(16) NOT NULL,
78 expiration timestamp NOT NULL,
79 user_id integer NOT NULL
81 ALTER TABLE tokens ADD CONSTRAINT tokens_value_uq UNIQUE ( value );
82 ALTER TABLE tokens ADD CONSTRAINT tokens_user_id_fk FOREIGN KEY (user_id) REFERENCES userbase (id);