author | Pascal Volk <neverseen@users.sourceforge.net> |
Fri, 04 Nov 2011 03:25:29 +0000 | |
branch | v0.6.x |
changeset 448 | 45c917e6a386 |
parent 437 | 9823548b2717 |
child 500 | 5ccc9c6e5193 |
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 |
-- --- |
437
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
39 |
-- Make room for different mailbox formats and longer password hashes. |
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; |
297
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
43 |
DROP VIEW postfix_maildir; |
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
|
44 |
DROP VIEW vmm_domain_info; |
297
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
45 |
|
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
46 |
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
|
47 |
CREATE SEQUENCE quotalimit_id; |
297
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
48 |
|
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
49 |
CREATE TABLE mailboxformat ( |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
50 |
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
|
51 |
format varchar(20) NOT NULL, |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
52 |
CONSTRAINT pkey_mailboxformat PRIMARY KEY (fid), |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
53 |
CONSTRAINT ukey_mailboxformat UNIQUE (format) |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
54 |
); |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
55 |
-- Insert supported mailbox formats |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
56 |
INSERT INTO mailboxformat(format) VALUES ('maildir'); |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
57 |
INSERT INTO mailboxformat(format) VALUES ('mdbox'); |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
58 |
INSERT INTO mailboxformat(format) VALUES ('sdbox'); |
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 |
-- Adjust maillocation table |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
61 |
ALTER TABLE maillocation DROP CONSTRAINT ukey_maillocation; |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
62 |
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
|
63 |
ALTER TABLE maillocation |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
64 |
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
|
65 |
ADD COLUMN extra varchar(1024); |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
66 |
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
|
67 |
FOREIGN KEY (fid) REFERENCES mailboxformat (fid); |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
68 |
|
437
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
69 |
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
|
70 |
|
382
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
71 |
-- --- |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
72 |
-- Add quota stuff |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
73 |
-- --- |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
74 |
CREATE TABLE quotalimit ( |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
75 |
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
|
76 |
bytes bigint NOT NULL, |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
77 |
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
|
78 |
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
|
79 |
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
|
80 |
); |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
81 |
-- 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
|
82 |
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
|
83 |
|
437
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
84 |
-- Adjust tables (quota) |
382
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
85 |
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
|
86 |
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
|
87 |
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
|
88 |
|
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
89 |
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
|
90 |
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
|
91 |
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
|
92 |
|
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
93 |
CREATE TABLE userquota_11 ( |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
94 |
uid bigint NOT NULL, |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
95 |
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
|
96 |
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
|
97 |
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
|
98 |
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
|
99 |
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
|
100 |
); |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
101 |
|
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
102 |
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
|
103 |
BEGIN |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
104 |
UPDATE userquota_11 |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
105 |
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
|
106 |
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
|
107 |
IF found THEN |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
108 |
RETURN NULL; |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
109 |
ELSE |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
110 |
RETURN NEW; |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
111 |
END IF; |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
112 |
END; |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
113 |
$$ LANGUAGE plpgsql; |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
114 |
|
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
115 |
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
|
116 |
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
|
117 |
|
437
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
118 |
-- Adjust tables (services) |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
119 |
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
|
120 |
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
|
121 |
FOREIGN KEY (ssid) REFERENCES service_set (ssid); |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
122 |
|
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
123 |
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
|
124 |
-- save current service sets |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
125 |
UPDATE users u |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
126 |
SET ssid = ss.ssid |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
127 |
FROM service_set ss |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
128 |
WHERE ss.smtp = u.smtp |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
129 |
AND ss.pop3 = u.pop3 |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
130 |
AND ss.imap = u.imap |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
131 |
AND ss.managesieve = u.managesieve; |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
132 |
|
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
133 |
ALTER TABLE users DROP COLUMN smtp; |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
134 |
ALTER TABLE users DROP COLUMN pop3; |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
135 |
ALTER TABLE users DROP COLUMN imap; |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
136 |
ALTER TABLE users DROP COLUMN managesieve; |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
137 |
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
|
138 |
FOREIGN KEY (ssid) REFERENCES service_set (ssid); |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
139 |
|
382
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
140 |
-- --- |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
141 |
-- Restore views |
5e6bcb2e010e
pgsql/*: Added tables, triggers and functions for quota support.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
297
diff
changeset
|
142 |
-- --- |
297
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
143 |
CREATE VIEW dovecot_user AS |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
144 |
SELECT local_part || '@' || domain_name.domainname AS userid, |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
145 |
uid, gid, domain_data.domaindir || '/' || uid AS home, |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
146 |
mailboxformat.format || ':~/' || maillocation.directory AS mail |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
147 |
FROM users |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
148 |
LEFT JOIN domain_data USING (gid) |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
149 |
LEFT JOIN domain_name USING (gid) |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
150 |
LEFT JOIN maillocation USING (mid) |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
151 |
LEFT JOIN mailboxformat USING (fid); |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
152 |
|
437
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
153 |
CREATE OR REPLACE VIEW dovecot_password AS |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
154 |
SELECT local_part || '@' || domainname AS "user", |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
155 |
passwd AS "password", smtp, pop3, imap, managesieve |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
156 |
FROM users |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
157 |
LEFT JOIN domain_name USING (gid) |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
158 |
LEFT JOIN service_set USING (ssid); |
9823548b2717
pgsql: Added new table `service_set'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
391
diff
changeset
|
159 |
|
297
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
160 |
CREATE VIEW postfix_maildir AS |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
161 |
SELECT local_part || '@' || domain_name.domainname AS address, |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
162 |
domain_data.domaindir||'/'||uid||'/'||maillocation.directory||'/' |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
163 |
AS maildir |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
164 |
FROM users |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
165 |
LEFT JOIN domain_data USING (gid) |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
166 |
LEFT JOIN domain_name USING (gid) |
e21ceaabe871
pgsql: Added support for different mailbox formats.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
167 |
LEFT JOIN maillocation USING (mid); |
388
dd95ed5bc9d2
pgsql: Added quotalimit's bytes and messages to view vmm_domain_info.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
387
diff
changeset
|
168 |
|
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
|
169 |
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
|
170 |
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
|
171 |
(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
|
172 |
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
|
173 |
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
|
174 |
(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
|
175 |
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
|
176 |
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
|
177 |
(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
|
178 |
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
|
179 |
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
|
180 |
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
|
181 |
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
|
182 |
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
|
183 |
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
|
184 |
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
|
185 |
GROUP BY gid; |