Skip to content

Commit

Permalink
Added trigger in sql script to write an event in events table for wor…
Browse files Browse the repository at this point in the history
…kflow creation

Signed-off-by: parauliya <aman@infracloud.io>
  • Loading branch information
parauliya committed Sep 22, 2020
1 parent 08b5a24 commit 7e3bd2e
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
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 events_notify_changes()
FOR EACH ROW EXECUTE PROCEDURE events_notify_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, data) VALUES (new.workflow_id, 2, 0, new.action_list);
RETURN NEW;
END IF;
END;
$trigger1$ LANGUAGE plpgsql;

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

0 comments on commit 7e3bd2e

Please sign in to comment.