From b926857f7c797c94a28a27dd298777577868901d Mon Sep 17 00:00:00 2001 From: blushi Date: Tue, 7 Nov 2023 14:33:57 +0100 Subject: [PATCH] fix: use msg.data @type instead of msg_event.type in all_ecocredit_txes pg fn --- migrations/committed/000001.sql | 18 ++++++++++++++++++ migrations/schema_snapshot.sql | 27 +++++++++++++++++++++------ 2 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 migrations/committed/000001.sql diff --git a/migrations/committed/000001.sql b/migrations/committed/000001.sql new file mode 100644 index 0000000..02d3fb6 --- /dev/null +++ b/migrations/committed/000001.sql @@ -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 +$$; diff --git a/migrations/schema_snapshot.sql b/migrations/schema_snapshot.sql index a2f66ec..096384c 100644 --- a/migrations/schema_snapshot.sql +++ b/migrations/schema_snapshot.sql @@ -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; @@ -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: - -- @@ -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 $$; @@ -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: - -- @@ -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; --