CREATE OR REPLACE FUNCTION edit_task RETURNS trigger AS BODY BEGIN INS

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
CREATE OR REPLACE FUNCTION edit_task()
RETURNS trigger AS
$BODY$
BEGIN
INSERT INTO "task_status"(start, task_id, status_id)
VALUES(current_timestamp, new.id, new.status_id);
RETURN NEW;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
ALTER FUNCTION edit_task() OWNER TO postgres;
CREATE OR REPLACE FUNCTION create_new_task()
RETURNS trigger AS
$BODY$
BEGIN
INSERT INTO "task_status"(start, task_id, status_id)
VALUES(current_timestamp, new.id, 1);
RETURN NEW;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
ALTER FUNCTION create_new_task() OWNER TO postgres;
CREATE TABLE task
(
id serial NOT NULL,
date_accpeted date NOT NULL,
est_date date NOT NULL,
worker_id integer NOT NULL,
client_id integer NOT NULL,
article_id integer NOT NULL,
status_id integer NOT NULL DEFAULT 1,
inviz_date timestamp without time zone,
"comment" text,
CONSTRAINT task_pkey PRIMARY KEY (id),
CONSTRAINT task_article_id_fkey FOREIGN KEY (article_id)
REFERENCES article (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT task_client_id_fkey FOREIGN KEY (client_id)
REFERENCES client (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT task_status_id_fkey FOREIGN KEY (status_id)
REFERENCES t_status (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT task_worker_id_fkey FOREIGN KEY (worker_id)
REFERENCES worker (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (OIDS=FALSE);
ALTER TABLE task OWNER TO postgres;
-- Trigger: new_task_insert on task
-- DROP TRIGGER new_task_insert ON task;
CREATE TRIGGER new_task_insert
AFTER INSERT
ON task
FOR EACH ROW
EXECUTE PROCEDURE create_new_task();
-- Trigger: task_edit on task
-- DROP TRIGGER task_edit ON task;
CREATE TRIGGER task_edit
AFTER UPDATE
ON task
FOR EACH ROW
EXECUTE PROCEDURE edit_task();