Skip to content

Commit

Permalink
Merge pull request #654 from nyaruka/channel_log_uuid
Browse files Browse the repository at this point in the history
Add channel log UUID field
  • Loading branch information
rowanseymour authored Sep 5, 2022
2 parents 7fd2c5c + aff6484 commit 4ef3f8f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions core/models/channel_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import (

"github.com/nyaruka/gocommon/httpx"
"github.com/nyaruka/gocommon/jsonx"
"github.com/nyaruka/gocommon/uuids"
"github.com/pkg/errors"
)

// ChannelLogID is our type for a channel log id
type ChannelLogID int64

// ChannelLogUUID is our type for a channel log UUID
type ChannelLogUUID uuids.UUID

type ChanneLogType string

const (
Expand All @@ -25,9 +29,10 @@ const (

// ChannelLog is the mailroom struct that represents channel logs
type ChannelLog struct {
ID ChannelLogID `db:"id"`
ChannelID ChannelID `db:"channel_id"`
ConnectionID ConnectionID `db:"connection_id"`
ID ChannelLogID `db:"id"`
UUID ChannelLogUUID `db:"uuid"`
ChannelID ChannelID `db:"channel_id"`
ConnectionID ConnectionID `db:"connection_id"`

Type ChanneLogType `db:"log_type"`
HTTPLogs json.RawMessage `db:"http_logs"`
Expand All @@ -37,8 +42,8 @@ type ChannelLog struct {
}

const sqlInsertChannelLog = `
INSERT INTO channels_channellog( channel_id, connection_id, log_type, http_logs, is_error, elapsed_ms, created_on)
VALUES(:channel_id, :connection_id, :log_type, :http_logs, :is_error, :elapsed_ms, :created_on)
INSERT INTO channels_channellog( uuid, channel_id, connection_id, log_type, http_logs, is_error, elapsed_ms, created_on)
VALUES(:uuid, :channel_id, :connection_id, :log_type, :http_logs, :is_error, :elapsed_ms, :created_on)
RETURNING id`

// NewChannelLog creates a new channel log from the given HTTP trace
Expand All @@ -51,6 +56,7 @@ func NewChannelLog(channelID ChannelID, conn *ChannelConnection, logType ChanneL
}

l := &ChannelLog{
UUID: ChannelLogUUID(uuids.New()),
ChannelID: channelID,
Type: logType,
HTTPLogs: jsonx.MustMarshal([]*httpx.Log{httpLog}),
Expand Down
Binary file modified mailroom_test.dump
Binary file not shown.

0 comments on commit 4ef3f8f

Please sign in to comment.