From aaec3adf9ab0892b96173d7a16710738d33ce1ca Mon Sep 17 00:00:00 2001 From: Taka Goto Date: Wed, 26 Sep 2018 11:32:24 -0500 Subject: [PATCH] update price feed trigger to return new price feed --- ...537979235_update_price_feeds_trigger.down.sql | 15 +++++++++++++++ .../1537979235_update_price_feeds_trigger.up.sql | 16 ++++++++++++++++ scripts/create_migration | 2 +- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 db/migrations/1537979235_update_price_feeds_trigger.down.sql create mode 100644 db/migrations/1537979235_update_price_feeds_trigger.up.sql diff --git a/db/migrations/1537979235_update_price_feeds_trigger.down.sql b/db/migrations/1537979235_update_price_feeds_trigger.down.sql new file mode 100644 index 00000000..952cec40 --- /dev/null +++ b/db/migrations/1537979235_update_price_feeds_trigger.down.sql @@ -0,0 +1,15 @@ +DROP TRIGGER notify_pricefeeds ON maker.price_feeds; + +CREATE OR REPLACE FUNCTION notify_pricefeed() RETURNS trigger AS $$ +BEGIN + PERFORM pg_notify( + CAST('postgraphile:price_feed' AS text), + row_to_json(NEW)::text); + RETURN NEW; +END; +$$ LANGUAGE plpgsql; + +CREATE TRIGGER notify_pricefeeds + AFTER INSERT ON maker.price_feeds + FOR EACH ROW + EXECUTE PROCEDURE notify_pricefeed(); diff --git a/db/migrations/1537979235_update_price_feeds_trigger.up.sql b/db/migrations/1537979235_update_price_feeds_trigger.up.sql new file mode 100644 index 00000000..989ef859 --- /dev/null +++ b/db/migrations/1537979235_update_price_feeds_trigger.up.sql @@ -0,0 +1,16 @@ +DROP TRIGGER notify_pricefeeds ON maker.price_feeds; + +CREATE OR REPLACE FUNCTION notify_pricefeed() RETURNS trigger AS $$ +BEGIN + PERFORM pg_notify( + CAST('postgraphile:price_feed' AS text), + json_build_object('__node__', json_build_array('price_feeds', NEW.id))::text + ); + RETURN NEW; +END; +$$ LANGUAGE plpgsql; + +CREATE TRIGGER notify_pricefeeds + AFTER INSERT ON maker.price_feeds + FOR EACH ROW + EXECUTE PROCEDURE notify_pricefeed(); diff --git a/scripts/create_migration b/scripts/create_migration index 23148ff6..82be868e 100755 --- a/scripts/create_migration +++ b/scripts/create_migration @@ -2,7 +2,7 @@ if [ $# -eq 1 ] then - migrate create -dir ./db/migrations -ext sql $1 + $GOBIN/migrate create -dir ./db/migrations -ext sql $1 else echo "**An Error Occurred**" echo "Usage: ./scripts/create_migration "