Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,15 @@ jobs:
- name: Test with coverage
run: go test -count=1 ./... -coverprofile=coverage.out

- name: Exclude generated code from coverage
run: grep -v '^github.com/openclaw/discrawl/internal/store/storedb/' coverage.out > coverage.filtered.out

- name: Test with race detector
run: go test -count=1 -race ./...

- name: Enforce coverage floor
run: |
total="$(go tool cover -func=coverage.out | awk '/^total:/ { sub(/%$/, "", $3); print $3 }')"
total="$(go tool cover -func=coverage.filtered.out | awk '/^total:/ { sub(/%$/, "", $3); print $3 }')"
awk -v total="$total" 'BEGIN {
if (total == "") {
print "missing coverage total"
Expand Down
41 changes: 19 additions & 22 deletions internal/store/attachments.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"strings"
"time"

"github.com/openclaw/discrawl/internal/store/storedb"
)

type AttachmentListOptions struct {
Expand Down Expand Up @@ -241,29 +243,24 @@ func (s *Store) ExpandAttachmentChannelIDs(ctx context.Context, channelIDs []str
}

func (s *Store) UpdateAttachmentMedia(ctx context.Context, update AttachmentMediaUpdate) error {
_, err := s.db.ExecContext(ctx, `
update message_attachments
set media_path = ?,
content_sha256 = ?,
content_size = ?,
fetched_at = ?,
fetch_status = ?,
fetch_error = ?,
updated_at = ?
where attachment_id = ?
`, nullable(update.MediaPath), nullable(update.ContentSHA256), update.ContentSize, nullable(update.FetchedAt),
update.FetchStatus, update.FetchError, time.Now().UTC().Format(timeLayout), update.AttachmentID)
return err
return s.q.UpdateAttachmentMedia(ctx, storedb.UpdateAttachmentMediaParams{
MediaPath: nullString(update.MediaPath),
ContentSha256: nullString(update.ContentSHA256),
ContentSize: update.ContentSize,
FetchedAt: nullString(update.FetchedAt),
FetchStatus: update.FetchStatus,
FetchError: update.FetchError,
UpdatedAt: time.Now().UTC().Format(timeLayout),
AttachmentID: update.AttachmentID,
})
}

func (s *Store) UpdateAttachmentFetchStatus(ctx context.Context, attachmentID, fetchedAt, status, message string) error {
_, err := s.db.ExecContext(ctx, `
update message_attachments
set fetched_at = ?,
fetch_status = ?,
fetch_error = ?,
updated_at = ?
where attachment_id = ?
`, nullable(fetchedAt), status, message, time.Now().UTC().Format(timeLayout), attachmentID)
return err
return s.q.UpdateAttachmentFetchStatus(ctx, storedb.UpdateAttachmentFetchStatusParams{
FetchedAt: nullString(fetchedAt),
FetchStatus: status,
FetchError: message,
UpdatedAt: time.Now().UTC().Format(timeLayout),
AttachmentID: attachmentID,
})
}
1 change: 1 addition & 0 deletions internal/store/attachments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func TestAttachmentMediaUpdatesAndFilters(t *testing.T) {
FetchStatus: "fetched",
}))
require.NoError(t, s.UpdateAttachmentFetchStatus(ctx, "a2", "2026-05-15T12:06:00Z", "failed", "boom"))
require.NoError(t, seedAttachmentForGuild(ctx, s, "g1", "c1", "m1", "a1"))

rows, err := s.ListAttachments(ctx, AttachmentListOptions{MissingOnly: true})
require.NoError(t, err)
Expand Down
Loading