guix-cuirass/src/schema.sql

136 lines
4.4 KiB
MySQL
Raw Normal View History

BEGIN TRANSACTION;
2021-01-05 10:20:34 +01:00
CREATE TABLE SchemaVersion (
version INTEGER NOT NULL
);
CREATE TABLE Specifications (
Add support for multiple inputs. * Makefile.am (dist_sql_DATA): Add src/sql/upgrade-1.sql. * bin/cuirass.in (show-help, %options, main): Remove the LOAD-PATH option that was used afterwards as %GUIX-PACKAGE-PATH. * bin/evaluate.in (absolutize, input-checkout, spec-source, spec-load-path, spec-package-path, format-checkouts): New procedures. (%not-colon): Remove variable. (main): Take the load path, package path and PROC from the checkouts that result from the inputs. Format the checkouts before sending them to the procedure. Remove the LOAD-PATH argument. * doc/cuirass.texi (Overview, Database schema): Document the changes. * examples/{guix-jobs.scm, hello-git.scm, hello-singleton.scm, hello-subset.scm, random.scm}: Adapt to the new specification format. * examples/guix-track-git.scm (package->spec): Rename to PACKAGE->INPUT. (package->git-tracked): Replace FETCH-REPOSITORY with FETCH-INPUT and handle the new format of its return value. * examples/random-jobs.scm (make-random-jobs): Rename RANDOM to CHECKOUT. Rename the checkout from 'random (which is a specification) to 'cuirass (which is a checkout resulting from an input). * src/cuirass/base.scm (fetch-repository): Rename to fetch-input. Rename SPEC to INPUT. Return a checkout object instead of returning two values. (evaluate): Take a list of CHECKOUTS and COMMITS as arguments, instead of SOURCE. Remove TOKENIZE and LOAD-PATH. Pass the CHECKOUTS instead of the SOURCE to "evaluate". Remove %GUIX-PACKAGE-PATH. Build the EVAL object instead of getting it from "evaluate". (compile?, fetch-inputs, compile-checkouts): New procedures. (process-specs): Fetch all inputs instead of only fetching one repository. The result of that fetching operation is a list of CHECKOUTS whose COMMITS are used as a STAMP. (%guix-package-path, set-guix-package-path): Remove them. * src/cuirass/database.scm (db-add-input, db-get-inputs): New procedures. (db-add-specification, db-get-specifications): Adapt to the new specification format. Add/get all inputs as well. (db-add-evaluation): Rename REVISION to COMMITS. Store COMMITS as space separated commit hashes. (db-get-builds): Rename REPO_NAME to NAME. (db-get-stamp): Rename COMMIT to STAMP. Return #f when there is no STAMP. (db-add-stamp): Rename COMMIT to STAMP. Deal with DB-GET-STAMP's new return value. (db-get-evaluations): Rename REVISION to COMMITS. Tokenize COMMITS. * src/cuirass/utils.scm (%non-blocking): Export it. * src/schema.sql (Inputs): New table that refers to the Specifications table. (Specifications): Move input related fields to the Inputs table. Rename REPO_NAME to NAME. Rename ARGUMENTS to PROC_ARGS. Rename FILE to PROC_FILE. Add LOAD_PATH_INPUTS, PACKAGE_PATH_INPUTS and PROC_INPUT fields that refer to the Inputs table. (Stamps): Rename REPO_NAME to NAME. (Evaluations): Rename REPO_NAME to NAME. Rename REVISION to COMMITS. (Specifications_index): Replace with Inputs_index. * src/sql/upgrade-1.sql: New file. * tests/database.scm (example-spec, make-dummy-eval, sqlite-exec): Adapt to the new specifications format. Rename REVISION to COMMITS. * tests/http.scm (evaluations-query-result, fill-db): Idem.
2018-06-26 11:18:23 +02:00
name TEXT NOT NULL PRIMARY KEY,
2021-03-03 15:25:04 +01:00
build TEXT NOT NULL,
channels TEXT NOT NULL,
build_outputs TEXT NOT NULL,
notifications TEXT NOT NULL,
period INTEGER NOT NULL DEFAULT 0,
priority INTEGER NOT NULL DEFAULT 0,
2021-03-03 15:25:04 +01:00
systems TEXT NOT NULL
2016-07-26 00:36:12 +02:00
);
CREATE TABLE Evaluations (
2021-01-05 10:20:34 +01:00
id SERIAL PRIMARY KEY,
specification TEXT NOT NULL,
status INTEGER NOT NULL,
timestamp INTEGER NOT NULL,
checkouttime INTEGER NOT NULL,
evaltime INTEGER NOT NULL,
FOREIGN KEY (specification) REFERENCES Specifications(name) ON DELETE CASCADE
2016-07-16 18:16:39 +02:00
);
2021-01-05 10:20:34 +01:00
CREATE TABLE Checkouts (
specification TEXT NOT NULL,
revision TEXT NOT NULL,
evaluation INTEGER NOT NULL,
2021-03-03 15:25:04 +01:00
channel TEXT NOT NULL,
2021-01-05 10:20:34 +01:00
directory TEXT NOT NULL,
timestamp INTEGER NOT NULL,
PRIMARY KEY (specification, revision),
FOREIGN KEY (evaluation) REFERENCES Evaluations(id) ON DELETE CASCADE,
FOREIGN KEY (specification) REFERENCES Specifications(name) ON DELETE CASCADE
);
CREATE TABLE Builds (
2021-01-05 10:20:34 +01:00
id SERIAL PRIMARY KEY,
derivation TEXT NOT NULL UNIQUE,
evaluation INTEGER NOT NULL,
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.
2018-08-01 00:03:12 +02:00
job_name TEXT NOT NULL,
system TEXT NOT NULL,
worker TEXT, --optional, worker performing the build.
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.
2018-08-01 00:03:12 +02:00
nix_name TEXT NOT NULL,
log TEXT NOT NULL,
status INTEGER NOT NULL,
last_status INTEGER,
weather INTEGER,
priority INTEGER NOT NULL DEFAULT 0,
max_silent INTEGER NOT NULL DEFAULT 0,
timeout INTEGER NOT NULL DEFAULT 0,
timestamp INTEGER NOT NULL,
starttime INTEGER NOT NULL,
stoptime INTEGER NOT NULL,
FOREIGN KEY (evaluation) REFERENCES Evaluations(id) ON DELETE CASCADE
2021-01-05 10:20:34 +01:00
);
CREATE TABLE Jobs (
name TEXT NOT NULL,
evaluation INTEGER NOT NULL,
build INTEGER NOT NULL,
2021-04-14 15:05:00 +02:00
status INTEGER NOT NULL, --caches Builds.status
system TEXT NOT NULL, --caches Builds.system
PRIMARY KEY (evaluation, build),
FOREIGN KEY (build) REFERENCES Builds(id) ON DELETE CASCADE,
FOREIGN KEY (evaluation) REFERENCES Evaluations(id) ON DELETE CASCADE
);
2021-01-05 10:20:34 +01:00
CREATE TABLE Outputs (
derivation TEXT NOT NULL,
name TEXT NOT NULL,
path TEXT NOT NULL PRIMARY KEY,
FOREIGN KEY (derivation) REFERENCES Builds(derivation) ON DELETE CASCADE
2016-07-16 18:16:39 +02:00
);
CREATE TABLE Metrics (
2021-01-05 10:20:34 +01:00
id SERIAL,
field TEXT NOT NULL,
type INTEGER NOT NULL,
value DOUBLE PRECISION NOT NULL,
timestamp INTEGER NOT NULL,
PRIMARY KEY (field, type)
);
CREATE TABLE BuildProducts (
2021-01-05 10:20:34 +01:00
id SERIAL,
build INTEGER NOT NULL,
type TEXT NOT NULL,
file_size BIGINT NOT NULL,
checksum TEXT NOT NULL,
path TEXT NOT NULL,
2021-01-05 10:20:34 +01:00
PRIMARY KEY (build, path),
FOREIGN KEY (build) REFERENCES Builds(id) ON DELETE CASCADE
);
CREATE TABLE Notifications (
2021-01-05 10:20:34 +01:00
id SERIAL PRIMARY KEY,
type TEXT NOT NULL,
build INTEGER NOT NULL,
FOREIGN KEY (build) REFERENCES Builds(id) ON DELETE CASCADE
);
CREATE TABLE Workers (
name TEXT NOT NULL PRIMARY KEY,
address TEXT NOT NULL,
machine TEXT NOT NULL,
systems TEXT NOT NULL,
last_seen INTEGER NOT NULL
);
-- XXX: All queries targeting Builds and Outputs tables *must* be covered by
-- an index. It is also preferable for the other tables.
CREATE INDEX Builds_status_index ON Builds (status);
CREATE INDEX Builds_evaluation_index ON Builds (evaluation, status);
CREATE INDEX Builds_job_name_timestamp on Builds(job_name, timestamp);
2021-01-05 10:20:34 +01:00
CREATE INDEX Builds_nix_name ON Builds (nix_name);
CREATE INDEX Builds_timestamp_stoptime on Builds(timestamp, stoptime);
CREATE INDEX Builds_stoptime on Builds(stoptime DESC);
CREATE INDEX Builds_stoptime_id on Builds(stoptime DESC, id DESC);
CREATE INDEX Builds_status_ts_id on Builds(status DESC, timestamp DESC, id ASC);
2021-01-05 10:20:34 +01:00
CREATE INDEX Builds_priority_timestamp on Builds(priority ASC, timestamp DESC);
CREATE INDEX Builds_weather_evaluation ON Builds (weather, evaluation);
CREATE INDEX Jobs_name ON Jobs (name);
2021-04-14 15:05:00 +02:00
CREATE INDEX Jobs_system_status ON Jobs (system, status);
CREATE INDEX Evaluations_status_index ON Evaluations (id, status);
CREATE INDEX Evaluations_specification_index ON Evaluations (specification, id DESC);
CREATE INDEX Outputs_derivation_index ON Outputs (derivation);
COMMIT;