Alter db build index

We started looking up by date a lot.
This commit is contained in:
Reynir Björnsson 2021-04-29 15:16:19 +02:00
parent 4f17b8b8a6
commit 561a81a951
3 changed files with 45 additions and 2 deletions

View file

@ -101,6 +101,17 @@ let f20210308 =
Cmdliner.Term.(const do_database_action $ const M20210308.fixup $ setup_log $ dbpath),
Cmdliner.Term.info ~doc "fixup-2021-03-08"
let m20210427 =
let doc = "Adds an index 'idx_build_job_start' on 'build' (2021-04-27)" in
Cmdliner.Term.(const do_database_action $ const M20210427.migrate $ setup_log $ dbpath),
Cmdliner.Term.info ~doc "migrate-2021-04-27"
let r20210427 =
let doc = "Rollback index 'idx_build_job_start'' on 'build' (2021-04-27)" in
Cmdliner.Term.(const do_database_action $ const M20210427.rollback $ setup_log $ dbpath),
Cmdliner.Term.info ~doc "rollback-2021-04-27"
let help_cmd =
let topic =
let doc = "Migration to get help on" in
@ -124,5 +135,6 @@ let () =
m20210216; r20210216;
m20210218; r20210218;
f20210308;
m20210427; r20210427;
]
|> Cmdliner.Term.exit

View file

@ -0,0 +1,31 @@
open Rresult.R.Infix
let migrate (module Db : Caqti_blocking.CONNECTION) =
let idx_build_job_start =
Caqti_request.exec ~oneshot:true
Caqti_type.unit
"CREATE INDEX idx_build_job_start ON build(job, start_d DESC, start_ps DESC)"
in
let rm_job_build_idx =
Caqti_request.exec ~oneshot:true
Caqti_type.unit
"DROP INDEX IF EXISTS job_build_idx"
in
Grej.check_version ~user_version:3L (module Db) >>= fun () ->
Db.exec rm_job_build_idx () >>= fun () ->
Db.exec idx_build_job_start ()
let rollback (module Db : Caqti_blocking.CONNECTION) =
let job_build_idx =
Caqti_request.exec ~oneshot:true
Caqti_type.unit
"CREATE INDEX job_build_idx ON build(job)"
in
let rm_idx_build_job_start =
Caqti_request.exec ~oneshot:true
Caqti_type.unit
"DROP INDEX IF EXISTS idx_build_job_start"
in
Grej.check_version ~user_version:3L (module Db) >>= fun () ->
Db.exec rm_idx_build_job_start () >>= fun () ->
Db.exec job_build_idx ()

View file

@ -516,7 +516,7 @@ let migrate = [
Build_file.migrate;
User.migrate;
Caqti_request.exec Caqti_type.unit
"CREATE INDEX job_build_idx ON build(job)";
"CREATE INDEX idx_build_job_start ON build(job, startd DESC, start_ps DESC)";
set_current_version;
set_application_id;
]
@ -528,7 +528,7 @@ let rollback = [
Build.rollback;
Job.rollback;
Caqti_request.exec Caqti_type.unit
"DROP INDEX IF EXISTS job_build_idx";
"DROP INDEX IF EXISTS idx_build_job_start";
Caqti_request.exec Caqti_type.unit
"PRAGMA user_version = 0";
Caqti_request.exec Caqti_type.unit