diff --git a/bin/migrations/builder_migrations.ml b/bin/migrations/builder_migrations.ml index edcb8bf..862ffd3 100644 --- a/bin/migrations/builder_migrations.ml +++ b/bin/migrations/builder_migrations.ml @@ -179,6 +179,7 @@ let () = [ f20210910 ]; actions (module M20211105); actions (module M20220509); + actions (module M20230911); ]) |> Cmd.eval |> exit diff --git a/bin/migrations/m20230911.ml b/bin/migrations/m20230911.ml new file mode 100644 index 0000000..ec36977 --- /dev/null +++ b/bin/migrations/m20230911.ml @@ -0,0 +1,26 @@ +let new_version = 17L and old_version = 16L +and identifier = "2023-09-11" +and migrate_doc = "index failed builds on main binary is null" +and rollback_doc = "index failed builds on exit code" + +open Grej.Syntax + +let migrate _datadir (module Db : Caqti_blocking.CONNECTION) = + let* () = Grej.check_version ~user_version:old_version (module Db) in + let* () = + Db.exec (Caqti_type.unit ->. Caqti_type.unit @@ + "CREATE INDEX idx_build_failed ON build(job, start_d DESC, start_ps DESC) \ + WHERE main_binary IS NULL") + () + in + Db.exec (Grej.set_version new_version) () + +let rollback _datadir (module Db : Caqti_blocking.CONNECTION) = + let* () = Grej.check_version ~user_version:new_version (module Db) in + let* () = + Db.exec (Caqti_type.unit ->. Caqti_type.unit @@ + "CREATE INDEX idx_build_failed ON build(job, start_d DESC, start_ps DESC) \ + WHERE result_code <> 0") + () + in + Db.exec (Grej.set_version old_version) () diff --git a/db/builder_db.ml b/db/builder_db.ml index 18f6d29..6ea1ba8 100644 --- a/db/builder_db.ml +++ b/db/builder_db.ml @@ -5,7 +5,7 @@ open Caqti_request.Infix let application_id = 1234839235l (* Please update this when making changes! *) -let current_version = 16L +let current_version = 17L type 'a id = 'a Rep.id @@ -283,7 +283,7 @@ module Build = struct b.main_binary, b.input_id, b.user, b.job FROM build b INNER JOIN job ON job.id = b.job - WHERE b.result_code <> 0 AND ($3 IS NULL OR b.platform = $3) + WHERE b.main_binary IS NULL AND ($3 IS NULL OR b.platform = $3) ORDER BY start_d DESC, start_ps DESC LIMIT $2 OFFSET $1 @@ -304,7 +304,8 @@ module Build = struct result_code, result_msg, console, script, platform, main_binary, input_id, user, job FROM build - WHERE job = $1 AND result_code <> 0 + WHERE job = $1 + AND main_binary IS NULL AND ($2 IS NULL OR platform = $2) ORDER BY start_d DESC, start_ps DESC |} @@ -319,7 +320,7 @@ module Build = struct FROM build b LEFT JOIN build_artifact a ON b.main_binary = a.id - WHERE b.job = $1 AND b.platform = $2 AND b.result_code = 0 + WHERE b.job = $1 AND b.platform = $2 ORDER BY b.start_d DESC, b.start_ps DESC LIMIT 1 |} @@ -331,8 +332,9 @@ module Build = struct b.result_code, b.result_msg, b.console, b.script, b.platform, b.main_binary, b.input_id, b.user, b.job FROM build b - WHERE b.job = $1 AND b.result_code = 0 + WHERE b.job = $1 AND ($2 IS NULL OR b.platform = $2) + AND b.main_binary IS NOT NULL ORDER BY b.start_d DESC, b.start_ps DESC LIMIT 1 |} @@ -346,7 +348,6 @@ module Build = struct FROM build b, build b0, build_artifact a, build_artifact a0 WHERE b0.id = ? AND b0.job = b.job AND b.platform = b0.platform AND - b.result_code = 0 AND a.id = b.main_binary AND a0.id = b0.main_binary AND a.sha256 <> a0.sha256 AND (b0.start_d > b.start_d OR b0.start_d = b.start_d AND b0.start_ps > b.start_ps) @@ -363,7 +364,6 @@ module Build = struct FROM build b, build b0, build_artifact a, build_artifact a0 WHERE b0.id = ? AND b0.job = b.job AND b.platform = b0.platform AND - b.result_code = 0 AND a.id = b.main_binary AND a0.id = b0.main_binary AND a.sha256 <> a0.sha256 AND (b0.start_d < b.start_d OR b0.start_d = b.start_d AND b0.start_ps < b.start_ps) @@ -585,7 +585,7 @@ let migrate = [ Caqti_type.unit ->. Caqti_type.unit @@ "CREATE INDEX idx_build_job_start ON build(job, start_d DESC, start_ps DESC)"; Caqti_type.unit ->. Caqti_type.unit @@ - "CREATE INDEX idx_build_failed ON build(job, start_d DESC, start_ps DESC) WHERE result_code <> 0"; + "CREATE INDEX idx_build_failed ON build(job, start_d DESC, start_ps DESC) WHERE main_binary IS NULL"; Caqti_type.unit ->. Caqti_type.unit @@ "CREATE INDEX idx_build_input_id ON build(input_id)"; Caqti_type.unit ->. Caqti_type.unit @@