From 1d45b63516f8d3d0e993e3f12cb51e4ba9fb6f0e Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Mon, 1 Feb 2021 18:27:28 +0100 Subject: [PATCH] Fix transition from declarative non-flake to flake jobset The database has these constraints: check ((type = 0) = (nixExprInput is not null and nixExprPath is not null)), check ((type = 1) = (flake is not null)), which prevented switching to flakes in a declarative jobspec, since the nixexpr{path,input} fields were not nulled in such an update Co-Authored-By: Graham Christensen --- src/lib/Hydra/Helper/AddBuilds.pm | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lib/Hydra/Helper/AddBuilds.pm b/src/lib/Hydra/Helper/AddBuilds.pm index 80faeaa0..d928943a 100644 --- a/src/lib/Hydra/Helper/AddBuilds.pm +++ b/src/lib/Hydra/Helper/AddBuilds.pm @@ -49,6 +49,18 @@ sub updateDeclarativeJobset { $update{$key} = $declSpec->{$key}; delete $declSpec->{$key}; } + # Ensure jobset constraints are met, only have nixexpr{path,input} or + # flakes set if the type is 0 or 1 respectively. So in the update we need + # to null the field of the other type. + if (defined $update{type}) { + if ($update{type} == 0) { + $update{flake} = undef; + } elsif ($update{type} == 1) { + $update{nixexprpath} = undef; + $update{nixexprinput} = undef; + } + } + $db->txn_do(sub { my $jobset = $project->jobsets->update_or_create(\%update); $jobset->jobsetinputs->delete;