Skip to content

Commit 55bd95f

Browse files
committed
Make sure the channel event UUID is generated and read from the the DB
1 parent e551248 commit 55bd95f

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

Diff for: backends/rapidpro/backend_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ WHERE
16411641
`
16421642

16431643
const sqlSelectEvent = `
1644-
SELECT id, org_id, channel_id, contact_id, contact_urn_id, event_type, optin_id, extra, occurred_on, created_on, log_uuids
1644+
SELECT id, uuid, org_id, channel_id, contact_id, contact_urn_id, event_type, optin_id, extra, occurred_on, created_on, log_uuids
16451645
FROM channels_channelevent
16461646
WHERE id = $1`
16471647

Diff for: backends/rapidpro/channel_event.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/lib/pq"
1515
"github.com/nyaruka/courier"
1616
"github.com/nyaruka/gocommon/urns"
17+
"github.com/nyaruka/gocommon/uuids"
1718
"github.com/nyaruka/null/v3"
1819
)
1920

@@ -65,6 +66,7 @@ func newChannelEvent(channel courier.Channel, eventType courier.ChannelEventType
6566
dbChannel := channel.(*Channel)
6667

6768
return &ChannelEvent{
69+
UUID_: courier.ChannelEventUUID(uuids.NewV4()),
6870
ChannelUUID_: dbChannel.UUID_,
6971
OrgID_: dbChannel.OrgID_,
7072
ChannelID_: dbChannel.ID_,
@@ -136,8 +138,8 @@ func writeChannelEvent(ctx context.Context, b *backend, event courier.ChannelEve
136138

137139
const sqlInsertChannelEvent = `
138140
INSERT INTO
139-
channels_channelevent( org_id, channel_id, contact_id, contact_urn_id, event_type, optin_id, extra, occurred_on, created_on, status, log_uuids)
140-
VALUES(:org_id, :channel_id, :contact_id, :contact_urn_id, :event_type, :optin_id, :extra, :occurred_on, NOW(), 'P', :log_uuids)
141+
channels_channelevent( org_id, uuid, channel_id, contact_id, contact_urn_id, event_type, optin_id, extra, occurred_on, created_on, status, log_uuids)
142+
VALUES(:org_id, :uuid, :channel_id, :contact_id, :contact_urn_id, :event_type, :optin_id, :extra, :occurred_on, NOW(), 'P', :log_uuids)
141143
RETURNING id, created_on`
142144

143145
// writeChannelEventToDB writes the passed in channel event to our db

Diff for: backends/rapidpro/schema.sql

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ CREATE TABLE channels_channellog (
129129
DROP TABLE IF EXISTS channels_channelevent CASCADE;
130130
CREATE TABLE channels_channelevent (
131131
id serial primary key,
132+
uuid uuid NOT NULL,
132133
event_type character varying(16) NOT NULL,
133134
status character varying(1) NOT NULL,
134135
extra text,

0 commit comments

Comments
 (0)