Subversion Repositories general

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
906 dev 1
--
924 dev 2
-- hostadmiral sql tables
906 dev 3
--
923 dev 4
-- FIXME: which values has boolean in hibernate - '1':' ' or '1':'0'?
906 dev 5
 
899 dev 6
create sequence hibernate_sequence;
7
 
8
-- an user is allowed to:
9
--   see/use an user if he is the 'boss' or is the same user
10
--   modify password - as above
11
--   modify login - only if he is the 'boss', not of his own, and only inside some name rules (e.g. name@domain)
913 dev 12
-- 'superuser' is allowed to do anything with all objects, but cannot delete himself or modify own
899 dev 13
--   'superuser' flag (to guarantee at least one superuser exists in the system)
14
create table users
15
(
16
	id          integer                         not null,
17
	login       varchar(255)                    not null,
18
	password    varchar(255)                    not null,
19
	boss        integer,
913 dev 20
	superuser   char(1)                         default ' ' check (superuser = '1' or superuser = ' '),
950 dev 21
	locale      varchar(5)                      default 'en', -- language_country
913 dev 22
	enabled     char(1)                         default '1' check (enabled   = '1' or enabled   = ' '),
23
	comment     text,
899 dev 24
	mod_stamp   timestamp,
25
	mod_user    integer,
26
 
27
	constraint users_prim  primary key (id),
28
	constraint users_login unique(login),
29
	constraint users_boss  foreign key (boss) references users(id)
30
);
31
 
949 dev 32
-- login tries. "usr" is set if the user is found only
33
create table userlogins
34
(
35
	id          integer                         not null,
36
	usr         integer,
37
	login       varchar(255)                    not null,
38
	logintime   timestamp                       not null,
39
	success     char(1)                         default '0' check (success = '1' or success = '0'),
40
    ip          inet                            not null,
41
 
42
	constraint userlogins_prim primary key (id),
43
	constraint userlogins_user foreign key (usr) references users(id)
44
);
45
 
899 dev 46
-- default user admin:admin
913 dev 47
insert into users (id, login, password, superuser) values (1, 'admin', '21232f297a57a5a743894a0e4a801fc3', '1');
899 dev 48
select nextval('hibernate_sequence'); -- skip id of the default user
49
 
50
-- an user is allowed to see and use a system user if he is the 'owner' or the system user has no owner (null)
51
create table systemusers
52
(
53
	id          integer                         not null,
54
	uid         integer                         not null,
55
	name        varchar(255)                    not null,
56
	owner       integer,
913 dev 57
	enabled     char(1)                         default '1' check (enabled   = '1' or enabled   = ' '),
58
	comment     text,
899 dev 59
	mod_stamp   timestamp,
60
	mod_user    integer,
61
 
62
	constraint systemusers_prim  primary key (id),
63
	constraint systemusers_uid   unique(uid),
64
	constraint systemusers_name  unique(name),
65
	constraint systemusers_owner foreign key (owner) references users(id)
66
);
67
 
68
create table domains
69
(
70
	id          integer                         not null,
71
	name        varchar(255)                    not null,
72
	owner       integer                         not null,
913 dev 73
	enabled     char(1)                         default '1' check (enabled   = '1' or enabled   = ' '),
74
	comment     text,
899 dev 75
	mod_stamp   timestamp,
76
	mod_user    integer,
77
 
78
	constraint domains_prim  primary key (id),
79
	constraint domains_name  unique(name),
80
	constraint domains_owner foreign key (owner) references users(id)
81
);
82
 
83
-- name of mailbox = login + '@' + domain, e.g. user@example.com
84
-- FIXME: make a possibility to use global unique mailboxes
85
create table mailboxes
86
(
87
	id          integer                         not null,
88
	login       varchar(255)                    not null,
89
	password    varchar(255),                             -- if null, then owner's password is used
90
	domain      integer                         not null,
91
	owner       integer                         not null,
913 dev 92
	virusCheck  char(1)                         default '1' check (virusCheck = '1' or virusCheck = ' '),
93
	spamCheck   char(1)                         default '1' check (spamCheck  = '1' or spamCheck  = ' '),
899 dev 94
	systemuser  integer,
913 dev 95
	enabled     char(1)                         default '1' check (enabled    = '1' or enabled    = ' '),
96
	comment     text,
899 dev 97
	mod_stamp   timestamp,
98
	mod_user    integer,
99
 
100
	constraint mailboxes_prim       primary key (id),
101
	constraint mailboxes_name       unique(login, domain),
102
	constraint mailboxes_domain     foreign key (domain)     references domains(id),
103
	constraint mailboxes_owner      foreign key (owner)      references users(id),
104
	constraint mailboxes_systemuser foreign key (systemuser) references systemusers(id)
105
);
106
 
107
-- email address of alias = address + '@' + domain, e.g. user@example.com
108
create table mailaliases
109
(
110
	id          integer                         not null,
111
	address     varchar(255)                    not null,
112
	domain      integer                         not null,
113
	owner       integer                         not null,
913 dev 114
	enabled     char(1)                         default '1' check (enabled   = '1' or enabled   = ' '),
115
	comment     text,
899 dev 116
	mod_stamp   timestamp,
117
	mod_user    integer,
118
 
119
	constraint mailaliases_prim   primary key (id),
120
	constraint mailaliases_name   unique(address, domain),
121
	constraint mailaliases_domain foreign key (domain) references domains(id),
122
	constraint mailaliases_owner  foreign key (owner)  references users(id)
123
);
124
 
125
create table mailaliasdests
126
(
127
	id          integer                         not null,
128
	alias       integer                         not null,
129
	mailbox     integer,
130
	email       varchar(255),
913 dev 131
	enabled     char(1)                         default '1' check (enabled   = '1' or enabled   = ' '),
132
	comment     text,
899 dev 133
	mod_stamp   timestamp,
134
	mod_user    integer,
135
 
136
	constraint mailaliasdests_prim    primary key (id),
137
	constraint mailaliasdests_dest    check ((mailbox notnull) or (email notnull)),
138
	constraint mailaliasdests_mailbox foreign key (mailbox) references mailboxes(id),
139
	constraint mailaliasdests_email   check ((email isnull) or (char_length(email) > 0))
140
);