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;
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: z3950_index_ field_map (label, metabib_field, z3950_attr) VALUES ('Title2', 5, 5); -- Sucess, z3950_attr_type is null, z3950_attr defined 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 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
Pre-patch:
INSERT INTO config.
INSERT INTO config.
INSERT INTO config.
Post-patch: 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. 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 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;
INSERT INTO config.
INSERT INTO config.
INSERT INTO config.