Alter db build index
We started looking up by date a lot.
This commit is contained in:
parent
4f17b8b8a6
commit
561a81a951
3 changed files with 45 additions and 2 deletions
|
@ -101,6 +101,17 @@ let f20210308 =
|
||||||
Cmdliner.Term.(const do_database_action $ const M20210308.fixup $ setup_log $ dbpath),
|
Cmdliner.Term.(const do_database_action $ const M20210308.fixup $ setup_log $ dbpath),
|
||||||
Cmdliner.Term.info ~doc "fixup-2021-03-08"
|
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 help_cmd =
|
||||||
let topic =
|
let topic =
|
||||||
let doc = "Migration to get help on" in
|
let doc = "Migration to get help on" in
|
||||||
|
@ -124,5 +135,6 @@ let () =
|
||||||
m20210216; r20210216;
|
m20210216; r20210216;
|
||||||
m20210218; r20210218;
|
m20210218; r20210218;
|
||||||
f20210308;
|
f20210308;
|
||||||
|
m20210427; r20210427;
|
||||||
]
|
]
|
||||||
|> Cmdliner.Term.exit
|
|> Cmdliner.Term.exit
|
||||||
|
|
31
bin/migrations/m20210427.ml
Normal file
31
bin/migrations/m20210427.ml
Normal 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 ()
|
|
@ -516,7 +516,7 @@ let migrate = [
|
||||||
Build_file.migrate;
|
Build_file.migrate;
|
||||||
User.migrate;
|
User.migrate;
|
||||||
Caqti_request.exec Caqti_type.unit
|
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_current_version;
|
||||||
set_application_id;
|
set_application_id;
|
||||||
]
|
]
|
||||||
|
@ -528,7 +528,7 @@ let rollback = [
|
||||||
Build.rollback;
|
Build.rollback;
|
||||||
Job.rollback;
|
Job.rollback;
|
||||||
Caqti_request.exec Caqti_type.unit
|
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
|
Caqti_request.exec Caqti_type.unit
|
||||||
"PRAGMA user_version = 0";
|
"PRAGMA user_version = 0";
|
||||||
Caqti_request.exec Caqti_type.unit
|
Caqti_request.exec Caqti_type.unit
|
||||||
|
|
Loading…
Reference in a new issue