builder-web/bin/migrations/m20210308.ml
Reynir Björnsson 3b81c52c59 Expose database repr, database fixup
Parts of the database representation are exposed.
A fixup command for builder-migrations is added to remove bad database
entries fixed in a57798f4c0. It is up to
the operator to remove the files and optionally re-upload the 'full'
files to builder-web.
2021-03-08 17:01:00 +01:00

23 lines
919 B
OCaml

module Rep = Builder_db.Rep
let broken_builds =
Caqti_request.collect ~oneshot:true
Caqti_type.unit
(Caqti_type.tup3 Rep.id Rep.uuid Caqti_type.string)
{| SELECT b.id, b.uuid, job.name FROM build b, job
WHERE result_kind = 0 AND result_code = 0 AND main_binary IS NOT NULL AND job.id = b.job AND
(SELECT COUNT( * ) FROM build_artifact a
WHERE a.build = b.id and a.filepath = b.main_binary) = 0
|}
let fixup (module Db : Caqti_blocking.CONNECTION) =
let open Rresult.R.Infix in
Db.rev_collect_list broken_builds () >>= fun broken_builds ->
List.fold_left
(fun r ((build, uuid, job_name) : Rep.id * Uuidm.t * string) ->
r >>= fun () ->
Format.printf "Removing job %a.\nPlease clean up data files in /var/db/builder-web/%s/%a\n"
Uuidm.pp uuid job_name Uuidm.pp uuid;
Db.exec Builder_db.Build.remove build)
(Ok ())
broken_builds