2 -- @description: Journal für verschickte E-Mails
3 -- @depends: release_3_3_0
5 -- Note: sender_id may be NULL to indicate a mail sent by the system
6 -- without a user being logged in – e.g. by the task server.
7 CREATE TABLE email_journal (
11 recipients TEXT NOT NULL,
12 sent_on TIMESTAMP NOT NULL DEFAULT now(),
13 subject TEXT NOT NULL,
15 headers TEXT NOT NULL,
17 extended_status TEXT NOT NULL,
18 itime TIMESTAMP NOT NULL DEFAULT now(),
19 mtime TIMESTAMP NOT NULL DEFAULT now(),
22 FOREIGN KEY (sender_id) REFERENCES employee (id),
23 CONSTRAINT valid_status CHECK (status IN ('ok', 'failed'))
26 CREATE TABLE email_journal_attachments (
28 position INTEGER NOT NULL,
29 email_journal_id INTEGER NOT NULL,
31 mime_type TEXT NOT NULL,
32 content BYTEA NOT NULL,
33 itime TIMESTAMP NOT NULL DEFAULT now(),
34 mtime TIMESTAMP NOT NULL DEFAULT now(),
37 FOREIGN KEY (email_journal_id) REFERENCES email_journal (id) ON DELETE CASCADE
40 CREATE TRIGGER mtime_email_journal BEFORE UPDATE ON email_journal FOR EACH ROW EXECUTE PROCEDURE set_mtime();
41 CREATE TRIGGER mtime_email_journal_attachments BEFORE UPDATE ON email_journal_attachments FOR EACH ROW EXECUTE PROCEDURE set_mtime();