Webpush: Fix FK issue with Postgres

This commit is contained in:
binwiederhier
2026-03-16 10:24:16 -04:00
parent 6b38acb23a
commit 3a37ea32f7
4 changed files with 8 additions and 3 deletions
+4 -2
View File
@@ -26,6 +26,7 @@ var (
type Store struct {
db *db.DB
queries queries
}
// queries holds the database-specific SQL queries.
@@ -63,9 +64,10 @@ func (s *Store) UpsertSubscription(endpoint string, auth, p256dh, userID string,
} else if err != nil {
return err
}
// Insert or update subscription
// Insert or update subscription, and read back the actual ID (which may differ from
// the generated one if another request for the same endpoint raced us and inserted first)
updatedAt, warnedAt := time.Now().Unix(), 0
if _, err := tx.Exec(s.queries.upsertSubscription, subscriptionID, endpoint, auth, p256dh, userID, subscriberIP.String(), updatedAt, warnedAt); err != nil {
if err := tx.QueryRow(s.queries.upsertSubscription, subscriptionID, endpoint, auth, p256dh, userID, subscriberIP.String(), updatedAt, warnedAt).Scan(&subscriptionID); err != nil {
return err
}
// Replace all subscription topics