Source

iredmail / iRedMail / samples / iredmail.pgsql

Diff from to

iRedMail/samples/iredmail.pgsql

     username VARCHAR(255) NOT NULL,
     bytes INT8 NOT NULL DEFAULT 0,
     messages INT8 NOT NULL DEFAULT 0,
+    domain VARCHAR(255) NOT NULL DEFAULT '',
     PRIMARY KEY (username)
 );
+CREATE INDEX idx_used_quota_domain ON used_quota (domain);
 
 -- Trigger required by quota dict
 CREATE OR REPLACE FUNCTION merge_quota() RETURNS TRIGGER AS $$
 
     LOOP
         UPDATE used_quota
-        SET bytes = bytes + NEW.bytes, messages = messages + NEW.messages
+        SET bytes = bytes + NEW.bytes, messages = messages + NEW.messages, domain=split_part(NEW.username, '@', 2)
         WHERE username = NEW.username;
         IF found THEN
             RETURN NULL;
 
         BEGIN
             IF NEW.messages = 0 THEN
-                INSERT INTO used_quota (bytes, messages, username)
-                VALUES (NEW.bytes, NULL, NEW.username);
+                INSERT INTO used_quota (bytes, messages, username, domain)
+                VALUES (NEW.bytes, NULL, NEW.username, split_part(NEW.username, '@', 2));
             ELSE
-                INSERT INTO used_quota (bytes, messages, username)
-                VALUES (NEW.bytes, -NEW.messages, NEW.username);
+                INSERT INTO used_quota (bytes, messages, username, domain)
+                VALUES (NEW.bytes, -NEW.messages, NEW.username, split_part(NEW.username, '@', 2));
             END IF;
             return NULL;
             EXCEPTION WHEN unique_violation THEN
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.