Add to git.
[monolith.git] / sql / monolith_users_create.sql
1 -- Create schema for monolith users.
2 -- - by Richard W.M. Jones <rich@annexia.org>
3 --
4 -- This library is free software; you can redistribute it and/or
5 -- modify it under the terms of the GNU Library General Public
6 -- License as published by the Free Software Foundation; either
7 -- version 2 of the License, or (at your option) any later version.
8 --
9 -- This library is distributed in the hope that it will be useful,
10 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 -- Library General Public License for more details.
13 --
14 -- You should have received a copy of the GNU Library General Public
15 -- License along with this library; if not, write to the Free
16 -- Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 --
18 -- $Id: monolith_users_create.sql,v 1.2 2002/11/15 20:46:05 rich Exp $
19 --
20 -- Depends: monolith_core
21
22 -- Monolith does not require that you use this table. You can modify
23 -- the schema in monolith_auth_create.sql to use your own users table
24 -- if you wish. However, many of the monolith standard widgets use
25 -- this table for accessing user information.
26
27 begin work;
28
29 create table ml_users
30 (
31         userid serial,          -- Unique number for each user
32         email text              -- Unique email address for each user
33                 constraint ml_users_email_nn
34                 not null,
35         username varchar(32)    -- Displayed username (not necessarily unique)
36                 constraint ml_users_username_nn
37                 not null,
38         password varchar(32),   -- Hashed password (not always required)
39
40         -- Personal data.
41         given_name text,        -- Forename (in western locales)
42         family_name text,       -- Surname (in western locales)
43         date_of_birth date,     -- Date of birth
44         gender char(1)          -- Gender
45                 constraint ml_users_gender_ck
46                 check (gender in ('m', 'f')),
47
48         -- Locale information.
49         langcode char(8),       -- Language and modifiers
50         timezone int4           -- POSIX Timezone
51                 references ml_timezones (id),
52         countrycode char(2)     -- ISO country code
53                 references ml_countries (code),
54
55         -- Accounting information.
56         signup_date date        -- When the account was created
57                 default current_date
58                 constraint ml_users_signup_date_nn
59                 not null,
60         lastlogin_date date,    -- When they last logged in
61         nr_logins int4          -- Number of times they have logged in
62                 default 0
63                 constraint ml_users_nr_logins_nn
64                 not null,
65         bad_logins int4         -- Since they last logged in, how many bad
66                                 -- login attempts have been made
67                 default 0
68                 constraint ml_users_bad_logins_nn
69                 not null
70 );
71
72 create unique index ml_users_email_ui on ml_users (email);
73
74 -- Grant access to the webserver.
75
76 grant select, insert, update, delete on ml_users to nobody;
77 grant select, update on ml_users_userid_seq to nobody;
78
79 commit work;