Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ do $$

drop table if exists moves_view;

create temp table moves_view as
create table moves_view as
select transactions_seq, public.aggregate_objects(jsonb_build_object(accounts_address, volumes)) as volumes
from (
select transactions_seq::numeric, accounts_address, public.aggregate_objects(json_build_object(asset, json_build_object('input', (post_commit_volumes).inputs, 'output', (post_commit_volumes).outputs))::jsonb) as volumes
select transactions_seq, accounts_address, public.aggregate_objects(json_build_object(asset, json_build_object('input', (post_commit_volumes).inputs, 'output', (post_commit_volumes).outputs))::jsonb) as volumes
from (
SELECT DISTINCT ON (moves.transactions_seq, accounts_address, asset) moves.transactions_seq, accounts_address, asset,
first_value(post_commit_volumes) OVER (
Expand All @@ -27,6 +27,8 @@ do $$
group by transactions_seq;

create index moves_view_idx on moves_view(transactions_seq);
-- speed up hash join when updating rows later
alter table moves_view add foreign key(transactions_seq) references transactions(seq);

if (select count(*) from moves_view) = 0 then
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ do $$

drop table if exists moves_view;

create temp table moves_view as
create table moves_view as
select transactions_seq, public.aggregate_objects(jsonb_build_object(accounts_address, volumes)) as volumes
from (
select transactions_seq::numeric, accounts_address, public.aggregate_objects(json_build_object(asset, json_build_object('input', (post_commit_volumes).inputs, 'output', (post_commit_volumes).outputs))::jsonb) as volumes
select transactions_seq, accounts_address, public.aggregate_objects(json_build_object(asset, json_build_object('input', (post_commit_volumes).inputs, 'output', (post_commit_volumes).outputs))::jsonb) as volumes
from (
SELECT DISTINCT ON (moves.transactions_seq, accounts_address, asset) moves.transactions_seq, accounts_address, asset,
first_value(post_commit_volumes) OVER (
Expand All @@ -27,6 +27,8 @@ do $$
group by transactions_seq;

create index moves_view_idx on moves_view(transactions_seq);
-- speed up hash join when updating rows later
alter table moves_view add foreign key(transactions_seq) references transactions(seq);

if (select count(*) from moves_view) = 0 then
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ do $$

drop table if exists moves_view;

create temp table moves_view as
create table moves_view as
select transactions_seq, public.aggregate_objects(jsonb_build_object(accounts_address, volumes)) as volumes
from (
select transactions_seq::numeric, accounts_address, public.aggregate_objects(json_build_object(asset, json_build_object('input', (post_commit_volumes).inputs, 'output', (post_commit_volumes).outputs))::jsonb) as volumes
select transactions_seq, accounts_address, public.aggregate_objects(json_build_object(asset, json_build_object('input', (post_commit_volumes).inputs, 'output', (post_commit_volumes).outputs))::jsonb) as volumes
from (
SELECT DISTINCT ON (moves.transactions_seq, accounts_address, asset) moves.transactions_seq, accounts_address, asset,
first_value(post_commit_volumes) OVER (
Expand All @@ -27,6 +27,8 @@ do $$
group by transactions_seq;

create index moves_view_idx on moves_view(transactions_seq);
-- speed up hash join when updating rows later
alter table moves_view add foreign key(transactions_seq) references transactions(seq);

if (select count(*) from moves_view) = 0 then
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ do $$

drop table if exists txs_view;

create temp table txs_view as
create table txs_view as
select *
from transactions
where updated_at is null;

if (select count(*) from txs_view) = 0 then
return;
end if;
-- speed up hash join when updating rows later
alter table txs_view add foreign key(seq) references transactions(seq);

perform pg_notify('migrations-{{ .Schema }}', 'init: ' || (select count(*) from txs_view));

Expand All @@ -29,8 +31,7 @@ do $$
update transactions
set updated_at = transactions.inserted_at
from data
where transactions.seq = data.seq and
transactions.ledger = data.ledger;
where transactions.seq = data.seq;

exit when not found;

Expand Down
Loading