The current check happening in jobsets is incorrect. The wanted constraint is stated as follow :
The current version will not catch (i.e. it will accept) situations where you have for instance : type = 1, nixExprPath null, nixExprInput non-null, flake non-null
This commit fixes that.
I split(ted) that into two constraints, to make it more readable and easier to extend if a new type appears in the future.
The complete query could be instead : ( type = 0 AND nixExprInput IS NOT NULL AND nixExprPath IS NOT NULL AND flake IS NULL ) OR ( type = 1 AND nixExprInput IS NULL AND nixExprPath IS NULL AND flake IS NOT NULL )
(but an "OR" cannot be split, hence the other formulation)
WKZLAYIEIH2VQJGFTDZAVL2ILQWI32X5UZA7Y6YBVE7LVVS5A2TQC
BQHDSG6OTHRD3WP25GX2N46ZUFRDH4E6L7URATJWXN5TKIKAPQFAC
QUMWPGCUBMAPWLUPRSISK7PNU5LIHKHKCAZYE4XXQCJ5E4L74VSQC
N22GPKYTOLZLBGTGDATQDVZ4R5APZEAOIA7L32X4UXBH4XNI7MWAC
LLAJKVGIFUSYN24LSSJMXB742HZL7455B5MMAHUQAVBSM3AZCOFQC
CCIORPJ5SKP5EVW4FXNDS7U7MXD3ZK65XRVBWI5QBJGETMQRPZUQC
MWXDVTS3V6SLJ27SJUVN3LT34H3ZMLHPYQCDV7C6KPLHV2QTEF7QC
W4G5MZZSCK7VGSZJQKLS6XMQPFDIL7D542XWDMFMO4RZEO4FQB2QC
SS4TZXNUWXSEJC3XYHGVS3IBZ2D7GPIPELODVQOHRRGYADI2L72AC
KN3VYE5P2RJB3KZ355LA5C2T2D5S2IR3QZFE53AJIWUVMETEEYDAC
D5QIOJGPKQJIYBUCSC3MFJ3TXLPNZ2XMI37GXMFRVRFWWR2VMTFAC
check (schedulingShares > 0),
check ((type = 0) = (nixExprInput is not null and nixExprPath is not null)),
check ((type = 1) = (flake is not null)),
constraint jobsets_schedulingshares_nonzero_check check (schedulingShares > 0),
constraint jobsets_type_known_check check (type = 0 or type = 1),
-- If the type is 0, then nixExprInput and nixExprPath should be non-null and other type-specific fields should be null
-- Otherwise the check passes
constraint jobsets_legacy_paths_check check ((type = 0) = (nixExprInput is not null and nixExprPath is not null and flake is null)),
-- If the type is 1, then flake should be non-null and other type-specific fields should be null
-- Otherwise the check passes
constraint jobsets_flake_paths_check check ((type = 1) = (nixExprInput is null and nixExprPath is null and flake is not null)),
alter table Jobsets add constraint jobsets_type_known_check check (type = 0 or type = 1);
alter table Jobsets add constraint jobsets_legacy_paths_check check ((type = 0) = (nixExprInput is not null and nixExprPath is not null and flake is null));
alter table Jobsets add constraint jobsets_flake_paths_check check ((type = 1) = (nixExprInput is null and nixExprPath is null and flake is not null));
alter table Jobsets add constraint jobsets_schedulingshares_nonzero_check check (schedulingShares > 0);
alter table Jobsets drop constraint if exists jobsets_schedulingshares_check;
alter table Jobsets drop constraint if exists jobsets_check;
alter table Jobsets drop constraint if exists jobsets_check1;
alter table Jobsets drop constraint if exists jobsets_check2;