Skip to content

fix(database): fix GetRecordCIDs failing with PostgreSQL backend#1807

Merged
paralta merged 1 commit into
mainfrom
fix/search-postgres
Jul 14, 2026
Merged

fix(database): fix GetRecordCIDs failing with PostgreSQL backend#1807
paralta merged 1 commit into
mainfrom
fix/search-postgres

Conversation

@paralta

@paralta paralta commented Jul 14, 2026

Copy link
Copy Markdown
Member

GetRecordCIDs was querying SELECT DISTINCT records.record_cid while applyRecordOrder always appended ORDER BY records.created_at DESC, records.record_cid ASC. PostgreSQL enforces the SQL standard requirement that all ORDER BY expressions appear in the SELECT list for SELECT DISTINCT queries (SQLSTATE 42P10), whereas SQLite silently permits it — so the bug only surfaced when running against a real PostgreSQL database.

The fix expands the SELECT to include all columns that applyRecordOrder may reference (created_at, name, version, schema_version, and usage-metrics expressions when needed). Because record_cid is the primary key, these columns are functionally dependent on it, so DISTINCT still deduplicates at the record level. Pluck is replaced with Find into a minimal struct, since Pluck does not correctly scan a multi-column result into a string slice.

@github-actions github-actions Bot added the size/XS Denotes a PR that changes 0-49 lines label Jul 14, 2026
@paralta
paralta marked this pull request as ready for review July 14, 2026 12:11
@paralta
paralta requested a review from a team as a code owner July 14, 2026 12:11
Signed-off-by: Catarina Paralta <clouropa@cisco.com>
@paralta
paralta force-pushed the fix/search-postgres branch from b18e369 to 781a0bd Compare July 14, 2026 12:36
@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
server/database/gorm/record.go 93.3% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@paralta
paralta merged commit 1486cab into main Jul 14, 2026
32 checks passed
@paralta
paralta deleted the fix/search-postgres branch July 14, 2026 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS Denotes a PR that changes 0-49 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants