From: Ian Jackson Date: Thu, 27 Aug 2020 17:48:36 +0000 (+0100) Subject: host lifecycle: Prevent referential integrity violation X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=e4a8cf2505103d5c7a0f59948c656a0d5c52da1f;p=osstest.git host lifecycle: Prevent referential integrity violation We can't use normal constraints for either of these, sadly. We can make the constraints into a single query which says "OK". Signed-off-by: Ian Jackson --- diff --git a/Osstest/JobDB/Executive.pm b/Osstest/JobDB/Executive.pm index 3a8308e..f69ce27 100644 --- a/Osstest/JobDB/Executive.pm +++ b/Osstest/JobDB/Executive.pm @@ -553,6 +553,28 @@ END ON h.taskid = t.taskid WHERE h.hostname = ? ORDER BY h.lcseq; +END + # We simulate two foreign key constraints which can't be in the + # db schema, by checking the values we are going to insert. + # + # For "resources" we would need a foreign key constraint + # with a literal value as part of the foreign key, which is + # not supported until PostgreSQL 13. + # + # For "tasks" we only want to apply the constraint on inserts into + # "host_lifecycle" - in particular, we want to allow delet6ions + # from "tasks" to render the taskid foreign key unresolvable. + # This could be done with a trigger, but since here is the only + # place we do insertions into host_lifecycle, this seems easier. + my $constraintsq = $dbh_tests->prepare(<prepare(<{stepno}$osuffix"; } } + $constraintsq->execute($hostname, $ttaskid); + $constraintsq->fetchrow_array() or confess "$hostname ?"; + if (defined $flight) { $insertq->execute($hostname, $ttaskid, $flight, $job,