Creating index for uuid after migration, and dropping on rollback

This commit is contained in:
rand00 2022-05-10 14:50:22 +02:00 committed by Reynir Björnsson
parent a45b373019
commit bca4c80127

View file

@ -33,11 +33,20 @@ let rollback_q =
(Caqti_type.tup2 (Builder_db.Rep.id (`build : [`build])) old_uuid_rep) (Caqti_type.tup2 (Builder_db.Rep.id (`build : [`build])) old_uuid_rep)
"UPDATE build SET uuid = $2 WHERE id = $1" "UPDATE build SET uuid = $2 WHERE id = $1"
let create_index =
Caqti_request.exec Caqti_type.unit
"CREATE INDEX idx_build_uuid ON build(uuid);"
let drop_index =
Caqti_request.exec Caqti_type.unit
"DROP INDEX idx_build_uuid;"
let migrate _datadir (module Db : Caqti_blocking.CONNECTION) = let migrate _datadir (module Db : Caqti_blocking.CONNECTION) =
let open Grej.Infix in let open Grej.Infix in
Grej.check_version ~user_version:old_version (module Db) >>= fun () -> Grej.check_version ~user_version:old_version (module Db) >>= fun () ->
Db.collect_list uuids_byte_encoded_q () >>= fun old_uuids -> Db.collect_list uuids_byte_encoded_q () >>= fun old_uuids ->
Grej.list_iter_result (Db.exec migrate_q) old_uuids >>= fun () -> Grej.list_iter_result (Db.exec migrate_q) old_uuids >>= fun () ->
Db.exec create_index () >>= fun () ->
Db.exec (Grej.set_version new_version) () Db.exec (Grej.set_version new_version) ()
let rollback _datadir (module Db : Caqti_blocking.CONNECTION) = let rollback _datadir (module Db : Caqti_blocking.CONNECTION) =
@ -45,4 +54,5 @@ let rollback _datadir (module Db : Caqti_blocking.CONNECTION) =
Grej.check_version ~user_version:new_version (module Db) >>= fun () -> Grej.check_version ~user_version:new_version (module Db) >>= fun () ->
Db.collect_list uuids_hex_encoded_q () >>= fun new_uuids -> Db.collect_list uuids_hex_encoded_q () >>= fun new_uuids ->
Grej.list_iter_result (Db.exec rollback_q) new_uuids >>= fun () -> Grej.list_iter_result (Db.exec rollback_q) new_uuids >>= fun () ->
Db.exec drop_index () >>= fun () ->
Db.exec (Grej.set_version old_version) () Db.exec (Grej.set_version old_version) ()