Skip to content

Commit

Permalink
Added trigger for writing event in events table
Browse files Browse the repository at this point in the history
Signed-off-by: parauliya <aman@infracloud.io>
  • Loading branch information
parauliya committed Sep 21, 2020
1 parent 539e7ae commit be4a874
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions deploy/db/tinkerbell-init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ CREATE TABLE IF NOT EXISTS workflow_data (
, data JSONB
);

CREATE EXTENSION "uuid-ossp";

CREATE TABLE IF NOT EXISTS events (
id UUID UNIQUE NOT NULL primary key
id UUID UNIQUE DEFAULT uuid_generate_v4()
, resource_id UUID NOT NULL
, resource_type int NOT NULL
, event_type int NOT NULL
Expand All @@ -99,4 +101,18 @@ $$ LANGUAGE plpgsql;

CREATE TRIGGER events_channel
AFTER INSERT ON events
FOR EACH ROW EXECUTE PROCEDURE notify_event_changes()
FOR EACH ROW EXECUTE PROCEDURE notify_event_changes();

CREATE OR REPLACE FUNCTION insert_event()
RETURNS trigger AS $trigger1$
BEGIN
IF (TG_OP = 'INSERT') THEN
INSERT INTO events(resource_id, resource_type, event_type, created_at, data) VALUES (new.workflow_id, 2, 0, CURRENT_TIMESTAMP, new.action_list);
RETURN NEW;
END IF;
END;
$trigger1$ LANGUAGE plpgsql;

CREATE TRIGGER workflow_changed
AFTER INSERT ON workflow_state
FOR EACH ROW EXECUTE PROCEDURE insert_event()

0 comments on commit be4a874

Please sign in to comment.