Skip to content

Commit 77a64f5

Browse files
committed
fix: from reviews
1 parent 3f0c2c3 commit 77a64f5

File tree

4 files changed

+5
-66
lines changed
  • internal/storage/bucket/migrations
    • 18-transactions-fill-inserted-at
    • 27-fix-invalid-pcv
    • 32-fix-log-data-for-reverted-transactions
    • 33-fix-invalid-date-format

4 files changed

+5
-66
lines changed

internal/storage/bucket/migrations/18-transactions-fill-inserted-at/up.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ do $$
3434
with _rows as (
3535
select *
3636
from logs_transactions
37-
where row_number >= i and row_number < i + _batch_size
37+
where row_number > i and row_number <= i + _batch_size
3838
)
3939
update transactions
4040
set inserted_at = _rows.date
Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,6 @@
11
do $$
2-
declare
3-
_offset integer := 0;
4-
_batch_size integer := 1000;
52
begin
6-
set search_path = '{{ .Schema }}';
7-
8-
-- drop table if exists moves_view;
9-
--
10-
-- create table moves_view as
11-
-- select transactions_seq, public.aggregate_objects(jsonb_build_object(accounts_address, volumes)) as volumes
12-
-- from (
13-
-- 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
14-
-- from (
15-
-- SELECT DISTINCT ON (moves.transactions_seq, accounts_address, asset) moves.transactions_seq, accounts_address, asset,
16-
-- first_value(post_commit_volumes) OVER (
17-
-- PARTITION BY moves.transactions_seq, accounts_address, asset
18-
-- ORDER BY seq DESC
19-
-- ) AS post_commit_volumes
20-
-- FROM moves
21-
-- where insertion_date < (
22-
-- select tstamp from goose_db_version where version_id = 12
23-
-- )
24-
-- ) moves
25-
-- group by transactions_seq, accounts_address
26-
-- ) data
27-
-- group by transactions_seq;
28-
--
29-
-- create index moves_view_idx on moves_view(transactions_seq);
30-
-- -- speed up hash join when updating rows later
31-
-- alter table moves_view add foreign key(transactions_seq) references transactions(seq);
32-
--
33-
-- if (select count(*) from moves_view) = 0 then
34-
-- drop table moves_view;
35-
-- return;
36-
-- end if;
37-
--
38-
-- perform pg_notify('migrations-{{ .Schema }}', 'init: ' || (select count(*) from moves_view));
39-
--
40-
-- loop
41-
-- with data as (
42-
-- select transactions_seq, volumes
43-
-- from moves_view
44-
-- -- play better than offset/limit
45-
-- where transactions_seq >= _offset and transactions_seq < _offset + _batch_size
46-
-- )
47-
-- update transactions
48-
-- set post_commit_volumes = data.volumes
49-
-- from data
50-
-- where transactions.seq = data.transactions_seq;
51-
--
52-
-- if not found then
53-
-- drop table moves_view;
54-
-- exit;
55-
-- end if;
56-
--
57-
-- _offset = _offset + _batch_size;
58-
--
59-
-- perform pg_notify('migrations-{{ .Schema }}', 'continue: ' || _batch_size);
60-
--
61-
-- commit;
62-
-- end loop;
63-
--
64-
-- drop table if exists moves_view;
3+
raise notice 'Migration superseded by next migration';
654
end
665
$$;
676

internal/storage/bucket/migrations/32-fix-log-data-for-reverted-transactions/up.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ do $$
2323
reversed.revertedTransactionID = transactions.id and
2424
reversed.ledger = transactions.ledger;
2525

26-
create index txs_view_idx on txs_view(log_id, id);
26+
create index txs_view_idx on txs_view(row_number);
2727

2828
if (select count(*) from txs_view) = 0 then
2929
return;
@@ -35,7 +35,7 @@ do $$
3535
with data as (
3636
select *
3737
from txs_view
38-
where row_number >= _offset and row_number < _offset + _batch_size
38+
where row_number > _offset and row_number <= _offset + _batch_size
3939
)
4040
update logs
4141
set data = data || jsonb_build_object('revertedTransaction', jsonb_build_object(

internal/storage/bucket/migrations/33-fix-invalid-date-format/up.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ do $$
3434
with data as (
3535
select *
3636
from txs_view
37-
where row_number >= _offset and row_number < _offset + _batch_size
37+
where row_number > _offset and row_number <= _offset + _batch_size
3838
)
3939
update logs
4040
set data = data || jsonb_build_object('revertedTransaction', jsonb_build_object(

0 commit comments

Comments
 (0)