diff --git a/database/pgsql/vulnerability.go b/database/pgsql/vulnerability.go index b8a71f06..6ee07a70 100644 --- a/database/pgsql/vulnerability.go +++ b/database/pgsql/vulnerability.go @@ -196,12 +196,6 @@ func (pgSQL *pgSQL) insertVulnerability(vulnerability database.Vulnerability) er tx.Rollback() return handleError("i_vulnerability", err) } - - // Create NewVulnerabilityNotification. - notification := database.VulnerabilityNotification{NewVulnerability: vulnerability} - if err := pgSQL.insertNotification(tx, notification); err != nil { - return err - } } else { // Update vulnerability if vulnerability.Description != existingVulnerability.Description || @@ -228,6 +222,22 @@ func (pgSQL *pgSQL) insertVulnerability(vulnerability database.Vulnerability) er return err } + // Create notification. + var notification database.VulnerabilityNotification + if existingVulnerability.ID == 0 { + notification = database.VulnerabilityNotification{ + NewVulnerability: vulnerability, + } + } else { + notification = database.VulnerabilityNotification{ + OldVulnerability: &existingVulnerability, + NewVulnerability: vulnerability, + } + } + if err := pgSQL.insertNotification(tx, notification); err != nil { + return err + } + // Commit transaction. err = tx.Commit() if err != nil {