Comment 4 for bug 1506534

Revision history for this message
Jason Boyer (jboyer) wrote :

I found some spare tuits on the shelf while a database rebuilds and have a branch to test here:

http://git.evergreen-ils.org/?p=working/Evergreen.git;a=shortlog;h=refs/heads/user/jboyer/lp1506534_z3950_attr_check

It removes the check, replaces the existing function with a trigger function, and applies a constraint trigger to the table so it can be deferred. It worked as expected for me and a simple test method is described below. I didn't know if this warranted a pgtap test since it's so basic (Could be used as an example of the simplest possible constraint trigger impl). I can work on a simple test, but I wanted to get this out there in case anyone wanted to throw some manual testing at it.

Testing:
Pre-patch:
INSERT INTO config.z3950_index_field_map (label, metabib_field, z3950_attr) VALUES ('Title2', 5, 5); -- Sucess, z3950_attr_type is null, z3950_attr defined
INSERT INTO config.z3950_index_field_map (label, metabib_field, z3950_attr_type) VALUES ('Title3', 5, 'title'); -- Success, z3950_attr_type exists in config.z3950_attr seed data
INSERT INTO config.z3950_index_field_map (label, metabib_field, z3950_attr_type) VALUES ('Title4', 5, 'sadface'); -- Failure! z3950_attr_type does not exist in config.z3950_attr seed data

Post-patch:
INSERT INTO config.z3950_index_field_map (label, metabib_field, z3950_attr) VALUES ('Title2', 5, 5); -- Sucess, z3950_attr_type is null, z3950_attr defined, trigger isn't called in this case.
INSERT INTO config.z3950_index_field_map (label, metabib_field, z3950_attr_type) VALUES ('Title3', 5, 'title'); -- Success, z3950_attr_type exists in config.z3950_attr seed data
INSERT INTO config.z3950_index_field_map (label, metabib_field, z3950_attr_type) VALUES ('Title4', 5, 'sadface'); -- Failure! z3950_attr_type does not exist in config.z3950_attr seed data. If in a transaction, does not fail until COMMIT;