Skip to content

Commit

Permalink
Add a handler for deleting a build from the DB. Careful!
Browse files Browse the repository at this point in the history
For #40.
  • Loading branch information
bsiegert committed Aug 22, 2024
1 parent b83ab42 commit 1aa85a8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
20 changes: 20 additions & 0 deletions ddao/manual_additions.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ func (d *DB) BeginReadOnlyTransaction(ctx context.Context) (*DB, func(), error)
}, func() { tx.Rollback() }, nil
}

// DeleteBuild deletes an entire build entry, the metadata and the detailed results.
func (d *DB) DeleteBuild(ctx context.Context, buildID int64) error {
tx, err := d.BeginTransaction(ctx, nil)
if err != nil {
return err
}
defer tx.Rollback()

q := d.WithTx(tx)
err = q.DeleteAllForBuild(ctx, NullInt64(buildID))
if err != nil {
return err
}
err = q.deleteBuild(ctx, buildID)
if err != nil {
return err
}
return tx.Commit()
}

// PutResults writes the results for the given build ID to the database.
func (d *DB) PutResults(ctx context.Context, results []PkgResult, buildID int64) error {
tx, err := d.BeginTransaction(ctx, nil)
Expand Down
10 changes: 10 additions & 0 deletions ddao/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion pages/bulktracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ func (b *BuildDetails) ServeHTTP(w http.ResponseWriter, r *http.Request) {
templates.ReindexOK(w)
return
case "delete":
// delete.DeleteBuildDetails.Call(ctx, key)
err = b.DB.DeleteBuild(ctx, buildID)
if err != nil {
log.Errorf(ctx, "DeleteBuild: %v", err)
}
return
}

if len(paths) > 1 {
Expand Down
4 changes: 4 additions & 0 deletions queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
DELETE from results
WHERE build_id = ?;

-- name: deleteBuild :exec
DELETE from builds
WHERE build_id = ?;

-- name: GetBuild :one
SELECT * FROM builds
WHERE build_id = ?;
Expand Down

0 comments on commit 1aa85a8

Please sign in to comment.