Change name of table as we'll use it for other views too.

This commit is contained in:
Bradley M. Kuhn 2022-06-22 10:15:37 -07:00
parent e7bdf7db27
commit fe0cda3232

View file

@ -140,18 +140,20 @@ CREATE UNIQUE INDEX donor_postal_address_mapping_single_prefferred_per_donor
-- Note: CREATE TEMP TABLE doesn't work in BEGIN/END block of a CREATE TRIGGER, and as such, we have to create -- Note: CREATE TEMP TABLE doesn't work in BEGIN/END block of a CREATE TRIGGER, and as such, we have to create
-- all the temp tables as real tables. -- all the temp tables as real tables.
DROP TABLE IF EXISTS "_temp_size_val_for_fix_tshirt_size_request"; -- -------------- VIEW: UserOperation_fix_tshirt_size_request ---------------------
CREATE TABLE _temp_size_val_for_fix_tshirt_size_request( DROP TABLE IF EXISTS "_temp_request_configuration_change";
CREATE TABLE _temp_request_configuration_change(
old_request_configuration_id integer, old_request_configuration_id integer,
new_request_configuration_id integer, new_request_configuration_id integer,
new_description varchar(100) NOT NULL); new_description varchar(100) NOT NULL);
DROP VIEW IF EXISTS UserOperation_fix_tshirt_size_request; DROP VIEW IF EXISTS UserOperation_fix_tshirt_size_request;
CREATE VIEW UserOperation_fix_tshirt_size_request AS CREATE VIEW UserOperation_fix_tshirt_size_request AS
SELECT donor.id as donor_id, request.id as request_id, donor.ledger_entity_id as donor_name, SELECT donor.ledger_entity_id as donor_name,
request_type.type as shirt_requested, request_configuration.description as size_requested, request_type.type as shirt_requested, request_configuration.description as size_requested,
request.date_requested as request_date, request.notes as note request.date_requested as request_date, request.notes as note, donor.id as donor_id, request.id as request_id
FROM donor, request_configuration, request, request_type FROM donor, request_configuration, request, request_type
WHERE request.id not in (select request_id from fulfillment) AND WHERE request.id not in (select request_id from fulfillment) AND
request_type.type LIKE "%shirt%" AND request_type.type LIKE "%shirt%" AND
@ -165,17 +167,17 @@ CREATE TRIGGER fix_tshirt_size_request_updater
INSTEAD OF UPDATE OF size_requested on UserOperation_fix_tshirt_size_request INSTEAD OF UPDATE OF size_requested on UserOperation_fix_tshirt_size_request
BEGIN BEGIN
DELETE FROM _temp_size_val_for_fix_tshirt_size_request; DELETE FROM _temp_request_configuration_change;
INSERT INTO _temp_size_val_for_fix_tshirt_size_request(new_description) VALUES(NEW.size_requested); INSERT INTO _temp_request_configuration_change(new_description) VALUES(NEW.size_requested);
update _temp_size_val_for_fix_tshirt_size_request set new_request_configuration_id = (select rc.id update _temp_request_configuration_change set new_request_configuration_id = (select rc.id
from request_configuration rc, request_type rt from request_configuration rc, request_type rt
where rc.description = NEW.size_requested where rc.description = NEW.size_requested
and rt.id = rc.request_type_id and rt.id = rc.request_type_id
and rt.type = OLD.shirt_requested) and rt.type = OLD.shirt_requested)
WHERE new_description = NEW.size_requested; WHERE new_description = NEW.size_requested;
UPDATE _temp_size_val_for_fix_tshirt_size_request set old_request_configuration_id = UPDATE _temp_request_configuration_change set old_request_configuration_id =
(SELECT rc.id (SELECT rc.id
FROM request_configuration rc, request_type rt FROM request_configuration rc, request_type rt
where rc.description = OLD.size_requested where rc.description = OLD.size_requested
@ -185,18 +187,18 @@ UPDATE _temp_size_val_for_fix_tshirt_size_request set old_request_configuration_
AND new_request_configuration_id IS NOT NULL; AND new_request_configuration_id IS NOT NULL;
SELECT CASE SELECT CASE
WHEN ( (SELECT new_request_configuration_id from _temp_size_val_for_fix_tshirt_size_request) IS NULL ) WHEN ( (SELECT new_request_configuration_id from _temp_request_configuration_change) IS NULL )
THEN RAISE(FAIL, "Invalid t-shirt size for this particular t-shirt style!") THEN RAISE(FAIL, "Invalid t-shirt size for this particular t-shirt style!")
END; END;
UPDATE request UPDATE request
set request_configuration_id = set request_configuration_id =
(select new_request_configuration_id from _temp_size_val_for_fix_tshirt_size_request) (select new_request_configuration_id from _temp_request_configuration_change)
where id = OLD.request_id where id = OLD.request_id
and request_configuration_id = and request_configuration_id =
(select old_request_configuration_id from _temp_size_val_for_fix_tshirt_size_request); (select old_request_configuration_id from _temp_request_configuration_change);
DELETE FROM _temp_size_val_for_fix_tshirt_size_request; DELETE FROM _temp_request_configuration_change;
END; END;