2021-01-08 12:47:17 +00:00
|
|
|
module Rep = Representation
|
|
|
|
open Rep
|
|
|
|
|
2021-01-27 20:25:51 +00:00
|
|
|
let application_id = 1234839235l
|
|
|
|
|
|
|
|
(* Please update this when making changes! *)
|
2021-06-25 10:26:03 +00:00
|
|
|
let current_version = 8L
|
2021-01-27 20:25:51 +00:00
|
|
|
|
2021-01-08 12:47:17 +00:00
|
|
|
type id = Rep.id
|
|
|
|
|
2021-01-28 11:17:06 +00:00
|
|
|
type file = Rep.file = {
|
2021-01-08 12:47:17 +00:00
|
|
|
filepath : Fpath.t;
|
|
|
|
localpath : Fpath.t;
|
|
|
|
sha256 : Cstruct.t;
|
2021-02-25 14:27:45 +00:00
|
|
|
size : int;
|
2021-01-08 12:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let last_insert_rowid =
|
|
|
|
Caqti_request.find
|
|
|
|
Caqti_type.unit
|
|
|
|
id
|
|
|
|
"SELECT last_insert_rowid()"
|
|
|
|
|
2021-01-27 20:25:51 +00:00
|
|
|
|
|
|
|
let get_application_id =
|
|
|
|
Caqti_request.find
|
|
|
|
Caqti_type.unit
|
|
|
|
Caqti_type.int32
|
|
|
|
"PRAGMA application_id"
|
|
|
|
|
|
|
|
let get_version =
|
|
|
|
Caqti_request.find
|
|
|
|
Caqti_type.unit
|
|
|
|
Caqti_type.int64
|
|
|
|
"PRAGMA user_version"
|
|
|
|
|
|
|
|
let set_application_id =
|
|
|
|
Caqti_request.exec
|
|
|
|
Caqti_type.unit
|
|
|
|
(Printf.sprintf "PRAGMA application_id = %ld" application_id)
|
|
|
|
|
|
|
|
let set_current_version =
|
|
|
|
Caqti_request.exec
|
|
|
|
Caqti_type.unit
|
|
|
|
(Printf.sprintf "PRAGMA user_version = %Ld" current_version)
|
|
|
|
|
2021-01-08 12:47:17 +00:00
|
|
|
module Job = struct
|
|
|
|
let migrate =
|
|
|
|
Caqti_request.exec
|
|
|
|
Caqti_type.unit
|
|
|
|
{| CREATE TABLE job (
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
|
|
name VARCHAR(255) NOT NULL UNIQUE
|
|
|
|
)
|
|
|
|
|}
|
|
|
|
|
|
|
|
let rollback =
|
|
|
|
Caqti_request.exec
|
|
|
|
Caqti_type.unit
|
|
|
|
{| DROP TABLE IF EXISTS job |}
|
|
|
|
|
|
|
|
let get =
|
2021-03-23 10:53:41 +00:00
|
|
|
Caqti_request.find
|
2021-01-08 12:47:17 +00:00
|
|
|
id
|
|
|
|
Caqti_type.string
|
|
|
|
"SELECT name FROM job WHERE id = ?"
|
|
|
|
|
|
|
|
let get_id_by_name =
|
2021-06-09 09:48:51 +00:00
|
|
|
Caqti_request.find_opt
|
2021-01-08 12:47:17 +00:00
|
|
|
Caqti_type.string
|
|
|
|
id
|
|
|
|
"SELECT id FROM job WHERE name = ?"
|
|
|
|
|
|
|
|
let get_all =
|
|
|
|
Caqti_request.collect
|
|
|
|
Caqti_type.unit
|
|
|
|
Caqti_type.(tup2 id string)
|
|
|
|
"SELECT id, name FROM job ORDER BY name ASC"
|
|
|
|
|
|
|
|
let try_add =
|
|
|
|
Caqti_request.exec
|
|
|
|
Caqti_type.string
|
|
|
|
"INSERT OR IGNORE INTO job (name) VALUES (?)"
|
|
|
|
|
|
|
|
let remove =
|
|
|
|
Caqti_request.exec
|
|
|
|
id
|
|
|
|
"DELETE FROM job WHERE id = ?"
|
|
|
|
end
|
|
|
|
|
|
|
|
module Build_artifact = struct
|
|
|
|
let migrate =
|
|
|
|
Caqti_request.exec
|
|
|
|
Caqti_type.unit
|
|
|
|
{| CREATE TABLE build_artifact (
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
|
|
filepath TEXT NOT NULL, -- the path as in the build
|
|
|
|
localpath TEXT NOT NULL, -- local path to the file on disk
|
|
|
|
sha256 BLOB NOT NULL,
|
2021-02-23 14:37:30 +00:00
|
|
|
size INTEGER NOT NULL,
|
2021-01-08 12:47:17 +00:00
|
|
|
build INTEGER NOT NULL,
|
|
|
|
|
|
|
|
FOREIGN KEY(build) REFERENCES build(id),
|
|
|
|
UNIQUE(build, filepath)
|
|
|
|
)
|
|
|
|
|}
|
|
|
|
|
|
|
|
let rollback =
|
|
|
|
Caqti_request.exec
|
|
|
|
Caqti_type.unit
|
|
|
|
"DROP TABLE IF EXISTS build_artifact"
|
|
|
|
|
2021-01-27 20:25:51 +00:00
|
|
|
let get_by_build =
|
|
|
|
Caqti_request.find
|
|
|
|
(Caqti_type.tup2 id fpath)
|
|
|
|
(Caqti_type.tup2 id file)
|
2021-02-23 14:37:30 +00:00
|
|
|
{| SELECT id, filepath, localpath, sha256, size
|
2021-01-27 20:25:51 +00:00
|
|
|
FROM build_artifact
|
|
|
|
WHERE build = ? AND filepath = ?
|
|
|
|
|}
|
|
|
|
|
2021-01-08 12:47:17 +00:00
|
|
|
let get_by_build_uuid =
|
|
|
|
Caqti_request.find_opt
|
|
|
|
(Caqti_type.tup2 uuid fpath)
|
2021-01-27 20:25:51 +00:00
|
|
|
(Caqti_type.tup2 id file)
|
|
|
|
{| SELECT build_artifact.id, build_artifact.filepath,
|
2021-02-23 14:37:30 +00:00
|
|
|
build_artifact.localpath, build_artifact.sha256, build_artifact.size
|
2021-01-08 12:47:17 +00:00
|
|
|
FROM build_artifact
|
|
|
|
INNER JOIN build ON build.id = build_artifact.build
|
|
|
|
WHERE build.uuid = ? AND build_artifact.filepath = ?
|
|
|
|
|}
|
|
|
|
|
|
|
|
let get_all_by_build =
|
|
|
|
Caqti_request.collect
|
|
|
|
id
|
|
|
|
Caqti_type.(tup2
|
|
|
|
id
|
|
|
|
file)
|
2021-02-23 14:37:30 +00:00
|
|
|
"SELECT id, filepath, localpath, sha256, size FROM build_artifact WHERE build = ?"
|
2021-01-08 12:47:17 +00:00
|
|
|
|
|
|
|
let add =
|
|
|
|
Caqti_request.exec
|
|
|
|
Caqti_type.(tup2 file id)
|
2021-02-23 14:37:30 +00:00
|
|
|
"INSERT INTO build_artifact (filepath, localpath, sha256, size, build)
|
2021-03-04 13:32:58 +00:00
|
|
|
VALUES (?, ?, ?, ?, ?)"
|
2021-01-08 12:47:17 +00:00
|
|
|
|
|
|
|
let remove_by_build =
|
|
|
|
Caqti_request.exec
|
|
|
|
id
|
|
|
|
"DELETE FROM build_artifact WHERE build = ?"
|
2021-06-25 12:01:20 +00:00
|
|
|
|
|
|
|
let remove =
|
|
|
|
Caqti_request.exec
|
|
|
|
id
|
|
|
|
"DELETE FROM build_artifact WHERE id = ?"
|
2021-01-08 12:47:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
module Build = struct
|
|
|
|
type t = {
|
|
|
|
uuid : Uuidm.t;
|
|
|
|
start : Ptime.t;
|
|
|
|
finish : Ptime.t;
|
|
|
|
result : Builder.execution_result;
|
|
|
|
console : (int * string) list;
|
|
|
|
script : string;
|
2021-06-02 10:29:08 +00:00
|
|
|
main_binary : id option;
|
2021-06-09 11:54:24 +00:00
|
|
|
user_id : id;
|
2021-01-08 12:47:17 +00:00
|
|
|
job_id : id;
|
|
|
|
}
|
|
|
|
|
|
|
|
let t =
|
|
|
|
let rep =
|
2021-06-09 11:54:24 +00:00
|
|
|
Caqti_type.(tup3
|
2021-01-08 12:47:17 +00:00
|
|
|
(tup4
|
|
|
|
uuid
|
|
|
|
(tup2
|
|
|
|
Rep.ptime
|
|
|
|
Rep.ptime)
|
|
|
|
(tup2
|
|
|
|
execution_result
|
|
|
|
console)
|
2021-01-27 20:25:51 +00:00
|
|
|
(tup2
|
|
|
|
string
|
2021-06-02 10:29:08 +00:00
|
|
|
(option Rep.id)))
|
2021-06-09 11:54:24 +00:00
|
|
|
id
|
2021-01-08 12:47:17 +00:00
|
|
|
id)
|
|
|
|
in
|
2021-06-09 11:54:24 +00:00
|
|
|
let encode { uuid; start; finish; result; console; script; main_binary; user_id; job_id } =
|
|
|
|
Ok ((uuid, (start, finish), (result, console), (script, main_binary)), user_id, job_id)
|
2021-01-08 12:47:17 +00:00
|
|
|
in
|
2021-06-09 11:54:24 +00:00
|
|
|
let decode ((uuid, (start, finish), (result, console), (script, main_binary)), user_id, job_id) =
|
|
|
|
Ok { uuid; start; finish; result; console; script; main_binary; user_id; job_id }
|
2021-01-08 12:47:17 +00:00
|
|
|
in
|
|
|
|
Caqti_type.custom ~encode ~decode rep
|
|
|
|
|
|
|
|
module Meta = struct
|
|
|
|
type t = {
|
|
|
|
uuid : Uuidm.t;
|
|
|
|
start : Ptime.t;
|
|
|
|
finish : Ptime.t;
|
|
|
|
result : Builder.execution_result;
|
2021-06-02 10:29:08 +00:00
|
|
|
main_binary : id option;
|
2021-06-09 11:54:24 +00:00
|
|
|
user_id : id;
|
2021-01-08 12:47:17 +00:00
|
|
|
job_id : id;
|
|
|
|
}
|
|
|
|
|
|
|
|
let t =
|
|
|
|
let rep =
|
2021-06-09 11:54:24 +00:00
|
|
|
Caqti_type.(tup3
|
2021-01-08 12:47:17 +00:00
|
|
|
(tup4
|
|
|
|
uuid
|
2021-01-27 20:25:51 +00:00
|
|
|
(tup2
|
|
|
|
Rep.ptime
|
|
|
|
Rep.ptime)
|
|
|
|
execution_result
|
2021-06-02 10:29:08 +00:00
|
|
|
(option Rep.id))
|
2021-06-09 11:54:24 +00:00
|
|
|
id
|
2021-01-08 12:47:17 +00:00
|
|
|
id)
|
|
|
|
in
|
2021-06-09 11:54:24 +00:00
|
|
|
let encode { uuid; start; finish; result; main_binary; user_id; job_id } =
|
|
|
|
Ok ((uuid, (start, finish), result, main_binary), user_id, job_id)
|
2021-01-08 12:47:17 +00:00
|
|
|
in
|
2021-06-09 11:54:24 +00:00
|
|
|
let decode ((uuid, (start, finish), result, main_binary), user_id, job_id) =
|
|
|
|
Ok { uuid; start; finish; result; main_binary; user_id; job_id }
|
2021-01-08 12:47:17 +00:00
|
|
|
in
|
|
|
|
Caqti_type.custom ~encode ~decode rep
|
|
|
|
end
|
|
|
|
|
|
|
|
let migrate =
|
|
|
|
Caqti_request.exec
|
|
|
|
Caqti_type.unit
|
|
|
|
{| CREATE TABLE build (
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
|
|
uuid VARCHAR(36) NOT NULL UNIQUE,
|
|
|
|
start_d INTEGER NOT NULL,
|
|
|
|
start_ps INTEGER NOT NULL,
|
|
|
|
finish_d INTEGER NOT NULL,
|
|
|
|
finish_ps INTEGER NOT NULL,
|
|
|
|
result_kind TINYINT NOT NULL,
|
|
|
|
result_code INTEGER,
|
|
|
|
result_msg TEXT,
|
|
|
|
console BLOB NOT NULL,
|
|
|
|
script TEXT NOT NULL,
|
2021-06-02 10:29:08 +00:00
|
|
|
main_binary INTEGER,
|
2021-06-09 11:54:24 +00:00
|
|
|
user INTEGER NOT NULL,
|
2021-01-08 12:47:17 +00:00
|
|
|
job INTEGER NOT NULL,
|
|
|
|
|
2021-06-02 10:29:08 +00:00
|
|
|
FOREIGN KEY(main_binary) REFERENCES build_artifact(id),
|
2021-06-09 11:54:24 +00:00
|
|
|
FOREIGN KEY(user) REFERENCES user(id),
|
2021-01-08 12:47:17 +00:00
|
|
|
FOREIGN KEY(job) REFERENCES job(id)
|
|
|
|
)
|
|
|
|
|}
|
|
|
|
|
|
|
|
let rollback =
|
|
|
|
Caqti_request.exec
|
|
|
|
Caqti_type.unit
|
|
|
|
{| DROP TABLE IF EXISTS build |}
|
|
|
|
|
|
|
|
let get_opt =
|
|
|
|
Caqti_request.find_opt
|
|
|
|
Caqti_type.int64
|
|
|
|
t
|
|
|
|
{| SELECT uuid, start_d, start_ps, finish_d, finish_ps,
|
2021-01-21 11:02:07 +00:00
|
|
|
result_kind, result_code, result_msg,
|
2021-06-09 11:54:24 +00:00
|
|
|
console, script, main_binary, user, job
|
2021-01-08 12:47:17 +00:00
|
|
|
FROM build
|
|
|
|
WHERE id = ?
|
|
|
|
|}
|
|
|
|
|
|
|
|
let get_by_uuid =
|
|
|
|
Caqti_request.find_opt
|
|
|
|
Rep.uuid
|
|
|
|
(Caqti_type.tup2 id t)
|
|
|
|
{| SELECT id, uuid, start_d, start_ps, finish_d, finish_ps,
|
|
|
|
result_kind, result_code, result_msg,
|
2021-06-09 11:54:24 +00:00
|
|
|
console, script, main_binary, user, job
|
2021-01-08 12:47:17 +00:00
|
|
|
FROM build
|
|
|
|
WHERE uuid = ?
|
|
|
|
|}
|
|
|
|
|
|
|
|
let get_all =
|
|
|
|
Caqti_request.collect
|
|
|
|
Caqti_type.int64
|
|
|
|
(Caqti_type.tup2 id t)
|
|
|
|
{| SELECT id, uuid, start_d, start_ps, finish_d, finish_ps,
|
|
|
|
result_kind, result_code, result_msg, console,
|
2021-06-09 11:54:24 +00:00
|
|
|
script, main_binary, user, job
|
2021-01-08 12:47:17 +00:00
|
|
|
FROM build
|
|
|
|
WHERE job = ?
|
2021-01-22 12:15:50 +00:00
|
|
|
ORDER BY start_d DESC, start_ps DESC
|
2021-01-08 12:47:17 +00:00
|
|
|
|}
|
|
|
|
|
|
|
|
let get_all_meta =
|
|
|
|
Caqti_request.collect
|
|
|
|
Caqti_type.int64
|
2021-01-28 11:17:06 +00:00
|
|
|
(Caqti_type.tup3
|
2021-06-07 13:52:37 +00:00
|
|
|
id Meta.t file_opt)
|
2021-01-08 12:47:17 +00:00
|
|
|
{| SELECT build.id, build.uuid,
|
2021-01-28 11:17:06 +00:00
|
|
|
build.start_d, build.start_ps, build.finish_d, build.finish_ps,
|
|
|
|
build.result_kind, build.result_code, build.result_msg,
|
2021-06-09 11:54:24 +00:00
|
|
|
build.main_binary, build.user, build.job,
|
2021-02-23 14:37:30 +00:00
|
|
|
build_artifact.filepath, build_artifact.localpath, build_artifact.sha256, build_artifact.size
|
2021-01-08 12:47:17 +00:00
|
|
|
FROM build, job
|
2021-01-28 11:17:06 +00:00
|
|
|
LEFT JOIN build_artifact ON
|
2021-06-02 10:29:08 +00:00
|
|
|
build.main_binary = build_artifact.id
|
2021-06-07 13:52:37 +00:00
|
|
|
WHERE job.id = ? AND build.job = job.id
|
2021-01-22 12:15:50 +00:00
|
|
|
ORDER BY start_d DESC, start_ps DESC
|
2021-01-08 12:47:17 +00:00
|
|
|
|}
|
|
|
|
|
2021-01-29 13:34:56 +00:00
|
|
|
let get_latest =
|
|
|
|
Caqti_request.find_opt
|
|
|
|
id
|
|
|
|
Caqti_type.(tup3
|
|
|
|
id
|
|
|
|
Meta.t
|
|
|
|
file_opt)
|
|
|
|
{| SELECT b.id,
|
|
|
|
b.uuid, b.start_d, b.start_ps, b.finish_d, b.finish_ps,
|
|
|
|
b.result_kind, b.result_code, b.result_msg,
|
2021-06-09 11:54:24 +00:00
|
|
|
b.main_binary, b.user, b.job,
|
2021-02-23 14:37:30 +00:00
|
|
|
a.filepath, a.localpath, a.sha256, a.size
|
2021-01-29 13:34:56 +00:00
|
|
|
FROM build b
|
|
|
|
LEFT JOIN build_artifact a ON
|
2021-06-02 10:29:08 +00:00
|
|
|
b.main_binary = a.id
|
2021-01-29 13:34:56 +00:00
|
|
|
WHERE b.job = ?
|
|
|
|
ORDER BY start_d DESC, start_ps DESC
|
|
|
|
LIMIT 1
|
|
|
|
|}
|
2021-01-08 12:47:17 +00:00
|
|
|
|
2021-04-23 13:00:12 +00:00
|
|
|
let get_latest_uuid =
|
|
|
|
Caqti_request.find_opt
|
|
|
|
id
|
|
|
|
Caqti_type.(tup2 id Rep.uuid)
|
|
|
|
{| SELECT b.id, b.uuid
|
|
|
|
FROM build b
|
|
|
|
WHERE b.job = ?
|
|
|
|
ORDER BY start_d DESC, start_ps DESC
|
|
|
|
LIMIT 1
|
|
|
|
|}
|
|
|
|
|
2021-06-02 12:23:40 +00:00
|
|
|
let get_latest_successful_uuid =
|
2021-06-02 13:05:10 +00:00
|
|
|
Caqti_request.find_opt
|
2021-06-02 12:23:40 +00:00
|
|
|
id
|
|
|
|
Rep.uuid
|
|
|
|
{| SELECT b.uuid
|
|
|
|
FROM build b
|
|
|
|
WHERE b.job = ? AND b.result_kind = 0 AND b.result_code = 0
|
|
|
|
ORDER BY start_d DESC, start_ps DESC
|
|
|
|
LIMIT 1
|
|
|
|
|}
|
|
|
|
|
2021-06-02 13:05:10 +00:00
|
|
|
let get_previous_successful =
|
2021-04-23 10:06:39 +00:00
|
|
|
Caqti_request.find_opt
|
|
|
|
id
|
|
|
|
Caqti_type.(tup2 id Meta.t)
|
|
|
|
{| SELECT b.id,
|
|
|
|
b.uuid, b.start_d, b.start_ps, b.finish_d, b.finish_ps,
|
|
|
|
b.result_kind, b.result_code, b.result_msg,
|
2021-06-09 11:54:24 +00:00
|
|
|
b.main_binary, b.user, b.job
|
2021-04-23 10:06:39 +00:00
|
|
|
FROM build b, build b0
|
|
|
|
WHERE b0.id = ? AND b0.job = b.job AND
|
2021-06-02 13:05:10 +00:00
|
|
|
b.result_kind = 0 AND b.result_code = 0 AND
|
2021-04-23 10:06:39 +00:00
|
|
|
(b0.start_d > b.start_d OR b0.start_d = b.start_d AND b0.start_ps > b.start_ps)
|
|
|
|
ORDER BY b.start_d DESC, b.start_ps DESC
|
|
|
|
LIMIT 1
|
|
|
|
|}
|
|
|
|
|
2021-01-08 12:47:17 +00:00
|
|
|
let add =
|
|
|
|
Caqti_request.exec
|
|
|
|
t
|
|
|
|
{| INSERT INTO build
|
|
|
|
(uuid, start_d, start_ps, finish_d, finish_ps,
|
2021-06-09 11:54:24 +00:00
|
|
|
result_kind, result_code, result_msg, console, script, main_binary, user, job)
|
2021-01-08 12:47:17 +00:00
|
|
|
VALUES
|
2021-06-09 11:54:24 +00:00
|
|
|
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
2021-01-08 12:47:17 +00:00
|
|
|
|}
|
|
|
|
|
2021-02-02 08:34:21 +00:00
|
|
|
let get_by_hash =
|
|
|
|
Caqti_request.find_opt
|
|
|
|
Rep.cstruct
|
|
|
|
(Caqti_type.tup2
|
|
|
|
Caqti_type.string
|
|
|
|
t)
|
|
|
|
{| SELECT job.name,
|
|
|
|
b.uuid, b.start_d, b.start_ps, b.finish_d, b.finish_ps,
|
|
|
|
b.result_kind, b.result_code, b.result_msg,
|
2021-06-09 11:54:24 +00:00
|
|
|
b.console, b.script, b.main_binary, b.user, b.job
|
2021-02-02 08:34:21 +00:00
|
|
|
FROM build_artifact a
|
|
|
|
INNER JOIN build b ON b.id = a.build
|
|
|
|
INNER JOIN job ON job.id = b.job
|
|
|
|
WHERE a.sha256 = ?
|
|
|
|
ORDER BY b.start_d DESC, b.start_ps DESC
|
|
|
|
LIMIT 1
|
|
|
|
|}
|
2021-03-08 16:01:00 +00:00
|
|
|
|
2021-06-02 10:29:08 +00:00
|
|
|
let set_main_binary =
|
|
|
|
Caqti_request.exec
|
|
|
|
(Caqti_type.tup2 id id)
|
|
|
|
"UPDATE build SET main_binary = ?2 WHERE id = ?1"
|
|
|
|
|
2021-03-08 16:01:00 +00:00
|
|
|
let remove =
|
|
|
|
Caqti_request.exec
|
|
|
|
id
|
|
|
|
"DELETE FROM build WHERE id = ?"
|
2021-01-08 12:47:17 +00:00
|
|
|
end
|
|
|
|
|
2021-01-20 21:50:35 +00:00
|
|
|
module User = struct
|
|
|
|
let migrate =
|
|
|
|
Caqti_request.exec
|
|
|
|
Caqti_type.unit
|
|
|
|
{| CREATE TABLE user (
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
|
|
username VARCHAR(255) NOT NULL UNIQUE,
|
|
|
|
password_hash BLOB NOT NULL,
|
|
|
|
password_salt BLOB NOT NULL,
|
2021-02-23 15:20:18 +00:00
|
|
|
scrypt_n INTEGER NOT NULL,
|
|
|
|
scrypt_r INTEGER NOT NULL,
|
2021-06-08 14:54:23 +00:00
|
|
|
scrypt_p INTEGER NOT NULL,
|
|
|
|
restricted BOOLEAN NOT NULL
|
2021-01-20 21:50:35 +00:00
|
|
|
)
|
|
|
|
|}
|
|
|
|
|
|
|
|
let rollback =
|
|
|
|
Caqti_request.exec
|
|
|
|
Caqti_type.unit
|
|
|
|
"DROP TABLE IF EXISTS user"
|
|
|
|
|
|
|
|
let get_user =
|
|
|
|
Caqti_request.find_opt
|
|
|
|
Caqti_type.string
|
|
|
|
(Caqti_type.tup2 id user_info)
|
2021-02-23 15:20:18 +00:00
|
|
|
{| SELECT id, username, password_hash, password_salt,
|
2021-06-08 14:54:23 +00:00
|
|
|
scrypt_n, scrypt_r, scrypt_p, restricted
|
2021-01-20 21:50:35 +00:00
|
|
|
FROM user
|
|
|
|
WHERE username = ?
|
|
|
|
|}
|
|
|
|
|
|
|
|
let get_all =
|
|
|
|
Caqti_request.collect
|
|
|
|
Caqti_type.unit
|
|
|
|
Caqti_type.string
|
|
|
|
"SELECT username FROM user"
|
|
|
|
|
|
|
|
let add =
|
|
|
|
Caqti_request.exec
|
|
|
|
user_info
|
2021-02-23 15:20:18 +00:00
|
|
|
{| INSERT INTO user (username, password_hash, password_salt,
|
2021-06-08 14:54:23 +00:00
|
|
|
scrypt_n, scrypt_r, scrypt_p, restricted)
|
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
2021-01-20 21:50:35 +00:00
|
|
|
|}
|
|
|
|
|
|
|
|
let remove =
|
|
|
|
Caqti_request.exec
|
|
|
|
id
|
|
|
|
"DELETE FROM user WHERE id = ?"
|
|
|
|
|
|
|
|
let remove_user =
|
|
|
|
Caqti_request.exec
|
|
|
|
Caqti_type.string
|
|
|
|
"DELETE FROM user WHERE username = ?"
|
|
|
|
|
|
|
|
let update_user =
|
|
|
|
Caqti_request.exec
|
|
|
|
user_info
|
|
|
|
{| UPDATE user
|
|
|
|
SET password_hash = ?2,
|
|
|
|
password_salt = ?3,
|
2021-02-23 15:20:18 +00:00
|
|
|
scrypt_n = ?4,
|
|
|
|
scrypt_r = ?5,
|
2021-06-08 14:54:23 +00:00
|
|
|
scrypt_p = ?6,
|
|
|
|
restricted = ?7
|
2021-01-20 21:50:35 +00:00
|
|
|
WHERE username = ?1
|
|
|
|
|}
|
|
|
|
end
|
|
|
|
|
2021-06-08 14:54:23 +00:00
|
|
|
module Access_list = struct
|
|
|
|
let migrate =
|
|
|
|
Caqti_request.exec
|
|
|
|
Caqti_type.unit
|
|
|
|
{| CREATE TABLE access_list (
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
|
|
user INTEGER NOT NULL,
|
|
|
|
job INTEGER NOT NULL,
|
|
|
|
|
|
|
|
FOREIGN KEY(user) REFERENCES user(id),
|
|
|
|
FOREIGN KEY(job) REFERENCES job(id),
|
|
|
|
UNIQUE(user, job)
|
|
|
|
)
|
|
|
|
|}
|
|
|
|
|
|
|
|
let rollback =
|
|
|
|
Caqti_request.exec
|
|
|
|
Caqti_type.unit
|
|
|
|
"DROP TABLE IF EXISTS access_list"
|
|
|
|
|
|
|
|
let get =
|
|
|
|
Caqti_request.find
|
|
|
|
Caqti_type.(tup2 Rep.id Rep.id)
|
|
|
|
Rep.id
|
|
|
|
"SELECT id FROM access_list WHERE user = ? AND job = ?"
|
|
|
|
|
|
|
|
let add =
|
|
|
|
Caqti_request.exec
|
|
|
|
Caqti_type.(tup2 Rep.id Rep.id)
|
|
|
|
"INSERT INTO access_list (user, job) VALUES (?, ?)"
|
|
|
|
|
|
|
|
let remove =
|
|
|
|
Caqti_request.exec
|
|
|
|
Caqti_type.(tup2 Rep.id Rep.id)
|
|
|
|
"DELETE FROM access_list WHERE user = ? AND job = ?"
|
|
|
|
|
|
|
|
let remove_all_by_username =
|
|
|
|
Caqti_request.exec
|
|
|
|
Caqti_type.string
|
|
|
|
"DELETE FROM access_list, user WHERE access_list.user = user.id AND user.username = ?"
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2021-01-08 12:47:17 +00:00
|
|
|
let migrate = [
|
|
|
|
Job.migrate;
|
|
|
|
Build.migrate;
|
|
|
|
Build_artifact.migrate;
|
2021-01-20 21:50:35 +00:00
|
|
|
User.migrate;
|
2021-06-08 14:54:23 +00:00
|
|
|
Access_list.migrate;
|
2021-02-02 09:23:54 +00:00
|
|
|
Caqti_request.exec Caqti_type.unit
|
2021-05-18 14:59:20 +00:00
|
|
|
"CREATE INDEX idx_build_job_start ON build(job, start_d DESC, start_ps DESC)";
|
2021-01-27 20:25:51 +00:00
|
|
|
set_current_version;
|
|
|
|
set_application_id;
|
2021-01-08 12:47:17 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
let rollback = [
|
2021-06-08 14:54:23 +00:00
|
|
|
Access_list.rollback;
|
2021-01-20 21:50:35 +00:00
|
|
|
User.rollback;
|
2021-01-08 12:47:17 +00:00
|
|
|
Build_artifact.rollback;
|
|
|
|
Build.rollback;
|
|
|
|
Job.rollback;
|
2021-02-02 09:23:54 +00:00
|
|
|
Caqti_request.exec Caqti_type.unit
|
2021-04-29 13:16:19 +00:00
|
|
|
"DROP INDEX IF EXISTS idx_build_job_start";
|
2021-01-27 20:25:51 +00:00
|
|
|
Caqti_request.exec Caqti_type.unit
|
|
|
|
"PRAGMA user_version = 0";
|
|
|
|
Caqti_request.exec Caqti_type.unit
|
|
|
|
"PRAGMA application_id = 0";
|
2021-01-08 12:47:17 +00:00
|
|
|
]
|