Skip to content

Commit

Permalink
fix: use msg.data @type instead of msg_event.type in all_ecocredit_tx…
Browse files Browse the repository at this point in the history
…es pg fn
  • Loading branch information
blushi committed Nov 7, 2023
1 parent 1c79fef commit b926857
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
18 changes: 18 additions & 0 deletions migrations/committed/000001.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--! Previous: -
--! Hash: sha1:5ad90bce5c5fb68d0a8f886b6c07fb280ccd2c42

CREATE INDEX IF NOT EXISTS msg_data_type_idx ON msg USING BTREE ((DATA -> '@type'));

DROP FUNCTION IF EXISTS all_ecocredit_txes;

CREATE FUNCTION public.all_ecocredit_txes() RETURNS SETOF public.tx
LANGUAGE sql STABLE
AS $$
select tx.*
from tx
inner join msg using (chain_num, block_height, tx_idx)
where
tx.data ->'tx_response'->'code' = '0' and
msg.data->>'@type' like '/regen.ecocredit.%'
order by tx.block_height desc
$$;
27 changes: 21 additions & 6 deletions migrations/schema_snapshot.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
-- PostgreSQL database dump
--

-- Dumped from database version 14.9 (Homebrew)
-- Dumped by pg_dump version 14.9 (Homebrew)
-- Dumped from database version 14.9 (Debian 14.9-1.pgdg110+1)
-- Dumped by pg_dump version 15.4

SET statement_timeout = 0;
SET lock_timeout = 0;
Expand All @@ -23,6 +23,13 @@ SET row_security = off;
CREATE SCHEMA graphile_migrate;


--
-- Name: public; Type: SCHEMA; Schema: -; Owner: -
--

-- *not* creating schema, since initdb creates it


--
-- Name: pg_stat_statements; Type: EXTENSION; Schema: -; Owner: -
--
Expand Down Expand Up @@ -77,10 +84,10 @@ CREATE FUNCTION public.all_ecocredit_txes() RETURNS SETOF public.tx
AS $$
select tx.*
from tx
natural join msg_event as me
inner join msg using (chain_num, block_height, tx_idx)
where
data ->'tx_response'->'code' = '0'
and me.type like 'regen.ecocredit.%'
tx.data ->'tx_response'->'code' = '0' and
msg.data->>'@type' like '/regen.ecocredit.%'
order by tx.block_height desc
$$;

Expand Down Expand Up @@ -571,6 +578,13 @@ CREATE INDEX class_issuers_latest_idx ON public.class_issuers USING btree (lates
CREATE INDEX flyway_schema_history_s_idx ON public.flyway_schema_history USING btree (success);


--
-- Name: msg_data_type_idx; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX msg_data_type_idx ON public.msg USING btree (((data -> '@type'::text)));


--
-- Name: msg_event_attr_type_idx; Type: INDEX; Schema: public; Owner: -
--
Expand Down Expand Up @@ -711,7 +725,8 @@ ALTER TABLE ONLY public.votes
-- Name: SCHEMA public; Type: ACL; Schema: -; Owner: -
--

REVOKE ALL ON SCHEMA public FROM PUBLIC;
REVOKE ALL ON SCHEMA public FROM postgres;
REVOKE USAGE ON SCHEMA public FROM PUBLIC;


--
Expand Down

0 comments on commit b926857

Please sign in to comment.