From b09001916b1d0a40dc37fa07f73fcf83c15a7cdd Mon Sep 17 00:00:00 2001 From: Robur Date: Wed, 7 Jul 2021 13:00:57 +0000 Subject: [PATCH] fixup 2021-07-07d: remove initial ./ from fpath --- bin/migrations/builder_migrations.ml | 6 ++++++ bin/migrations/m20210707d.ml | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 bin/migrations/m20210707d.ml diff --git a/bin/migrations/builder_migrations.ml b/bin/migrations/builder_migrations.ml index 0662753..5298b9d 100644 --- a/bin/migrations/builder_migrations.ml +++ b/bin/migrations/builder_migrations.ml @@ -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 diff --git a/bin/migrations/m20210707d.ml b/bin/migrations/m20210707d.ml new file mode 100644 index 0000000..ba9ce19 --- /dev/null +++ b/bin/migrations/m20210707d.ml @@ -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