Fix FOREIGN KEY constraint failed when operating on non-existent issues
Fixes #325 - Fix CloseIssue to check rows affected before inserting event - Fix RemoveLabel to check rows affected before inserting event - Fix UpdateIssueID to check rows affected before inserting event - Prevent orphan events and confusing error messages Amp-Thread-ID: https://ampcode.com/threads/T-aa765a68-5cc4-465b-a2f6-aa008933c11e Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -20,11 +20,20 @@ func (s *SQLiteStorage) executeLabelOperation(
|
||||
operationError string,
|
||||
) error {
|
||||
return s.withTx(ctx, func(tx *sql.Tx) error {
|
||||
_, err := tx.ExecContext(ctx, labelSQL, labelSQLArgs...)
|
||||
result, err := tx.ExecContext(ctx, labelSQL, labelSQLArgs...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %w", operationError, err)
|
||||
}
|
||||
|
||||
rows, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to check rows affected: %w", err)
|
||||
}
|
||||
if rows == 0 {
|
||||
// No change made (label already existed or didn't exist), so don't record event
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err = tx.ExecContext(ctx, `
|
||||
INSERT INTO events (issue_id, event_type, actor, comment)
|
||||
VALUES (?, ?, ?, ?)
|
||||
|
||||
Reference in New Issue
Block a user