Add index job_build_idx on build
This speeds up loading / by ~10x
This commit is contained in:
parent
6b96cae318
commit
03fe06be87
3 changed files with 44 additions and 2 deletions
|
@ -65,6 +65,16 @@ let r20210126 =
|
||||||
Cmdliner.Term.(const do_database_action $ const M20210126.rollback $ setup_log $ dbpath),
|
Cmdliner.Term.(const do_database_action $ const M20210126.rollback $ setup_log $ dbpath),
|
||||||
Cmdliner.Term.info ~doc "rollback-2021-01-26"
|
Cmdliner.Term.info ~doc "rollback-2021-01-26"
|
||||||
|
|
||||||
|
let m20210202 =
|
||||||
|
let doc = "Adds an index 'job_build_idx' on 'build' (2021-02-02)" in
|
||||||
|
Cmdliner.Term.(const do_database_action $ const M20210202.migrate $ setup_log $ dbpath),
|
||||||
|
Cmdliner.Term.info ~doc "migrate-2021-02-02"
|
||||||
|
|
||||||
|
let r20210202 =
|
||||||
|
let doc = "Rollback index 'job_build_idx' on 'build' (2021-02-02)" in
|
||||||
|
Cmdliner.Term.(const do_database_action $ const M20210202.rollback $ setup_log $ dbpath),
|
||||||
|
Cmdliner.Term.info ~doc "rollback-2021-02-02"
|
||||||
|
|
||||||
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
|
||||||
|
@ -82,6 +92,8 @@ let default_cmd =
|
||||||
let () =
|
let () =
|
||||||
Cmdliner.Term.eval_choice
|
Cmdliner.Term.eval_choice
|
||||||
default_cmd
|
default_cmd
|
||||||
[help_cmd;
|
[ help_cmd;
|
||||||
m20210126; r20210126]
|
m20210126; r20210126;
|
||||||
|
m20210202; r20210202;
|
||||||
|
]
|
||||||
|> Cmdliner.Term.exit
|
|> Cmdliner.Term.exit
|
||||||
|
|
26
bin/migrations/m20210202.ml
Normal file
26
bin/migrations/m20210202.ml
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
open Rresult.R.Infix
|
||||||
|
|
||||||
|
let migrate (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
|
||||||
|
Db.find Builder_db.get_application_id () >>= fun application_id ->
|
||||||
|
Db.find Builder_db.get_version () >>= fun user_version ->
|
||||||
|
if application_id <> Builder_db.application_id || user_version <> 1L
|
||||||
|
then Error (`Wrong_version (application_id, user_version))
|
||||||
|
else Db.exec job_build_idx ()
|
||||||
|
|
||||||
|
let rollback (module Db : Caqti_blocking.CONNECTION) =
|
||||||
|
let q =
|
||||||
|
Caqti_request.exec ~oneshot:true
|
||||||
|
Caqti_type.unit
|
||||||
|
"DROP INDEX IF EXISTS job_build_idx"
|
||||||
|
in
|
||||||
|
Db.find Builder_db.get_application_id () >>= fun application_id ->
|
||||||
|
Db.find Builder_db.get_version () >>= fun user_version ->
|
||||||
|
if application_id <> Builder_db.application_id || user_version <> 1L
|
||||||
|
then Error (`Wrong_version (application_id, user_version))
|
||||||
|
else
|
||||||
|
Db.exec q ()
|
|
@ -474,6 +474,8 @@ let migrate = [
|
||||||
Build_artifact.migrate;
|
Build_artifact.migrate;
|
||||||
Build_file.migrate;
|
Build_file.migrate;
|
||||||
User.migrate;
|
User.migrate;
|
||||||
|
Caqti_request.exec Caqti_type.unit
|
||||||
|
"CREATE INDEX job_build_idx ON build(job)";
|
||||||
set_current_version;
|
set_current_version;
|
||||||
set_application_id;
|
set_application_id;
|
||||||
]
|
]
|
||||||
|
@ -484,6 +486,8 @@ let rollback = [
|
||||||
Build_artifact.rollback;
|
Build_artifact.rollback;
|
||||||
Build.rollback;
|
Build.rollback;
|
||||||
Job.rollback;
|
Job.rollback;
|
||||||
|
Caqti_request.exec Caqti_type.unit
|
||||||
|
"DROP INDEX IF EXISTS job_build_idx";
|
||||||
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