-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure_db.sql
More file actions
47 lines (40 loc) · 887 Bytes
/
configure_db.sql
File metadata and controls
47 lines (40 loc) · 887 Bytes
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
CREATE TABLE IF NOT EXISTS commands (
id SERIAL PRIMARY KEY,
command TEXT NOT NULL
);
DROP TYPE IF EXISTS env_entry CASCADE;
CREATE TYPE env_entry AS (key TEXT, value TEXT);
CREATE TABLE IF NOT EXISTS inputs (
id SERIAL REFERENCES commands (id),
input TEXT,
env env_entry ARRAY
);
CREATE TABLE IF NOT EXISTS outputs (
id SERIAL REFERENCES commands (id),
output TEXT,
errors TEXT
);
CREATE TABLE IF NOT EXISTS statuses (
id SERIAL REFERENCES commands (id),
exit_code INTEGER
);
CREATE OR REPLACE FUNCTION outputs_statuses_trigger_fnc()
RETURNS trigger AS
$$
BEGIN
INSERT INTO outputs (id) VALUES (
NEW.id
);
INSERT INTO statuses (id) VALUES (
NEW.id
);
RETURN NEW;
END;
$$ LANGUAGE "plpgsql";
CREATE
OR
REPLACE
TRIGGER after_command_insert AFTER
INSERT
ON commands FOR EACH ROW
EXECUTE PROCEDURE outputs_statuses_trigger_fnc ();