diff --git a/src/sql/hydra.sql b/src/sql/hydra.sql index ec6177dc..f2885e73 100644 --- a/src/sql/hydra.sql +++ b/src/sql/hydra.sql @@ -183,6 +183,9 @@ create table Builds ( keep integer not null default 0, -- true means never garbage-collect the build output + check (finished = 0 or (stoptime is not null and stoptime != 0)), + check (finished = 0 or (starttime is not null and starttime != 0)), + foreign key (project) references Projects(name) on update cascade, foreign key (project, jobset) references Jobsets(project, name) on update cascade, foreign key (project, jobset, job) references Jobs(project, jobset, name) on update cascade diff --git a/src/sql/upgrade-15.sql b/src/sql/upgrade-15.sql new file mode 100644 index 00000000..89321fee --- /dev/null +++ b/src/sql/upgrade-15.sql @@ -0,0 +1,10 @@ +-- Previously we didn't always set stoptime. For those builds, set +-- stoptime to timestamp, since back then timestamp was the time the +-- build finished (for finished builds). +update builds set stoptime = timestamp where finished = 1 and (stoptime is null or stoptime = 0); + +-- Idem for starttime. +update builds set starttime = timestamp where finished = 1 and (starttime is null or starttime = 0); + +alter table builds add check (finished = 0 or (stoptime is not null and stoptime != 0)); +alter table builds add check (finished = 0 or (starttime is not null and starttime != 0));