diff options
author | Clément Lassieur <clement@lassieur.org> | 2018-08-01 00:03:12 +0200 |
---|---|---|
committer | Clément Lassieur <clement@lassieur.org> | 2018-08-16 19:19:23 +0200 |
commit | 4db99f647b3677086a2007763726d05a59b0cdcb (patch) | |
tree | bd98e6f8d34fa0a3e9a14f2479294cb9525ad833 /src/sql | |
parent | b4d058fc8d279a92208aa46b2f8a43e35feb5369 (diff) | |
download | cuirass-4db99f647b3677086a2007763726d05a59b0cdcb.tar cuirass-4db99f647b3677086a2007763726d05a59b0cdcb.tar.gz |
database: Merge Derivations into Builds table.
Fixes <https://bugs.gnu.org/32190>.
* Makefile.am (dist_sql_DATA): Add 'src/sql/upgrade-2.sql'.
* doc/cuirass.texi (Derivations): Remove section.
(Builds): Update accordingly. Add columns from the Derivations table.
(Outputs): Replace 'id' with 'derivation'.
* src/cuirass/base.scm (evaluate): Don't add jobs to the Derivations table.
(build-packages): Add columns that were in the Derivations table before. Only
build the derivations that were successfully registered, that is, those that
didn't exist in the Builds table. Give a derivation instead of a build id to
DB-GET-BUILD. Compute the number of failed jobs based on the derivations that
were added to the table, instead of the jobs.
* src/cuirass/database.scm (db-add-derivation, db-get-derivation): Remove
exported procedures.
(db-add-build): Catch SQLITE_CONSTRAINT_PRIMARYKEY error, which means that two
jobs produced the same derivation, and return #f in that case. Add columns
that were in the Derivations table before. Use 'derivation' as primary key
for the Outputs table.
(db-get-outputs): Use 'derivation' as identifier, instead of 'build-id'.
(filters->order): Replace 'id' with 'rowid'.
(db-get-builds): Add a 'derivation' filter. Replace 'id' with 'rowid'.
Remove the 'INNER JOIN Derivations'. Replace Derivations with Builds. Return
'derivation' in first position to make it clear that it's the primary key.
Pass DERIVATION instead of ID to DB-GET-OUTPUTS.
(db-get-build): Allow to take a derivation as argument. Use NUMBER? to
differentiate between derivations and ids.
(db-get-pending-derivations): Remove the 'SELECT DISTINCT' clause now that
derivations are unique. Remove the 'INNER JOIN Builds'.
(db-get-evaluations-build-summary, db-get-builds-min, db-get-builds-max):
Replace 'id' with 'rowid'.
* src/schema.sql (Derivations): Remove table.
(Outputs): Replace Builds.id with Builds.derivation.
(Builds): Use 'derivation' as primary key. Remove the 'id' column. Add
'job_name', 'system', 'nix_name' columns that were in the Derivations table
before.
(Builds_Derivations_index): Rename to Builds_index. Update accordingly.
(Derivations_index): Remove index.
* src/sql/upgrade-2.sql: New file with SQL queries to upgrade the database.
* tests/database.scm (make-dummy-job, make-dummy-derivation): Remove
procedures.
(make-dummy-build): Add columns that were in MAKE-DUMMY-DERIVATION. Get the
DRV parameter to be mandatory because it's a primary key.
(%id): Remove parameter.
("db-add-derivation", "db-get-derivation"): Remove tests.
("db-add-build"): Expect #f, because it adds twice the same derivation. Pass
the derivation argument to MAKE-DUMMY-BUILD.
("db-update-build-status!"): Rename 'id' to 'derivation'. Pass the derivation
argument to MAKE-DUMMY-BUILD. Remove the DB-ADD-DERIVATION call.
("db-get-builds", "db-get-pending-derivations"): Pass the derivation argument
to MAKE-DUMMY-BUILD. Remove the DB-ADD-DERIVATION calls.
* tests/http.scm ("fill-db"): Remove DERIVATION1 and DERIVATION2, and put
their content in BUILD1 and BUILD2. Remove the DB-ADD-DERIVATION calls.
Diffstat (limited to 'src/sql')
-rw-r--r-- | src/sql/upgrade-2.sql | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/sql/upgrade-2.sql b/src/sql/upgrade-2.sql new file mode 100644 index 0000000..dfb919b --- /dev/null +++ b/src/sql/upgrade-2.sql @@ -0,0 +1,49 @@ +BEGIN TRANSACTION; + +DROP INDEX Derivations_index; +DROP INDEX Builds_Derivations_index; + +ALTER TABLE Outputs RENAME TO tmp_Outputs; +ALTER TABLE Builds RENAME TO tmp_Builds; + +CREATE TABLE Builds ( + derivation TEXT NOT NULL PRIMARY KEY, + evaluation INTEGER NOT NULL, + job_name TEXT NOT NULL, + system TEXT NOT NULL, + nix_name TEXT NOT NULL, + log TEXT NOT NULL, + status INTEGER NOT NULL, + timestamp INTEGER NOT NULL, + starttime INTEGER NOT NULL, + stoptime INTEGER NOT NULL, + FOREIGN KEY (evaluation) REFERENCES Evaluations (id) +); + +CREATE TABLE Outputs ( + derivation TEXT NOT NULL, + name TEXT NOT NULL, + path TEXT NOT NULL, + PRIMARY KEY (derivation, name), + FOREIGN KEY (derivation) REFERENCES Builds (derivation) +); + +INSERT OR IGNORE INTO Builds (derivation, evaluation, job_name, system, nix_name, log, status, timestamp, starttime, stoptime) +SELECT Derivations.derivation, Derivations.evaluation, Derivations.job_name, Derivations.system, Derivations.nix_name, + tmp_Builds.log, tmp_Builds.status, tmp_Builds.timestamp, tmp_Builds.starttime, tmp_Builds.stoptime +FROM Derivations +INNER JOIN tmp_Builds ON tmp_Builds.derivation = Derivations.derivation + AND tmp_Builds.evaluation = Derivations.evaluation; + +INSERT OR IGNORE INTO Outputs (derivation, name, path) +SELECT tmp_Builds.derivation, tmp_Outputs.name, tmp_Outputs.path +FROM tmp_Outputs +INNER JOIN tmp_Builds on tmp_Builds.id = tmp_Outputs.build; + +CREATE INDEX Builds_index ON Builds(job_name, system, status ASC, timestamp ASC, derivation, evaluation, stoptime DESC); + +DROP TABLE tmp_Builds; +DROP TABLE tmp_Outputs; +DROP TABLE Derivations; + +COMMIT; |