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)
);
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,
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;
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);
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;
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;
PRIMARY KEY (id)
);
+
+
COMMIT;