summaryrefslogtreecommitdiff
path: root/src/schema.sql
blob: 8d3a651d5a4f31e9ada768303e31197399d6bdc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
BEGIN TRANSACTION;

CREATE TABLE Specifications (
  repo_name     TEXT NOT NULL PRIMARY KEY,
  url           TEXT NOT NULL,
  load_path     TEXT NOT NULL,
  file          TEXT NOT NULL,
  proc          TEXT NOT NULL,
  arguments     TEXT NOT NULL,
  -- The following columns are optional.
  branch        TEXT,
  tag           TEXT,
  revision      TEXT,
  no_compile_p  INTEGER
);

CREATE TABLE Stamps (
  specification TEXT NOT NULL PRIMARY KEY,
  stamp         TEXT NOT NULL,
  FOREIGN KEY (specification) REFERENCES Specifications (repo_name)
);

CREATE TABLE Evaluations (
  id            INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  specification TEXT NOT NULL,
  revision      TEXT NOT NULL,
  FOREIGN KEY (specification) REFERENCES Specifications (repo_name)
);

CREATE TABLE Derivations (
  derivation    TEXT NOT NULL,
  evaluation    INTEGER NOT NULL,
  job_name      TEXT NOT NULL,
  system        TEXT NOT NULL,
  nix_name      TEXT NOT NULL,
  PRIMARY KEY (derivation, evaluation),
  FOREIGN KEY (evaluation) REFERENCES Evaluations (id)
);

CREATE TABLE Outputs (
  build INTEGER NOT NULL,
  name TEXT NOT NULL,
  path TEXT NOT NULL,
  PRIMARY KEY (build, name),
  FOREIGN KEY (build) REFERENCES Builds (id)
);

-- Builds are not in a one to one relationship with derivations in order to
-- keep track of non deterministic compilations.
CREATE TABLE Builds (
  id            INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  derivation    TEXT NOT NULL,
  evaluation    INTEGER NOT NULL,
  log           TEXT NOT NULL,
  status        INTEGER NOT NULL,
  timestamp     INTEGER NOT NULL,
  starttime     INTEGER NOT NULL,
  stoptime      INTEGER NOT NULL,
  FOREIGN KEY (derivation) REFERENCES Derivations (derivation),
  FOREIGN KEY (evaluation) REFERENCES Evaluations (id)
);

-- Create indexes to speed up common queries, in particular those
-- corresponding to /api/latestbuilds HTTP requests.
CREATE INDEX Builds_Derivations_index ON Builds(status ASC, derivation, evaluation, stoptime DESC);
CREATE INDEX Specifications_index ON Specifications(repo_name, branch);
CREATE INDEX Derivations_index ON Derivations(derivation, evaluation, job_name, system);

COMMIT;