diff --git a/bin/migrations/m20210629.ml b/bin/migrations/m20210629.ml index 591dbda..695ae07 100644 --- a/bin/migrations/m20210629.ml +++ b/bin/migrations/m20210629.ml @@ -34,7 +34,7 @@ let jobs = "SELECT id FROM job" let latest_successful_build = - Caqti_request.find + Caqti_request.find_opt Builder_db.Rep.id Builder_db.Rep.id {| SELECT b.id @@ -138,18 +138,21 @@ let migrate datadir (module Db : Caqti_blocking.CONNECTION) = Db.find find_tag "description" >>= fun descr_id -> Db.collect_list jobs () >>= fun jobs -> Grej.list_iter_result (fun job -> - Db.find latest_successful_build job >>= fun build -> - Db.collect_list build_artifacts build >>= fun artifacts -> - List.fold_left (fun acc (fpath, lpath) -> - acc >>= fun acc -> - Bos.OS.File.read Fpath.(append datadir lpath) >>= fun data -> - Ok ((fpath, data) :: acc)) - (Ok []) - artifacts >>= fun files -> - let sec_syn = infer_section_and_synopsis files in - (match fst sec_syn with None -> Ok () | Some s -> Db.exec insert_job_tag (section_id, s, job)) >>= fun () -> - (match snd sec_syn with None, _ -> Ok () | Some s, _ -> Db.exec insert_job_tag (synopsis_id, s, job)) >>= fun () -> - (match snd sec_syn with _, None -> Ok () | _, Some s -> Db.exec insert_job_tag (descr_id, s, job))) + Db.find_opt latest_successful_build job >>= function + | None -> + Ok () + | Some build -> + Db.collect_list build_artifacts build >>= fun artifacts -> + List.fold_left (fun acc (fpath, lpath) -> + acc >>= fun acc -> + Bos.OS.File.read Fpath.(append datadir lpath) >>= fun data -> + Ok ((fpath, data) :: acc)) + (Ok []) + artifacts >>= fun files -> + let sec_syn = infer_section_and_synopsis files in + (match fst sec_syn with None -> Ok () | Some s -> Db.exec insert_job_tag (section_id, s, job)) >>= fun () -> + (match snd sec_syn with None, _ -> Ok () | Some s, _ -> Db.exec insert_job_tag (synopsis_id, s, job)) >>= fun () -> + (match snd sec_syn with _, None -> Ok () | _, Some s -> Db.exec insert_job_tag (descr_id, s, job))) jobs >>= fun () -> Db.exec (Grej.set_version new_version) () diff --git a/bin/migrations/m20210630.ml b/bin/migrations/m20210630.ml index d193fa2..f60f58f 100644 --- a/bin/migrations/m20210630.ml +++ b/bin/migrations/m20210630.ml @@ -10,7 +10,7 @@ let jobs = "SELECT id FROM job" let latest_successful_build = - Caqti_request.find + Caqti_request.find_opt Builder_db.Rep.id Builder_db.Rep.id {| SELECT b.id @@ -63,24 +63,26 @@ let migrate datadir (module Db : Caqti_blocking.CONNECTION) = Db.find find_tag "readme.md" >>= fun readme_id -> Db.collect_list jobs () >>= fun jobs -> Grej.list_iter_result (fun job -> - Db.find latest_successful_build job >>= fun build -> - Db.collect_list build_artifacts build >>= fun artifacts -> - List.fold_left (fun acc (fpath, lpath) -> - acc >>= fun acc -> - Bos.OS.File.read Fpath.(append datadir lpath) >>= fun data -> - Ok ((fpath, data) :: acc)) - (Ok []) - artifacts >>= fun files -> - let readme = - List.find_opt (fun (p, _) -> Fpath.(equal (v "README.md") p)) files - in - let readme_anywhere = - List.find_opt (fun (p, _) -> String.equal "README.md" (Fpath.basename p)) files - in - (match readme, readme_anywhere with - | None, None -> Ok () - | Some (_, data), _ | None, Some (_, data) -> - Db.exec insert_job_tag (readme_id, data, job))) + Db.find_opt latest_successful_build job >>= function + | None -> Ok () + | Some build -> + Db.collect_list build_artifacts build >>= fun artifacts -> + List.fold_left (fun acc (fpath, lpath) -> + acc >>= fun acc -> + Bos.OS.File.read Fpath.(append datadir lpath) >>= fun data -> + Ok ((fpath, data) :: acc)) + (Ok []) + artifacts >>= fun files -> + let readme = + List.find_opt (fun (p, _) -> Fpath.(equal (v "README.md") p)) files + in + let readme_anywhere = + List.find_opt (fun (p, _) -> String.equal "README.md" (Fpath.basename p)) files + in + (match readme, readme_anywhere with + | None, None -> Ok () + | Some (_, data), _ | None, Some (_, data) -> + Db.exec insert_job_tag (readme_id, data, job))) jobs >>= fun () -> Db.exec (Grej.set_version new_version) ()