Skip to content

Commit

Permalink
Check for termination in trigger as well
Browse files Browse the repository at this point in the history
  • Loading branch information
ngua committed Jun 6, 2024
1 parent 7c5d924 commit 3bcecee
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions nix/inferno-ml/migrations/v1-create-tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,20 @@ create table if not exists evalinfo
-- Because the `params` table references an array of model versions, and
-- because Postgres does not natively support arrays of foreign keys, this
-- trigger function checks that each array item in the `models` column is
-- a valid `mversions` primary key
-- a valid `mversions` primary key and that the model has not been terminated
create or replace function verifymvs()
returns trigger as $$
declare
mv int;
begin
foreach mv in array new.models loop
if not exists(select 1 from mversions where id = mv) then
if
not exists
( select 1 from mversions
where id = mv
and terminated is null
)
then
raise exception 'ID % is not a valid model version primary key', mv;
end if;
end loop;
Expand Down

0 comments on commit 3bcecee

Please sign in to comment.