From a4c2c853d6bf6866d3af2c8face58d9e00c29018 Mon Sep 17 00:00:00 2001 From: Brandur Date: Thu, 22 May 2025 08:50:11 -0700 Subject: [PATCH] Correct reindexer's handling of explicit schema Here, correct the reindexer's handling of an explicitly inject schema, which was being added with a "." _before_ the schema name instead of after. We also patch up the test suite. Looking into this, the error was being emitted in the tests as clear as day, but none of the tests were asserting anything (basically just that the reindexer ran in some way, shape, or form, not that it had been successful or done any work), so it was just being ignored. Fixes #915. --- CHANGELOG.md | 1 + internal/maintenance/reindexer.go | 2 +- internal/maintenance/reindexer_test.go | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e63da16c..e2e01406 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Resuming an already unpaused queue is now fully an no-op, and won't touch the row's `updated_at` like it (unintentionally) did before. [PR #870](https://github.com/riverqueue/river/pull/870). - Suppress an error log line from the producer that may occur on normal shutdown when operating in poll-only mode. [PR #896](https://github.com/riverqueue/river/pull/896). - Added missing help documentation for CLI command `river migrate-list`. [PR #903](https://github.com/riverqueue/river/pull/903). +- Correct handling an explicit schema in the reindexer maintenance service. [PR #916](https://github.com/riverqueue/river/pull/916). ## [0.22.0] - 2025-05-10 diff --git a/internal/maintenance/reindexer.go b/internal/maintenance/reindexer.go index 1de4b0cf..9f868f8b 100644 --- a/internal/maintenance/reindexer.go +++ b/internal/maintenance/reindexer.go @@ -164,7 +164,7 @@ func (s *Reindexer) reindexOne(ctx context.Context, indexName string) error { var maybeSchema string if s.Config.Schema != "" { - maybeSchema = "." + s.Config.Schema + maybeSchema = s.Config.Schema + "." } _, err := s.exec.Exec(ctx, "REINDEX INDEX CONCURRENTLY "+maybeSchema+indexName) diff --git a/internal/maintenance/reindexer_test.go b/internal/maintenance/reindexer_test.go index f71f6cb5..2519c351 100644 --- a/internal/maintenance/reindexer_test.go +++ b/internal/maintenance/reindexer_test.go @@ -78,6 +78,16 @@ func TestReindexer(t *testing.T) { startstoptest.Stress(ctx, t, svc) }) + t.Run("ReindexesOne", func(t *testing.T) { + t.Parallel() + + svc, _ := setup(t) + + for _, indexName := range svc.Config.IndexNames { + require.NoError(t, svc.reindexOne(ctx, indexName)) + } + }) + t.Run("ReindexesEachIndex", func(t *testing.T) { t.Parallel()