Skip to content

Commit

Permalink
Merge pull request #62 from nyaruka/msgs_no_reason
Browse files Browse the repository at this point in the history
Don't set `delete_reason` for messages
  • Loading branch information
rowanseymour authored Feb 22, 2022
2 parents 4ce0680 + dc97a4d commit cb16a27
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
14 changes: 1 addition & 13 deletions archives/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,6 @@ WHERE mm.org_id = $1 AND mm.created_on >= $2 AND mm.created_on < $3
ORDER BY mm.created_on ASC, mm.id ASC
`

const setMessageDeleteReason = `
UPDATE msgs_msg
SET delete_reason = 'A'
WHERE id IN(?)
`

const deleteMessageLogs = `
DELETE FROM channels_channellog
WHERE msg_id IN(?)
Expand Down Expand Up @@ -206,13 +200,7 @@ func DeleteArchivedMessages(ctx context.Context, config *Config, db *sqlx.DB, s3
return err
}

// first update our delete_reason
err = executeInQuery(ctx, tx, setMessageDeleteReason, idBatch)
if err != nil {
return errors.Wrap(err, "error updating delete reason")
}

// now delete any channel logs
// first delete any channel logs
err = executeInQuery(ctx, tx, deleteMessageLogs, idBatch)
if err != nil {
return errors.Wrap(err, "error removing channel logs")
Expand Down
16 changes: 5 additions & 11 deletions testdb.sql
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ CREATE TABLE msgs_msg (
org_id integer NOT NULL references orgs_org(id) on delete cascade,
flow_id integer NULL references flows_flow(id) on delete cascade,
metadata text,
topup_id integer,
delete_reason char(1) NULL
topup_id integer
);

DROP TABLE IF EXISTS msgs_broadcast_recipients;
Expand Down Expand Up @@ -171,8 +170,6 @@ CREATE TABLE flows_flowrun (
org_id integer NOT NULL references orgs_org(id),
results text NOT NULL,
path text NOT NULL,
events jsonb NOT NULL,
parent_id integer NULL references flows_flowrun(id),
created_on timestamp with time zone NOT NULL,
modified_on timestamp with time zone NOT NULL,
exited_on timestamp with time zone NULL,
Expand Down Expand Up @@ -299,25 +296,22 @@ INSERT INTO channels_channellog(id, msg_id) VALUES
INSERT INTO auth_user(id, username) VALUES
(1, 'greg@gmail.com');

INSERT INTO flows_flowrun(id, uuid, responded, contact_id, flow_id, org_id, results, path, events, created_on, modified_on, exited_on, status, submitted_by_id) VALUES
(1, '4ced1260-9cfe-4b7f-81dd-b637108f15b9', TRUE, 6, 1, 2, '{}', '[]', '[]', '2017-08-12 21:11:59.890662+02:00','2017-08-12 21:11:59.890662+02:00','2017-08-12 21:11:59.890662+02:00', 'C', NULL),
INSERT INTO flows_flowrun(id, uuid, responded, contact_id, flow_id, org_id, results, path, created_on, modified_on, exited_on, status, submitted_by_id) VALUES
(1, '4ced1260-9cfe-4b7f-81dd-b637108f15b9', TRUE, 6, 1, 2, '{}', '[]', '2017-08-12 21:11:59.890662+02:00','2017-08-12 21:11:59.890662+02:00','2017-08-12 21:11:59.890662+02:00', 'C', NULL),
(2, '7d68469c-0494-498a-bdf3-bac68321fd6d', TRUE, 6, 1, 2,
'{"agree": {"category": "Strongly agree", "node_uuid": "a0434c54-3e26-4eb0-bafc-46cdeaf435ac", "name": "Do you agree?", "value": "A", "created_on": "2017-05-03T12:25:21.714339+00:00", "input": "A"}}',
'[{"uuid": "c3d0b417-db75-417c-8050-33776ec8f620", "node_uuid": "10896d63-8df7-4022-88dd-a9d93edf355b", "arrived_on": "2017-08-12T15:07:24.049815+02:00", "exit_uuid": "2f890507-2ad2-4bd1-92fc-0ca031155fca"}]',
'[{"msg": {"urn": "tel:+12076661212", "text": "hola", "uuid": "cf05c58f-31fb-4ce8-9e65-4ecc9fd47cbe", "channel": {"name": "1223", "uuid": "bbfe2e9c-cf69-4d0a-b42e-00ac3dc0b0b8"}}, "type": "msg_created", "step_uuid": "659cdae5-1f29-4a58-9437-10421f724268", "created_on": "2018-01-22T15:06:47.357682+00:00"}]',
'2017-08-12 21:11:59.890662+02:00','2017-08-12 21:11:59.890662+02:00','2017-08-12 21:11:59.890662+02:00', 'C', NULL),
(3, 'de782b35-a398-46ed-8550-34c66053841b', TRUE, 7, 2, 3,
'{"agree": {"category": "Strongly agree", "node_uuid": "084c8cf1-715d-4d0a-b38d-a616ed74e638", "name": "Agree", "value": "A", "created_on": "2017-05-03T12:25:21.714339+00:00", "input": "A"}, "confirm_agree": {"category": "Confirmed Strongly agree", "node_uuid": "a0434c54-3e26-4eb0-bafc-46cdeaf435ab", "name": "Do you agree?", "value": "A", "created_on": "2017-05-03T12:25:21.714339+00:00", "input": "A"}}',
'[{"uuid": "600ac5b4-4895-4161-ad97-6e2f1bb48bcb", "node_uuid": "accbc6e2-b0df-46cd-9a76-bff0fdf4d753", "arrived_on": "2017-08-12T15:07:24.049815+02:00", "exit_uuid": "8249e2dc-c893-4200-b6d2-398d07a459bc"}]',
'[{"msg": {"urn": "tel:+12076661212", "text": "hola", "uuid": "9ea50923-0888-4596-9a9d-4890994934a9", "channel": {"name": "1223", "uuid": "d6597e08-8285-428c-8e7e-97c68adfa073"}}, "type": "msg_created", "step_uuid": "ae067248-df92-41c8-bb29-92506e984259", "created_on": "2018-01-22T15:06:47.357682+00:00"}]',
'2017-08-10 21:11:59.890662+02:00','2017-08-10 21:11:59.890662+02:00','2017-08-10 21:11:59.890662+02:00', 'C', 1),
(4, '329a5d24-64fc-479c-8d24-9674c9b46530', TRUE, 7, 2, 3,
'{"agree": {"category": "Disagree", "node_uuid": "084c8cf1-715d-4d0a-b38d-a616ed74e638", "name": "Agree", "value": "B", "created_on": "2017-10-10T12:25:21.714339+00:00", "input": "B"}}',
'[{"uuid": "babf4fc8-e12c-4bb9-a9dd-61178a118b5a", "node_uuid": "accbc6e2-b0df-46cd-9a76-bff0fdf4d753", "arrived_on": "2017-10-12T15:07:24.049815+02:00", "exit_uuid": "8249e2dc-c893-4200-b6d2-398d07a459bc"}]',
'[{"msg": {"urn": "tel:+12076661212", "text": "hi hi", "uuid": "543d2c4b-ff0b-4b87-a9a4-b2d6745cf470", "channel": {"name": "1223", "uuid": "d6597e08-8285-428c-8e7e-97c68adfa073"}}, "type": "msg_created", "step_uuid": "3a5014dd-7b14-4b7a-be52-0419c09340a6", "created_on": "2018-10-12T15:06:47.357682+00:00"}]',
'2017-10-10 21:11:59.890662+02:00','2017-10-10 21:11:59.890662+02:00','2017-10-10 21:11:59.890662+02:00', 'C', NULL),
(5, 'abed67d2-06b8-4749-8bb9-ecda037b673b', TRUE, 7, 2, 3, '{}', '[]', '[]', '2017-10-10 21:11:59.890663+02:00','2017-10-10 21:11:59.890662+02:00','2017-10-10 21:11:59.890662+02:00', 'C', NULL),
(6, '6262eefe-a6e9-4201-9b76-a7f25e3b7f29', TRUE, 7, 2, 3, '{}', '[]', '[]', '2017-12-12 21:11:59.890662+02:00','2017-12-12 21:11:59.890662+02:00','2017-12-12 21:11:59.890662+02:00', 'C', NULL);
(5, 'abed67d2-06b8-4749-8bb9-ecda037b673b', TRUE, 7, 2, 3, '{}', '[]', '2017-10-10 21:11:59.890663+02:00','2017-10-10 21:11:59.890662+02:00','2017-10-10 21:11:59.890662+02:00', 'C', NULL),
(6, '6262eefe-a6e9-4201-9b76-a7f25e3b7f29', TRUE, 7, 2, 3, '{}', '[]', '2017-12-12 21:11:59.890662+02:00','2017-12-12 21:11:59.890662+02:00','2017-12-12 21:11:59.890662+02:00', 'C', NULL);

-- update run #5 to have a path longer than 500 steps
UPDATE flows_flowrun SET path = s.path FROM (
Expand Down

0 comments on commit cb16a27

Please sign in to comment.