Skip to content

Instantly share code, notes, and snippets.

@SodaDev
Created February 2, 2021 22:04
Show Gist options
  • Save SodaDev/3d806764c09431a8dd8a54117e7f48a1 to your computer and use it in GitHub Desktop.
Save SodaDev/3d806764c09431a8dd8a54117e7f48a1 to your computer and use it in GitHub Desktop.
DROP TRIGGER IF EXISTS DELETED_ROUTE;
CREATE TRIGGER DELETED_ROUTE
AFTER DELETE
ON routes
FOR EACH ROW
BEGIN
CALL mysql.lambda_async(
'arn:aws:lambda:eu-west-1:XXXXXXXXXX:function:RDS-EVENTS-CONSUMER',
JSON_OBJECT(
'old', JSON_OBJECT(
'airportFrom', OLD.airportFrom,
'airportTo', OLD.airportTo,
'connectingAirport', OLD.connectingAirport,
'newRoute', OLD.newRoute is true,
'seasonalRoute', OLD.seasonalRoute is true,
'operator', OLD.operator,
'group', OLD.group,
'tags', OLD.tags,
'similarArrivalAirportCodes', OLD.similarArrivalAirportCodes,
'carrierCode', OLD.carrierCode)
)
);
end;
# Test delete
DELETE FROM flights.routes WHERE airportFrom = 'FOO' AND airportTo = 'BAR';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment