internal/postgres: use transaction in db.DeleteModule
db.DeleteModule creates a transaction but does not use this transaction
for its database operations. So use the transaction instead.
Run-TryBot: Shaquille Que
TryBot-Result: kokoro
@@ -728,21 +728,21 @@ func (db *DB) DeleteModule(ctx context.Context, modulePath, version string) (err
// We only need to delete from the modules table. Thanks to ON DELETE
// CASCADE constraints, that will trigger deletions from all other tables.
const stmt = `DELETE FROM modules WHERE module_path=$1 AND version=$2`
- if _, err := db.db.Exec(ctx, stmt, modulePath, version); err != nil {
+ if _, err := tx.Exec(ctx, stmt, modulePath, version); err != nil {
return err
}
- if _, err = db.db.Exec(ctx, `DELETE FROM version_map WHERE module_path = $1 AND resolved_version = $2`, modulePath, version); err != nil {
+ if _, err = tx.Exec(ctx, `DELETE FROM version_map WHERE module_path = $1 AND resolved_version = $2`, modulePath, version); err != nil {
return err
}
var x int
- err = db.db.QueryRow(ctx, `SELECT 1 FROM modules WHERE module_path=$1 LIMIT 1`, modulePath).Scan(&x)
+ err = tx.QueryRow(ctx, `SELECT 1 FROM modules WHERE module_path=$1 LIMIT 1`, modulePath).Scan(&x)
if err != sql.ErrNoRows || err == nil {
return err
}
// No versions of this module exist; remove it from imports_unique.
- _, err = db.db.Exec(ctx, `DELETE FROM imports_unique WHERE from_module_path = $1`, modulePath)
+ _, err = tx.Exec(ctx, `DELETE FROM imports_unique WHERE from_module_path = $1`, modulePath)
return err
})
}
