Commit 4c1b2cd
committed
fix(db): replace FirstOrCreate+Assign with explicit Find→Create/Save in UpsertAlert
Root cause: GORM v2's FirstOrCreate+Assign does not reliably update existing
records — Assign attaches attributes before the query but the actual UPDATE is
inconsistently applied. Dismissed/fixed alerts fetched from GitHub were silently
dropped, leaving DB records permanently stuck as state='open'.
Symptom: security_alerts rows had state='open' with dismissed_at or fixed_at
populated — an impossible combination from GitHub's API that indicated the DB
state was never updated after initial creation.
Fix: explicit lookup + create-or-save:
1. Find by (repository_id, alert_type, alert_number)
2. If not found: Create (new record)
3. If found: Save (full UPDATE with current GitHub state, preserving ID/CreatedAt)
Verified: bsv-blockchain/arcade and bsv-blockchain/go-wallet-toolbox now show
0 alerts after sync (were showing 3 and 8 respectively — all dismissed/fixed).1 parent d0340ad commit 4c1b2cd
1 file changed
Lines changed: 18 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
258 | 259 | | |
259 | 260 | | |
260 | 261 | | |
261 | | - | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
262 | 266 | | |
263 | 267 | | |
264 | | - | |
265 | | - | |
266 | | - | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
267 | 281 | | |
268 | 282 | | |
269 | 283 | | |
| |||
0 commit comments