Reynir Björnsson
bde3baec46
Each migration is, for the most part, a module that exposes expected database version numbers, command identifier and documentation. This results in all information about the migration and rollback are found in the module itself, and builder_migrations.ml only has to reference the module. Some migrations require foreign keys constraints are disabled. It is not possible to enable or disable foreign key constraints inside a transaction.
29 lines
906 B
OCaml
29 lines
906 B
OCaml
(* Grej is utilities *)
|
|
open Rresult.R.Infix
|
|
|
|
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) =
|
|
Db.find Builder_db.get_application_id () >>= fun application_id ->
|
|
Db.find Builder_db.get_version () >>= fun user_version ->
|
|
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 -> r >>= fun () -> 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)
|