2021-06-01 15:43:55 +00:00
|
|
|
let old_version = 3L
|
|
|
|
let new_version = 4L
|
2021-06-10 10:08:14 +00:00
|
|
|
let identifier = "2021-05-31"
|
|
|
|
let migrate_doc = "remove datadir prefix from build_artifact.localpath"
|
|
|
|
let rollback_doc = "add datadir prefix to build_artifact.localpath"
|
2021-06-01 15:43:55 +00:00
|
|
|
|
|
|
|
let build_artifacts =
|
|
|
|
Caqti_request.collect ~oneshot:true
|
|
|
|
Caqti_type.unit
|
2021-07-05 12:45:08 +00:00
|
|
|
Caqti_type.(tup2 Builder_db.Rep.untyped_id Builder_db.Rep.fpath)
|
2021-06-01 15:43:55 +00:00
|
|
|
"SELECT id, localpath FROM build_artifact"
|
|
|
|
|
|
|
|
let build_artifact_update_localpath =
|
|
|
|
Caqti_request.exec ~oneshot:true
|
2021-07-05 12:45:08 +00:00
|
|
|
Caqti_type.(tup2 Builder_db.Rep.untyped_id Builder_db.Rep.fpath)
|
2021-11-18 10:40:15 +00:00
|
|
|
"UPDATE build_artifact SET localpath = $2 WHERE id = $1"
|
2021-06-01 15:43:55 +00:00
|
|
|
|
|
|
|
(* We are not migrating build_file because it is unused *)
|
|
|
|
|
|
|
|
let migrate datadir (module Db : Caqti_blocking.CONNECTION) =
|
2021-10-20 09:10:43 +00:00
|
|
|
let open Grej.Infix in
|
2021-06-01 15:43:55 +00:00
|
|
|
Grej.check_version ~user_version:old_version (module Db) >>= fun () ->
|
|
|
|
Db.collect_list build_artifacts () >>= fun artifacts ->
|
|
|
|
Grej.list_iter_result (fun (id, localpath) ->
|
|
|
|
match Fpath.rem_prefix datadir localpath with
|
|
|
|
| Some p -> Db.exec build_artifact_update_localpath (id, p)
|
|
|
|
| None -> Error (`Msg ("couldn't remove datadir prefix from " ^ Fpath.to_string localpath)))
|
|
|
|
artifacts >>= fun () ->
|
|
|
|
Db.exec (Grej.set_version new_version) ()
|
|
|
|
|
|
|
|
let rollback datadir (module Db : Caqti_blocking.CONNECTION) =
|
2021-10-20 09:10:43 +00:00
|
|
|
let open Grej.Infix in
|
2021-06-01 15:43:55 +00:00
|
|
|
Grej.check_version ~user_version:new_version (module Db) >>= fun () ->
|
|
|
|
Db.collect_list build_artifacts () >>= fun artifacts ->
|
|
|
|
Grej.list_iter_result (fun (id, localpath) ->
|
|
|
|
let p = Fpath.(datadir // localpath) in
|
|
|
|
Db.exec build_artifact_update_localpath (id, p))
|
|
|
|
artifacts >>= fun () ->
|
|
|
|
Db.exec (Grej.set_version old_version) ()
|