fix: stats table empty when using PostgreSQL backend - #260
Open
brewle wants to merge 1 commit into
Open
Conversation
✅ Deploy Preview for peekaping ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for docspeekaping ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When using PostgreSQL as the database backend, the response time charts and uptime statistics are always empty, even though heartbeats are being recorded correctly.
The root cause is in
UpsertStatmethod instats.sql.repository.go.The original implementation used an UPDATE -> check RowsAffected -> INSERT pattern. On PostgreSQL,
RowsAffected()returns-1for UPDATE queries without aRETURNINGclause (this is a known behavior of thelib/pqdriver). As a result, the fallback INSERT never executes and thestatstable remains empty.This does not affect SQLite because SQLite always returns the correct
RowsAffectedvalue.Fix
Replace the UPDATE -> check -> INSERT pattern with a single atomic
INSERT ... ON CONFLICT (monitor_id, timestamp) DO UPDATEstatement.This works correctly on both PostgreSQL and SQLite.
Related issues
Fixes #188
Fixes #196