Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Commit

Permalink
add price feed trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
TakaGoto committed Sep 12, 2018
1 parent 0b987b3 commit 13b19c0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TRIGGER notify_pricefeeds ON maker.price_feeds;
13 changes: 13 additions & 0 deletions db/migrations/20180911215603_add_price_feed_trigger.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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();
23 changes: 23 additions & 0 deletions db/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';


--
-- Name: notify_pricefeed(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION public.notify_pricefeed() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
PERFORM pg_notify(
CAST('postgraphile:price_feed' AS text),
row_to_json(NEW)::text);
RETURN NEW;
END;
$$;


SET default_tablespace = '';

SET default_with_oids = false;
Expand Down Expand Up @@ -850,6 +866,13 @@ CREATE INDEX tx_from_index ON public.transactions USING btree (tx_from);
CREATE INDEX tx_to_index ON public.transactions USING btree (tx_to);


--
-- Name: price_feeds notify_pricefeeds; Type: TRIGGER; Schema: maker; Owner: -
--

CREATE TRIGGER notify_pricefeeds AFTER INSERT ON maker.price_feeds FOR EACH ROW EXECUTE PROCEDURE public.notify_pricefeed();


--
-- Name: flip_kick flip_kick_header_id_fkey; Type: FK CONSTRAINT; Schema: maker; Owner: -
--
Expand Down

0 comments on commit 13b19c0

Please sign in to comment.