fixup 2021-07-07d: remove initial ./ from fpath

This commit is contained in:
Robur 2021-07-07 13:00:57 +00:00
parent 1b4b27e1c5
commit b09001916b
2 changed files with 34 additions and 0 deletions

View file

@ -105,6 +105,11 @@ let f20210707c =
Cmdliner.Term.(const do_database_action $ const M20210707c.fixup $ setup_log $ datadir),
Cmdliner.Term.info ~doc "fixup-2021-07-07c"
let f20210707d =
let doc = "Remove ./ from filepath." in
Cmdliner.Term.(const do_database_action $ const M20210707d.fixup $ setup_log $ datadir),
Cmdliner.Term.info ~doc "fixup-2021-07-07d"
let help_cmd =
let topic =
let doc = "Migration to get help on" in
@ -142,5 +147,6 @@ let () =
[ f20210707a ];
[ f20210707b ];
[ f20210707c ];
[ f20210707d ];
])
|> Cmdliner.Term.exit

View file

@ -0,0 +1,28 @@
let all_build_artifacts_with_dot_slash : (unit, [`build_artifact] Builder_db.Rep.id * Fpath.t, [ `Zero | `One | `Many ]) Caqti_request.t =
Caqti_request.collect ~oneshot:true
Caqti_type.unit
(Caqti_type.tup2 (Builder_db.Rep.id `build_artifact) Builder_db.Rep.fpath)
"SELECT id, filepath FROM build_artifact WHERE filepath LIKE './%'"
let update_path : ([`build_artifact] Builder_db.Rep.id * Fpath.t, unit, [< `Zero | `One | `Many > `Zero ]) Caqti_request.t =
Caqti_request.exec
(Caqti_type.tup2 (Builder_db.Rep.id `build_artifact) Builder_db.Rep.fpath)
"UPDATE build_artifact SET filepath = ?2 WHERE id = ?1"
let fixup _datadir (module Db : Caqti_blocking.CONNECTION) =
let open Rresult.R.Infix in
Grej.check_version ~user_version:12L (module Db) >>= fun () ->
Db.rev_collect_list all_build_artifacts_with_dot_slash () >>= fun build_artifacts ->
Grej.list_iter_result
(fun (id, fpath) ->
let segs = match Fpath.segs fpath with
| "." :: tl -> tl
| x -> x
in
let fpath' = Fpath.v (String.concat "/" segs) in
if Fpath.equal fpath fpath' then
Ok ()
else
Db.exec update_path (id, fpath'))
build_artifacts