*** empty log message ***
authorMatthew Mondor <mmondor@pulsar-zone.net>
Wed, 14 Mar 2007 22:29:44 +0000 (22:29 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Wed, 14 Mar 2007 22:29:44 +0000 (22:29 +0000)
mmsoftware/mmmail/scripts/pgsql-tables.sql

index a9537e7..e5b6d28 100644 (file)
@@ -1,27 +1,22 @@
 BEGIN;
 
-CREATE LANGUAGE plpgsql;
 
 
+CREATE LANGUAGE plpgsql;
+
 
----
---- Box file garbage collection queue.  The application uses a thread to
---- clear all associated files with deleted boxes at regular intervals.
---- box deletions cause their associated address to be appended in this table.
----
-CREATE TABLE "box_deleted" (
-       address         varchar(64)     NOT NULL,
-       PRIMARY KEY (address)
-);
 
 ---
---- Mail file garbage collection queue.  The application uses a thread to
---- clear these files at regular intervals.  mail and relayqueue deletions
---- cause their associated file fullpath to be appended in this table.
+--- File garbage collection queue.
+--- Mail and box deletion events cause their path to be dumped here.
+--- The application uses a thread to at intervals clear associated files.
 ---
-CREATE TABLE "mail_deleted" (
-       file            varchar(255)    NOT NULL,
-       PRIMARY KEY (file)
+CREATE TABLE "file_gc_queue" (
+       id              bigserial       NOT NULL,
+       type            char(1)         NOT NULL
+                                       CHECK (type = 'd' OR type = 'f'),
+       path            varchar(255)    NOT NULL UNIQUE,
+       PRIMARY KEY (id)
 );
 
 
@@ -59,9 +54,9 @@ CREATE TABLE "user" (
        id              varchar(32)     NOT NULL,
        name            varchar(64)     NOT NULL,
        passwd          char(34)        NOT NULL,
-       created         timestamp       NOT NULL
+       time_created    timestamp       NOT NULL
                                        DEFAULT CURRENT_TIMESTAMP,
-       activity        timestamp       NOT NULL
+       time_activity   timestamp       NOT NULL
                                        DEFAULT CURRENT_TIMESTAMP,
        logins          bigint          NOT NULL
                                        DEFAULT 0,
@@ -98,13 +93,16 @@ CREATE TABLE "box" (
                                        DEFAULT CURRENT_TIMESTAMP,
        filter          boolean         NOT NULL
                                        DEFAULT 'f',
+       filter_type     boolean         NOT NULL
+                                       DEFAULT 'f',
        description     varchar(64),
+       directory       varchar(255)    NOT NULL UNIQUE,
        PRIMARY KEY (address)
 );
 
 CREATE FUNCTION box_delete() RETURNS trigger AS $box_delete$
 BEGIN
-       INSERT INTO box_deleted VALUES(OLD.address);
+       INSERT INTO file_gc_queue (type,path) VALUES('d', OLD.directory);
        RETURN NULL;
 END;
 $box_delete$ LANGUAGE plpgsql;
@@ -139,10 +137,10 @@ CREATE TABLE "mail" (
        box             varchar(64)     NOT NULL
                                        REFERENCES box (address)
                                                ON DELETE CASCADE,
-       file            varchar(255)    NOT NULL,
        created         timestamp       NOT NULL
                                        DEFAULT CURRENT_TIMESTAMP,
        size            bigint          NOT NULL,
+       file            varchar(255)    NOT NULL UNIQUE,
        PRIMARY KEY (id)
 );
 CREATE INDEX mail_box_index ON mail (box);
@@ -169,7 +167,7 @@ BEGIN
                msgs = msgs - 1,
                time_delete = CURRENT_TIMESTAMP
                WHERE address = OLD.box;
-       INSERT INTO mail_deleted VALUES(OLD.file);
+       INSERT INTO file_gc_queue (type,path) VALUES('f', OLD.file);
        RETURN NULL;
 END;
 $mail_delete$ LANGUAGE plpgsql;
@@ -221,7 +219,7 @@ CREATE INDEX relayqueue_todomain_index ON relayqueue (todomain);
 
 CREATE FUNCTION relayqueue_delete() RETURNS trigger AS $relayqueue_delete$
 BEGIN
-       INSERT INTO mail_deleted VALUES(OLD.file);
+       INSERT INTO file_gc_queue (type,path) VALUES('f', OLD.file);
        RETURN NULL;
 END;
 $relayqueue_delete$ LANGUAGE plpgsql;
@@ -242,4 +240,6 @@ CREATE TABLE "session" (
        PRIMARY KEY (id)
 );
 
+
+
 COMMIT;