The fix for bug
1513554 included creating a general trigger function to prevent
the deletion of reserved table rows with an ID lower than a specified threshold.
Testing for that seemed to pass muster, but using the function in practice revealed
a failure to delete deletable rows either.
This adds an explicit RETURN to the function, which fixes the issue.
Signed-off-by: Chris Sharp <csharp@georgialibraries.org>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
IF OLD.id < TG_ARGV[0]::INT THEN
RAISE EXCEPTION 'Cannot delete row with reserved ID %', OLD.id;
END IF;
+RETURN OLD;
END
$protect_reserved$
LANGUAGE plpgsql;
BEGIN;
-SELECT plan(1);
+SELECT plan(3);
SELECT throws_ok(
'delete from acq.cancel_reason where id = 1',
'Cannot delete row with reserved ID 1'
);
+SELECT lives_ok(
+ 'insert into acq.cancel_reason (id, org_unit, label, description) values (3001, 1, ''Test Reason'', ''Test Cancel Reason'')',
+ 'Creating test cancel reason'
+);
+
+SELECT lives_ok(
+ 'delete from acq.cancel_reason where id = 3001',
+ 'Testing delete of non-reserved cancel reason'
+);
+
SELECT * FROM finish();
ROLLBACK;
--- /dev/null
+BEGIN;
+
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+CREATE OR REPLACE FUNCTION evergreen.protect_reserved_rows_from_delete() RETURNS trigger AS $protect_reserved$
+BEGIN
+IF OLD.id < TG_ARGV[0]::INT THEN
+ RAISE EXCEPTION 'Cannot delete row with reserved ID %', OLD.id;
+END IF;
+RETURN OLD;
+END
+$protect_reserved$
+LANGUAGE plpgsql;
+
+COMMIT;