builder-web/bin/migrations/grej.ml
2021-11-05 10:10:44 +00:00

39 lines
1.1 KiB
OCaml

(* Grej is utilities *)
module Syntax = struct
let ( let* ) = Result.bind
let ( let+ ) x f = Result.map f x
end
module Infix = struct
let ( >>= ) = Result.bind
let ( >>| ) x f = Result.map f x
end
open Syntax
let set_version version =
Caqti_request.exec ~oneshot:true
Caqti_type.unit
(Printf.sprintf "PRAGMA user_version = %Ld" version)
let check_version
?application_id:(desired_application_id=Builder_db.application_id)
~user_version:desired_user_version
(module Db : Caqti_blocking.CONNECTION) =
let* application_id = Db.find Builder_db.get_application_id () in
let* user_version = Db.find Builder_db.get_version () in
if application_id <> desired_application_id || user_version <> desired_user_version
then Error (`Wrong_version (application_id, user_version))
else Ok ()
let list_iter_result f xs =
List.fold_left
(fun r x -> let* () = r in f x)
(Ok ())
xs
let foreign_keys on =
let on = if on then "ON" else "OFF" in
Caqti_request.exec
Caqti_type.unit
(Printf.sprintf "PRAGMA foreign_keys = %s" on)