From d493a58823aed8c556bf795d02207e57718b96c9 Mon Sep 17 00:00:00 2001 From: Mathieu Lirzin Date: Tue, 26 Jul 2016 16:53:57 +0200 Subject: schema: Separate "Derivations" from "Evaluations". * src/schema.sql (Derivations): New table. (Evaluations): Remove 'derivation' and 'job_name' columns. Add 'id' column. * src/cuirass/database.scm (db-add-evaluation): Adapt. (db-get-derivation, db-add-derivation): New procedures. (evaluation-exists?, db-get-evaluation): Delete. * bin/evaluate.in (main): Adapt. * tests/database.scm ("sqlite-exec"): Likewise. ("db-add-derivation", "db-get-derivation"): New tests. ("db-add-evaluation", "db-get-evaluation"): Delete. --- src/cuirass/database.scm | 26 ++++++++++++-------------- src/schema.sql | 11 +++++++++-- 2 files changed, 21 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/cuirass/database.scm b/src/cuirass/database.scm index 13362a5..a314704 100644 --- a/src/cuirass/database.scm +++ b/src/cuirass/database.scm @@ -31,9 +31,9 @@ db-get-specifications db-add-stamp db-get-stamp - evaluation-exists? db-add-evaluation - db-get-evaluation + db-add-derivation + db-get-derivation db-add-build read-sql-file read-quoted-string @@ -142,25 +142,23 @@ INSERT INTO Specifications\ (#:commit . ,(if (string=? rev "NULL") #f rev))) specs)))))) -(define (evaluation-exists? db job) - "Check if JOB is already added to DB." - (let ((primary-key (assq-ref job #:derivation))) - (not (null? (sqlite-exec db "\ -SELECT * FROM Evaluations WHERE derivation='~A';" - primary-key))))) - -(define (db-add-evaluation db job) +(define (db-add-derivation db job) "Store a derivation result in database DB and return its ID." (sqlite-exec db "\ -INSERT INTO Evaluations (derivation, job_name, specification)\ +INSERT INTO Derivations (derivation, job_name, evaluation)\ VALUES ('~A', '~A', '~A');" (assq-ref job #:derivation) (assq-ref job #:job-name) - (assq-ref job #:spec-id))) + (assq-ref job #:eval-id))) -(define (db-get-evaluation db id) +(define (db-get-derivation db id) "Retrieve a job in database DB which corresponds to ID." - (car (sqlite-exec db "SELECT * FROM Evaluations WHERE derivation='~A';" id))) + (car (sqlite-exec db "SELECT * FROM Derivations WHERE derivation='~A';" id))) + +(define (db-add-evaluation db spec-id) + (sqlite-exec db "INSERT INTO Evaluations (specification) VALUES ('~A');" + spec-id) + (last-insert-rowid db)) (define-syntax-rule (with-database db body ...) "Run BODY with a connection to the database which is bound to DB in BODY." diff --git a/src/schema.sql b/src/schema.sql index d5c1f00..248f9d2 100644 --- a/src/schema.sql +++ b/src/schema.sql @@ -21,12 +21,19 @@ CREATE TABLE Stamps ( ); CREATE TABLE Evaluations ( - derivation TEXT NOT NULL PRIMARY KEY, - job_name TEXT NOT NULL, + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, specification INTEGER NOT NULL, FOREIGN KEY (specification) REFERENCES Specifications (id) ); +CREATE TABLE Derivations ( + derivation TEXT NOT NULL, + evaluation INTEGER NOT NULL, + job_name TEXT NOT NULL, + PRIMARY KEY (derivation, evaluation), + FOREIGN KEY (evaluation) REFERENCES Evaluations (id) +); + CREATE TABLE Builds ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, derivation TEXT NOT NULL, -- cgit v1.2.3