diff --git a/db/migrations/20180911215603_add_price_feed_trigger.down.sql b/db/migrations/20180911215603_add_price_feed_trigger.down.sql new file mode 100644 index 00000000..456f014e --- /dev/null +++ b/db/migrations/20180911215603_add_price_feed_trigger.down.sql @@ -0,0 +1 @@ +DROP TRIGGER notify_pricefeeds ON maker.price_feeds; diff --git a/db/migrations/20180911215603_add_price_feed_trigger.up.sql b/db/migrations/20180911215603_add_price_feed_trigger.up.sql new file mode 100644 index 00000000..1e8f9d6c --- /dev/null +++ b/db/migrations/20180911215603_add_price_feed_trigger.up.sql @@ -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(); diff --git a/db/schema.sql b/db/schema.sql index 58a0dba5..069be85b 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -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; @@ -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: - --