diff --git a/core/models/runs.go b/core/models/runs.go index 12f81e5cf..fc5ceb3f8 100644 --- a/core/models/runs.go +++ b/core/models/runs.go @@ -48,7 +48,6 @@ type FlowRun struct { ExitedOn *time.Time `db:"exited_on"` Responded bool `db:"responded"` Results string `db:"results"` - Path string `db:"path"` PathNodes pq.StringArray `db:"path_nodes"` PathTimes pq.GenericArray `db:"path_times"` CurrentNodeUUID null.String `db:"current_node_uuid"` @@ -102,7 +101,6 @@ func newRun(ctx context.Context, tx *sqlx.Tx, oa *OrgAssets, session *Session, f OrgID: oa.OrgID(), SessionID: session.ID(), StartID: NilStartID, - Path: string(jsonx.MustMarshal(path)), PathNodes: pathNodes, PathTimes: pq.GenericArray{A: pathTimes}, Results: string(jsonx.MustMarshal(fr.Results())), @@ -127,9 +125,9 @@ func newRun(ctx context.Context, tx *sqlx.Tx, oa *OrgAssets, session *Session, f const sqlInsertRun = ` INSERT INTO -flows_flowrun(uuid, created_on, modified_on, exited_on, status, responded, results, path, path_nodes, path_times, +flows_flowrun(uuid, created_on, modified_on, exited_on, status, responded, results, path_nodes, path_times, current_node_uuid, contact_id, flow_id, org_id, session_id, start_id) - VALUES(:uuid, :created_on, NOW(), :exited_on, :status, :responded, :results, :path, :path_nodes, :path_times, + VALUES(:uuid, :created_on, NOW(), :exited_on, :status, :responded, :results, :path_nodes, :path_times, :current_node_uuid, :contact_id, :flow_id, :org_id, :session_id, :start_id) RETURNING id ` @@ -149,15 +147,14 @@ SET exited_on = r.exited_on::timestamptz, responded = r.responded::bool, results = r.results, - path = r.path::jsonb, path_nodes = r.path_nodes::uuid[], path_times = r.path_times::timestamptz[], current_node_uuid = r.current_node_uuid::uuid, modified_on = NOW() FROM ( - VALUES(:uuid, :status, :exited_on, :responded, :results, :path, :path_nodes, :path_times, :current_node_uuid) + VALUES(:uuid, :status, :exited_on, :responded, :results, :path_nodes, :path_times, :current_node_uuid) ) AS - r(uuid, status, exited_on, responded, results, path, path_nodes, path_times, current_node_uuid) + r(uuid, status, exited_on, responded, results, path_nodes, path_times, current_node_uuid) WHERE fr.uuid = r.uuid::uuid` diff --git a/core/models/runs_test.go b/core/models/runs_test.go index 4ec778d3a..e703c15e6 100644 --- a/core/models/runs_test.go +++ b/core/models/runs_test.go @@ -31,7 +31,6 @@ func TestInsertAndUpdateRuns(t *testing.T) { ModifiedOn: t2, Responded: true, Results: `{}`, - Path: `[]`, PathNodes: []string{"1895cae0-d3c0-4470-83df-0b4cf9449438", "3ea3c026-e1c0-4950-bb94-d4c532b1459f"}, PathTimes: pq.GenericArray{A: []interface{}{t1, t2}}, CurrentNodeUUID: "5f0d8d24-0178-4b10-ae35-b3ccdc785777", diff --git a/core/runner/runner_test.go b/core/runner/runner_test.go index 850a654d4..650c9272b 100644 --- a/core/runner/runner_test.go +++ b/core/runner/runner_test.go @@ -48,7 +48,7 @@ func TestStartFlowBatch(t *testing.T) { Returns(2) assertdb.Query(t, rt.DB, `SELECT count(*) FROM flows_flowrun WHERE contact_id = ANY($1) and flow_id = $2 AND responded = FALSE AND org_id = 1 AND status = 'C' - AND results IS NOT NULL AND path IS NOT NULL AND session_id IS NOT NULL`, pq.Array([]models.ContactID{testdata.Cathy.ID, testdata.Bob.ID}), testdata.SingleMessage.ID). + AND results IS NOT NULL AND path_nodes IS NOT NULL AND session_id IS NOT NULL`, pq.Array([]models.ContactID{testdata.Cathy.ID, testdata.Bob.ID}), testdata.SingleMessage.ID). Returns(2) assertdb.Query(t, rt.DB, `SELECT count(*) FROM msgs_msg WHERE contact_id = ANY($1) AND text = 'Hey, how are you?' AND org_id = 1 AND status = 'Q' @@ -133,7 +133,7 @@ func TestResume(t *testing.T) { runQuery := `SELECT count(*) FROM flows_flowrun WHERE contact_id = $1 AND flow_id = $2 AND status = $3 AND responded = TRUE AND org_id = 1 AND current_node_uuid IS NOT NULL - AND json_array_length(path::json) = $4 AND session_id IS NOT NULL` + AND array_length(path_nodes, 1) = $4 AND session_id IS NOT NULL` assertdb.Query(t, rt.DB, runQuery, modelContact.ID(), flow.ID(), tc.RunStatus, tc.PathLength). Returns(1, "%d: didn't find expected run", i) diff --git a/core/tasks/starts/start_flow_batch_test.go b/core/tasks/starts/start_flow_batch_test.go index eb6fb5236..843881489 100644 --- a/core/tasks/starts/start_flow_batch_test.go +++ b/core/tasks/starts/start_flow_batch_test.go @@ -43,7 +43,7 @@ func TestStartFlowBatchTask(t *testing.T) { Returns(2) assertdb.Query(t, rt.DB, `SELECT count(*) FROM flows_flowrun WHERE contact_id = ANY($1) and flow_id = $2 AND responded = FALSE AND org_id = 1 AND status = 'C' - AND results IS NOT NULL AND path IS NOT NULL AND session_id IS NOT NULL`, pq.Array([]models.ContactID{testdata.Cathy.ID, testdata.Bob.ID}), testdata.SingleMessage.ID). + AND results IS NOT NULL AND path_nodes IS NOT NULL AND session_id IS NOT NULL`, pq.Array([]models.ContactID{testdata.Cathy.ID, testdata.Bob.ID}), testdata.SingleMessage.ID). Returns(2) assertdb.Query(t, rt.DB, `SELECT count(*) FROM msgs_msg WHERE contact_id = ANY($1) AND text = 'Hey, how are you?' AND org_id = 1 AND status = 'Q'