Telefonnotizen: in Berichten Angebot/Auftrag filtern können.
[kivitendo-erp.git] / sql / Pg-upgrade2 / follow_ups.sql
1 -- @tag: follow_ups
2 -- @description: Tabellenstruktur für Wiedervorlagen und allgemeine Notizen
3 -- @depends: release_2_4_3
4 CREATE SEQUENCE note_id;
5 CREATE TABLE notes (
6        id integer NOT NULL DEFAULT nextval('note_id'),
7        subject text,
8        body text,
9        created_by integer NOT NULL,
10
11        trans_id integer,
12        trans_module varchar(10),
13
14        itime timestamp DEFAULT now(),
15        mtime timestamp,
16
17        PRIMARY KEY (id),
18        FOREIGN KEY (created_by) REFERENCES employee (id)
19 );
20
21 CREATE TRIGGER mtime_notes
22     BEFORE UPDATE ON notes
23     FOR EACH ROW
24     EXECUTE PROCEDURE set_mtime();
25
26 CREATE SEQUENCE follow_up_id;
27 CREATE TABLE follow_ups (
28        id integer NOT NULL DEFAULT nextval('follow_up_id'),
29        follow_up_date date NOT NULL,
30        created_for_user integer NOT NULL,
31        done boolean DEFAULT FALSE,
32        note_id integer NOT NULL,
33        created_by integer NOT NULL,
34
35        itime timestamp DEFAULT now(),
36        mtime timestamp,
37
38        PRIMARY KEY (id),
39        FOREIGN KEY (created_for_user) REFERENCES employee (id),
40        FOREIGN KEY (created_by) REFERENCES employee (id),
41        FOREIGN KEY (note_id) REFERENCES notes (id)
42 );
43
44 CREATE TRIGGER mtime_follow_ups
45     BEFORE UPDATE ON follow_ups
46     FOR EACH ROW
47     EXECUTE PROCEDURE set_mtime();
48
49 CREATE SEQUENCE follow_up_link_id;
50 CREATE TABLE follow_up_links (
51        id integer NOT NULL DEFAULT nextval('follow_up_link_id'),
52        follow_up_id integer NOT NULL,
53        trans_id integer NOT NULL,
54        trans_type text NOT NULL,
55        trans_info text,
56
57        itime timestamp DEFAULT now(),
58        mtime timestamp,
59
60        PRIMARY KEY (id),
61        FOREIGN KEY (follow_up_id) REFERENCES follow_ups (id)
62 );
63
64 CREATE TRIGGER mtime_follow_up_links
65     BEFORE UPDATE ON follow_up_links
66     FOR EACH ROW
67     EXECUTE PROCEDURE set_mtime();
68
69 CREATE TABLE follow_up_access (
70        who integer NOT NULL,
71        what integer NOT NULL,
72
73        FOREIGN KEY (who) REFERENCES employee (id),
74        FOREIGN KEY (what) REFERENCES employee (id)
75 );