update_postal_address_is_invalid — trigger: postal_address(invalid)

This commit is contained in:
Bradley M. Kuhn 2022-11-10 19:38:18 -08:00
parent 549df60002
commit 07f0b6aad6

View file

@ -145,7 +145,7 @@ CREATE UNIQUE INDEX donor_postal_address_mapping_single_prefferred_per_donor
DROP VIEW IF EXISTS UserOperation_postal_address_change; DROP VIEW IF EXISTS UserOperation_postal_address_change;
CREATE VIEW UserOperation_postal_address_change AS CREATE VIEW UserOperation_postal_address_change AS
SELECT ledger_entity_id as donor_name, map.preferred as preferred_override, pa.date_encountered as entered_date, SELECT ledger_entity_id as donor_name, map.preferred as preferred_override, pa.date_encountered as entered_date,
pa.formatted_address as formatted_postal_address, pa.id as address_id, dd.id as donor_id pa.formatted_address as formatted_postal_address, pa.id as address_id, dd.id as donor_id, pa.invalid as is_invalid
FROM donor dd, donor_postal_address_mapping map, postal_address pa FROM donor dd, donor_postal_address_mapping map, postal_address pa
WHERE dd.id = map.donor_id AND pa.id = map.postal_address_id WHERE dd.id = map.donor_id AND pa.id = map.postal_address_id
AND map.preferred is NOT NULL AND map.preferred is NOT NULL
@ -153,7 +153,7 @@ CREATE VIEW UserOperation_postal_address_change AS
UNION UNION
SELECT ledger_entity_id as donor_name, map.preferred as preferred_override, pa.date_encountered as entered_date, SELECT ledger_entity_id as donor_name, map.preferred as preferred_override, pa.date_encountered as entered_date,
pa.formatted_address as formatted_postal_address, pa.id as address_id, dd.id as donor_id pa.formatted_address as formatted_postal_address, pa.id as address_id, dd.id as donor_id, pa.invalid as is_invalid
FROM donor dd, donor_postal_address_mapping map, postal_address pa FROM donor dd, donor_postal_address_mapping map, postal_address pa
WHERE dd.id = map.donor_id AND pa.id = map.postal_address_id WHERE dd.id = map.donor_id AND pa.id = map.postal_address_id
AND map.preferred is NULL AND map.preferred is NULL
@ -179,6 +179,23 @@ SELECT CASE
END; END;
DROP TRIGGER IF EXISTS update_postal_address_is_invalid;
CREATE TRIGGER update_postal_address_is_invalid
INSTEAD OF UPDATE OF is_invalid on UserOperation_postal_address_change
BEGIN
UPDATE postal_address SET invalid = NEW.is_invalid
WHERE id = OLD.address_id;
SELECT CASE
WHEN ( (SELECT invalid FROM postal_address
WHERE id = OLD.address_id)
!= NEW.is_invalid )
THEN RAISE(FAIL, "Error encountered while updating invalid setting; please verify your changes worked!")
END;
END;
DROP TRIGGER IF EXISTS update_formatted_postal_address; DROP TRIGGER IF EXISTS update_formatted_postal_address;
CREATE TRIGGER update_formatted_postal_address CREATE TRIGGER update_formatted_postal_address