author | Pascal Volk <user@localhost.localdomain.org> |
Sun, 08 Apr 2012 16:20:43 +0000 | |
branch | v0.6.x |
changeset 500 | 5ccc9c6e5193 |
parent 437 | 9823548b2717 |
child 502 | e1b32377032f |
permissions | -rw-r--r-- |
297
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
1 |
SET client_encoding = 'UTF8'; |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
2 |
SET client_min_messages = warning; |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
3 |
|
437
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
4 |
-- --- |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
5 |
-- Create the new service_set table and insert all possible combinations |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
6 |
-- -- |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
7 |
CREATE SEQUENCE service_set_id; |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
8 |
|
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
9 |
CREATE TABLE service_set ( |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
10 |
ssid bigint NOT NULL DEFAULT nextval('service_set_id'), |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
11 |
smtp boolean NOT NULL DEFAULT TRUE, |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
12 |
pop3 boolean NOT NULL DEFAULT TRUE, |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
13 |
imap boolean NOT NULL DEFAULT TRUE, |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
14 |
managesieve boolean NOT NULL DEFAULT TRUE, |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
15 |
CONSTRAINT pkey_service_set PRIMARY KEY (ssid), |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
16 |
CONSTRAINT ukey_service_set UNIQUE (smtp, pop3, imap, managesieve) |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
17 |
); |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
18 |
|
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
19 |
COPY service_set (smtp, pop3, imap, managesieve) FROM stdin; |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
20 |
TRUE TRUE TRUE TRUE |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
21 |
FALSE TRUE TRUE TRUE |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
22 |
TRUE FALSE TRUE TRUE |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
23 |
FALSE FALSE TRUE TRUE |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
24 |
TRUE TRUE FALSE TRUE |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
25 |
FALSE TRUE FALSE TRUE |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
26 |
TRUE FALSE FALSE TRUE |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
27 |
FALSE FALSE FALSE TRUE |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
28 |
TRUE TRUE TRUE FALSE |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
29 |
FALSE TRUE TRUE FALSE |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
30 |
TRUE FALSE TRUE FALSE |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
31 |
FALSE FALSE TRUE FALSE |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
32 |
TRUE TRUE FALSE FALSE |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
33 |
FALSE TRUE FALSE FALSE |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
34 |
TRUE FALSE FALSE FALSE |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
35 |
FALSE FALSE FALSE FALSE |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
36 |
\. |
297
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
37 |
|
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
38 |
-- --- |
500
5ccc9c6e5193
pgsql: Removed most of the VIEWs.
Pascal Volk <user@localhost.localdomain.org>
parents:
437
diff
changeset
|
39 |
-- Drop the obsolete VIEWs, we've functions now. |
297
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
40 |
-- --- |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
41 |
DROP VIEW dovecot_user; |
437
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
42 |
DROP VIEW dovecot_password; |
500
5ccc9c6e5193
pgsql: Removed most of the VIEWs.
Pascal Volk <user@localhost.localdomain.org>
parents:
437
diff
changeset
|
43 |
DROP VIEW postfix_alias; |
297
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
44 |
DROP VIEW postfix_maildir; |
500
5ccc9c6e5193
pgsql: Removed most of the VIEWs.
Pascal Volk <user@localhost.localdomain.org>
parents:
437
diff
changeset
|
45 |
DROP VIEW postfix_relocated; |
5ccc9c6e5193
pgsql: Removed most of the VIEWs.
Pascal Volk <user@localhost.localdomain.org>
parents:
437
diff
changeset
|
46 |
DROP VIEW postfix_transport; |
5ccc9c6e5193
pgsql: Removed most of the VIEWs.
Pascal Volk <user@localhost.localdomain.org>
parents:
437
diff
changeset
|
47 |
DROP VIEW postfix_uid; |
5ccc9c6e5193
pgsql: Removed most of the VIEWs.
Pascal Volk <user@localhost.localdomain.org>
parents:
437
diff
changeset
|
48 |
-- the vmm_domain_info view will be restored later |
391
8217ddd5220d
pgsql: Updated view vmm_domain_info. No longer select data we have already.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
388
diff
changeset
|
49 |
DROP VIEW vmm_domain_info; |
297
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
50 |
|
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
51 |
CREATE SEQUENCE mailboxformat_id; |
382
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
52 |
CREATE SEQUENCE quotalimit_id; |
297
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
53 |
|
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
54 |
CREATE TABLE mailboxformat ( |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
55 |
fid bigint NOT NULL DEFAULT nextval('mailboxformat_id'), |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
56 |
format varchar(20) NOT NULL, |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
57 |
CONSTRAINT pkey_mailboxformat PRIMARY KEY (fid), |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
58 |
CONSTRAINT ukey_mailboxformat UNIQUE (format) |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
59 |
); |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
60 |
-- Insert supported mailbox formats |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
61 |
INSERT INTO mailboxformat(format) VALUES ('maildir'); |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
62 |
INSERT INTO mailboxformat(format) VALUES ('mdbox'); |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
63 |
INSERT INTO mailboxformat(format) VALUES ('sdbox'); |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
64 |
|
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
65 |
-- Adjust maillocation table |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
66 |
ALTER TABLE maillocation DROP CONSTRAINT ukey_maillocation; |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
67 |
ALTER TABLE maillocation RENAME COLUMN maillocation TO directory; |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
68 |
ALTER TABLE maillocation |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
69 |
ADD COLUMN fid bigint NOT NULL DEFAULT 1, |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
70 |
ADD COLUMN extra varchar(1024); |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
71 |
ALTER TABLE maillocation ADD CONSTRAINT fkey_maillocation_fid_mailboxformat |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
72 |
FOREIGN KEY (fid) REFERENCES mailboxformat (fid); |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
73 |
|
437
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
74 |
ALTER TABLE users ALTER COLUMN passwd TYPE varchar(270); |
297
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
75 |
|
382
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
76 |
-- --- |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
77 |
-- Add quota stuff |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
78 |
-- --- |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
79 |
CREATE TABLE quotalimit ( |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
80 |
qid bigint NOT NULL DEFAULT nextval('quotalimit_id'), |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
81 |
bytes bigint NOT NULL, |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
82 |
messages integer NOT NULL DEFAULT 0, |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
83 |
CONSTRAINT pkey_quotalimit PRIMARY KEY (qid), |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
84 |
CONSTRAINT ukey_quotalimit UNIQUE (bytes, messages) |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
85 |
); |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
86 |
-- Insert default (non) quota limit |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
87 |
INSERT INTO quotalimit(bytes, messages) VALUES (0, 0); |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
88 |
|
437
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
89 |
-- Adjust tables (quota) |
382
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
90 |
ALTER TABLE domain_data ADD COLUMN qid bigint NOT NULL DEFAULT 1; |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
91 |
ALTER TABLE domain_data ADD CONSTRAINT fkey_domain_data_qid_quotalimit |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
92 |
FOREIGN KEY (qid) REFERENCES quotalimit (qid); |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
93 |
|
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
94 |
ALTER TABLE users ADD COLUMN qid bigint NOT NULL DEFAULT 1; |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
95 |
ALTER TABLE users ADD CONSTRAINT fkey_users_qid_quotalimit |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
96 |
FOREIGN KEY (qid) REFERENCES quotalimit (qid); |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
97 |
|
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
98 |
CREATE TABLE userquota_11 ( |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
99 |
uid bigint NOT NULL, |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
100 |
path varchar(16) NOT NULL, |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
101 |
current bigint NOT NULL DEFAULT 0, |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
102 |
CONSTRAINT pkey_userquota_11 PRIMARY KEY (uid, path), |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
103 |
CONSTRAINT fkey_userquota_11_uid_users FOREIGN KEY (uid) |
387
05dc4e1f8dff
pgsql/{create,update}_tables*: Added the ON DELETE CASCADE clause
Pascal Volk <neverseen@users.sourceforge.net>
parents:
382
diff
changeset
|
104 |
REFERENCES users (uid) ON DELETE CASCADE |
382
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
105 |
); |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
106 |
|
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
107 |
CREATE OR REPLACE FUNCTION merge_userquota_11() RETURNS TRIGGER AS $$ |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
108 |
BEGIN |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
109 |
UPDATE userquota_11 |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
110 |
SET current = current + NEW.current |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
111 |
WHERE uid = NEW.uid AND path = NEW.path; |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
112 |
IF found THEN |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
113 |
RETURN NULL; |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
114 |
ELSE |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
115 |
RETURN NEW; |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
116 |
END IF; |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
117 |
END; |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
118 |
$$ LANGUAGE plpgsql; |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
119 |
|
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
120 |
CREATE TRIGGER mergeuserquota_11 BEFORE INSERT ON userquota_11 |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
121 |
FOR EACH ROW EXECUTE PROCEDURE merge_userquota_11(); |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
122 |
|
437
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
123 |
-- Adjust tables (services) |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
124 |
ALTER TABLE domain_data ADD COLUMN ssid bigint NOT NULL DEFAULT 1; |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
125 |
ALTER TABLE domain_data ADD CONSTRAINT fkey_domain_data_ssid_service_set |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
126 |
FOREIGN KEY (ssid) REFERENCES service_set (ssid); |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
127 |
|
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
128 |
ALTER TABLE users ADD COLUMN ssid bigint NOT NULL DEFAULT 1; |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
129 |
-- save current service sets |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
130 |
UPDATE users u |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
131 |
SET ssid = ss.ssid |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
132 |
FROM service_set ss |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
133 |
WHERE ss.smtp = u.smtp |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
134 |
AND ss.pop3 = u.pop3 |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
135 |
AND ss.imap = u.imap |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
136 |
AND ss.managesieve = u.managesieve; |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
137 |
|
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
138 |
ALTER TABLE users DROP COLUMN smtp; |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
139 |
ALTER TABLE users DROP COLUMN pop3; |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
140 |
ALTER TABLE users DROP COLUMN imap; |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
141 |
ALTER TABLE users DROP COLUMN managesieve; |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
142 |
ALTER TABLE users ADD CONSTRAINT fkey_users_ssid_service_set |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
143 |
FOREIGN KEY (ssid) REFERENCES service_set (ssid); |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
144 |
|
382
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
145 |
-- --- |
500
5ccc9c6e5193
pgsql: Removed most of the VIEWs.
Pascal Volk <user@localhost.localdomain.org>
parents:
437
diff
changeset
|
146 |
-- Restore view |
382
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
147 |
-- --- |
391
8217ddd5220d
pgsql: Updated view vmm_domain_info. No longer select data we have already.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
388
diff
changeset
|
148 |
CREATE VIEW vmm_domain_info AS |
8217ddd5220d
pgsql: Updated view vmm_domain_info. No longer select data we have already.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
388
diff
changeset
|
149 |
SELECT gid, count(uid) AS accounts, |
388
dd95ed5bc9d2
pgsql: Added quotalimit's bytes and messages to view vmm_domain_info.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
387
diff
changeset
|
150 |
(SELECT count(DISTINCT address) |
dd95ed5bc9d2
pgsql: Added quotalimit's bytes and messages to view vmm_domain_info.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
387
diff
changeset
|
151 |
FROM alias |
dd95ed5bc9d2
pgsql: Added quotalimit's bytes and messages to view vmm_domain_info.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
387
diff
changeset
|
152 |
WHERE alias.gid = domain_data.gid) AS aliases, |
dd95ed5bc9d2
pgsql: Added quotalimit's bytes and messages to view vmm_domain_info.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
387
diff
changeset
|
153 |
(SELECT count(gid) |
dd95ed5bc9d2
pgsql: Added quotalimit's bytes and messages to view vmm_domain_info.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
387
diff
changeset
|
154 |
FROM relocated |
dd95ed5bc9d2
pgsql: Added quotalimit's bytes and messages to view vmm_domain_info.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
387
diff
changeset
|
155 |
WHERE relocated.gid = domain_data.gid) AS relocated, |
dd95ed5bc9d2
pgsql: Added quotalimit's bytes and messages to view vmm_domain_info.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
387
diff
changeset
|
156 |
(SELECT count(gid) |
dd95ed5bc9d2
pgsql: Added quotalimit's bytes and messages to view vmm_domain_info.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
387
diff
changeset
|
157 |
FROM domain_name |
dd95ed5bc9d2
pgsql: Added quotalimit's bytes and messages to view vmm_domain_info.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
387
diff
changeset
|
158 |
WHERE domain_name.gid = domain_data.gid |
391
8217ddd5220d
pgsql: Updated view vmm_domain_info. No longer select data we have already.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
388
diff
changeset
|
159 |
AND NOT domain_name.is_primary) AS aliasdomains |
388
dd95ed5bc9d2
pgsql: Added quotalimit's bytes and messages to view vmm_domain_info.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
387
diff
changeset
|
160 |
FROM domain_data |
dd95ed5bc9d2
pgsql: Added quotalimit's bytes and messages to view vmm_domain_info.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
387
diff
changeset
|
161 |
LEFT JOIN domain_name USING (gid) |
dd95ed5bc9d2
pgsql: Added quotalimit's bytes and messages to view vmm_domain_info.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
387
diff
changeset
|
162 |
LEFT JOIN users USING (gid) |
dd95ed5bc9d2
pgsql: Added quotalimit's bytes and messages to view vmm_domain_info.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
387
diff
changeset
|
163 |
WHERE domain_name.is_primary |
391
8217ddd5220d
pgsql: Updated view vmm_domain_info. No longer select data we have already.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
388
diff
changeset
|
164 |
GROUP BY gid; |