In internal/database/migrations.go, applyMigration has:
deferfunc(){iferr!=nil{_=transaction.Rollback()}}()_,err=transaction.ExecContext(ctx,string(content))// ..._,err=transaction.ExecContext(ctx,"INSERT INTO schema_migrations ...")// ...commitErr:=transaction.Commit()ifcommitErr!=nil{returnfmt.Errorf("failed to commit migration: %w",commitErr)}
When Commit() fails, the error is stored in commitErr, not err. The deferred function checks err, which is nil (from the last successful ExecContext). So Rollback() is never called.
Impact
In practice, SQLite automatically rolls back failed commits, so data integrity is maintained. However, this is incorrect Go transaction handling and could cause issues with other database drivers or future changes.
Fix
Assign the commit error back to err:
err=transaction.Commit()iferr!=nil{returnfmt.Errorf("failed to commit migration: %w",err)}
## Bug
In `internal/database/migrations.go`, `applyMigration` has:
```go
defer func() {
if err != nil {
_ = transaction.Rollback()
}
}()
_, err = transaction.ExecContext(ctx, string(content))
// ...
_, err = transaction.ExecContext(ctx, "INSERT INTO schema_migrations ...")
// ...
commitErr := transaction.Commit()
if commitErr != nil {
return fmt.Errorf("failed to commit migration: %w", commitErr)
}
```
When `Commit()` fails, the error is stored in `commitErr`, not `err`. The deferred function checks `err`, which is nil (from the last successful ExecContext). So `Rollback()` is never called.
## Impact
In practice, SQLite automatically rolls back failed commits, so data integrity is maintained. However, this is incorrect Go transaction handling and could cause issues with other database drivers or future changes.
## Fix
Assign the commit error back to `err`:
```go
err = transaction.Commit()
if err != nil {
return fmt.Errorf("failed to commit migration: %w", err)
}
```
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Bug
In
internal/database/migrations.go,applyMigrationhas:When
Commit()fails, the error is stored incommitErr, noterr. The deferred function checkserr, which is nil (from the last successful ExecContext). SoRollback()is never called.Impact
In practice, SQLite automatically rolls back failed commits, so data integrity is maintained. However, this is incorrect Go transaction handling and could cause issues with other database drivers or future changes.
Fix
Assign the commit error back to
err: