From 90be3f811cf7b08e8dffb4f2463e6389f6edac20 Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Tue, 7 Jan 2025 17:23:14 +0545 Subject: [PATCH] feat: playbook run parent --- models/playbooks.go | 10 ++++++++++ schema/playbooks.hcl | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/models/playbooks.go b/models/playbooks.go index 2077f7c9..56159158 100644 --- a/models/playbooks.go +++ b/models/playbooks.go @@ -60,6 +60,12 @@ func (p Playbook) PK() string { return p.ID.String() } +var PlaybookRunStatusFinalStates = []PlaybookRunStatus{ + PlaybookRunStatusCancelled, + PlaybookRunStatusCompleted, + PlaybookRunStatusFailed, +} + var PlaybookRunStatusExecutingGroup = []PlaybookRunStatus{ PlaybookRunStatusRunning, PlaybookRunStatusScheduled, @@ -186,6 +192,10 @@ type PlaybookRun struct { Request types.JSONMap `json:"request,omitempty" gorm:"default:null"` AgentID *uuid.UUID `json:"agent_id,omitempty"` + // Parent Run's id + ParentID *uuid.UUID `json:"parent_id,omitempty"` + + // Parent notification send's id NotificationSendID *uuid.UUID `json:"notification_send_id,omitempty"` } diff --git a/schema/playbooks.hcl b/schema/playbooks.hcl index b1e81a84..93e09801 100644 --- a/schema/playbooks.hcl +++ b/schema/playbooks.hcl @@ -203,6 +203,11 @@ table "playbook_runs" { default = var.uuid_nil type = uuid } + column "parent_id" { + null = true + type = uuid + comment = "references the run that triggered this run" + } column "error" { null = true type = text @@ -210,6 +215,12 @@ table "playbook_runs" { primary_key { columns = [column.id] } + foreign_key "playbook_run_parent_id_fkey" { + columns = [column.parent_id] + ref_columns = [table.playbook_runs.column.id] + on_update = NO_ACTION + on_delete = NO_ACTION + } foreign_key "playbook_run_playbook_id_fkey" { columns = [column.playbook_id] ref_columns = [table.playbooks.column.id] @@ -252,6 +263,9 @@ table "playbook_runs" { on_update = NO_ACTION on_delete = NO_ACTION } + index "idx_playbook_runs_parent_id" { + columns = [column.parent_id] + } } table "playbook_action_agent_data" {