1 -- Tables needed for AWL Libraries
5 CREATE TABLE supported_locales (
6 locale TEXT PRIMARY KEY,
8 locale_name_locale TEXT
11 -- This is the table of users for the system
13 user_no SERIAL PRIMARY KEY,
14 active BOOLEAN DEFAULT TRUE,
16 joined TIMESTAMPTZ DEFAULT current_timestamp,
18 last_used TIMESTAMPTZ,
19 username TEXT NOT NULL, -- Note UNIQUE INDEX below constains case-insensitive uniqueness
24 date_format_type TEXT DEFAULT 'E', -- default to english date format dd/mm/yyyy
27 CREATE FUNCTION max_usr() RETURNS INT4 AS 'SELECT max(user_no) FROM usr' LANGUAGE 'sql';
28 CREATE UNIQUE INDEX usr_sk1_unique_username ON usr ( lower(username) );
30 CREATE TABLE usr_setting (
31 user_no INT4 REFERENCES usr ( user_no ) ON DELETE CASCADE,
34 PRIMARY KEY ( user_no, setting_name )
37 CREATE FUNCTION get_usr_setting(INT4,TEXT)
39 AS 'SELECT setting_value FROM usr_setting
40 WHERE usr_setting.user_no = $1
41 AND usr_setting.setting_name = $2 ' LANGUAGE 'sql';
44 role_no SERIAL PRIMARY KEY,
47 CREATE FUNCTION max_roles() RETURNS INT4 AS 'SELECT max(role_no) FROM roles' LANGUAGE 'sql';
50 CREATE TABLE role_member (
51 role_no INT4 REFERENCES roles ( role_no ),
52 user_no INT4 REFERENCES usr ( user_no ) ON DELETE CASCADE
56 CREATE TABLE session (
57 session_id SERIAL PRIMARY KEY,
58 user_no INT4 REFERENCES usr ( user_no ) ON DELETE CASCADE,
59 session_start TIMESTAMPTZ DEFAULT current_timestamp,
60 session_end TIMESTAMPTZ DEFAULT current_timestamp,
64 CREATE FUNCTION max_session() RETURNS INT4 AS 'SELECT max(session_id) FROM session' LANGUAGE 'sql';
66 CREATE TABLE tmp_password (
67 user_no INT4 REFERENCES usr ( user_no ),
69 valid_until TIMESTAMPTZ DEFAULT (current_timestamp + '1 day'::interval)