From 4e661552c3a0bebd9b584dcf72b9e949fb5582ef Mon Sep 17 00:00:00 2001 From: Clément Lassieur Date: Sun, 2 Sep 2018 09:45:48 +0200 Subject: database: Add builds only if one of their outputs is new. * Makefile.am (dist_sql_DATA): Add 'src/sql/upgrade-4.sql'. * src/cuirass/database.scm (db-add-output): New procedure. (db-add-build): Call DB-ADD-OUTPUT, rollback the transaction and return #f if DB-ADD-OUTPUT returned an empty list. * src/schema.sql (Outputs): Set 'path' as primary key, instead of 'derivation, name'. * src/sql/upgrade-4.sql: New file with SQL queries to upgrade the database. * tests/database.scm (make-dummy-build): Use the #:OUTPUTS key. Get default OUTPUTS to depend on DRV. ("db-add-build-with-fixed-output"): New test. --- src/sql/upgrade-4.sql | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/sql/upgrade-4.sql (limited to 'src/sql') diff --git a/src/sql/upgrade-4.sql b/src/sql/upgrade-4.sql new file mode 100644 index 0000000..e567f03 --- /dev/null +++ b/src/sql/upgrade-4.sql @@ -0,0 +1,18 @@ +BEGIN TRANSACTION; + +ALTER TABLE Outputs RENAME TO tmp_Outputs; + +CREATE TABLE Outputs ( + derivation TEXT NOT NULL, + name TEXT NOT NULL, + path TEXT NOT NULL PRIMARY KEY, + FOREIGN KEY (derivation) REFERENCES Builds (derivation) +); + +INSERT OR IGNORE INTO Outputs (derivation, name, path) +SELECT derivation, name, path +FROM tmp_Outputs; + +DROP TABLE tmp_Outputs; + +COMMIT; -- cgit v1.2.3