Skip to content

Commit

Permalink
Fix type hint in delete history by ids statement. (#5249)
Browse files Browse the repository at this point in the history
The missing `::uuid[]` caused SQLC to generate code splicing the slice
into the statement rather than passing it as-is, i.e. generating
`ANY(?, ?, ?, ?, ...)` rather than `ANY({ ... })`, causing the
statement compilation to fail.
  • Loading branch information
blkt authored Jan 6, 2025
1 parent e32e315 commit a02f754
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 20 deletions.
10 changes: 5 additions & 5 deletions cmd/server/app/history_purge.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
_ "github.com/golang-migrate/migrate/v4/database/postgres" // nolint
_ "github.com/golang-migrate/migrate/v4/source/file" // nolint
"github.com/google/uuid"
"github.com/rs/zerolog"
"github.com/spf13/cobra"
"github.com/spf13/viper"

Expand Down Expand Up @@ -53,9 +54,9 @@ func historyPurgeCommand(cmd *cobra.Command, _ []string) error {
// We maintain up to 30 days of history, plus any record
// that's the latest for any entity/rule pair.
threshold := time.Now().UTC().AddDate(0, 0, -30)
cmd.Printf("Calculated threshold is %s", threshold)
zerolog.Ctx(ctx).Info().Msgf("Calculated threshold is %s", threshold)

if err := purgeLoop(ctx, store, threshold, batchSize, dryRun, cmd.Printf); err != nil {
if err := purgeLoop(ctx, store, threshold, batchSize, dryRun); err != nil {
cliErrorf(cmd, "failed purging evaluation log: %s", err)
}

Expand Down Expand Up @@ -88,7 +89,6 @@ func purgeLoop(
threshold time.Time,
batchSize uint,
dryRun bool,
printf func(format string, a ...any),
) error {
deleted := 0

Expand All @@ -107,7 +107,7 @@ func purgeLoop(
}

if len(records) == 0 {
printf("No records to delete\n")
zerolog.Ctx(ctx).Info().Msg("No records to delete\n")
return nil
}

Expand All @@ -124,7 +124,7 @@ func purgeLoop(
}
}

printf("Done purging history, deleted %d records\n",
zerolog.Ctx(ctx).Info().Msgf("Done purging history, deleted %d records",
deleted,
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/server/app/history_purge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func TestPurgeLoop(t *testing.T) {
store = tt.dbSetup(ctrl)
}

err := purgeLoop(ctx, store, tt.threshold, tt.size, tt.dryRun, t.Logf)
err := purgeLoop(ctx, store, tt.threshold, tt.size, tt.dryRun)
if tt.err {
require.Error(t, err)
return
Expand Down
2 changes: 1 addition & 1 deletion database/query/eval_history.sql
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,4 @@ SELECT s.evaluation_time,

-- name: DeleteEvaluationHistoryByIDs :execrows
DELETE FROM evaluation_statuses s
WHERE s.id = ANY(sqlc.slice(evaluationIds));
WHERE s.id = ANY(sqlc.slice(evaluationIds)::uuid[]);
15 changes: 2 additions & 13 deletions internal/db/eval_history.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a02f754

Please sign in to comment.