Skip to content

Commit 7f6dae9

Browse files
authored
fix: potentially orphan temporary tables (#1256)
1 parent 526163a commit 7f6dae9

File tree

4 files changed

+8
-2
lines changed
  • internal/storage/bucket/migrations
    • 11-make-stateless
    • 17-moves-fill-transaction-id
    • 18-transactions-fill-inserted-at
    • 20-accounts-volumes-fill-history

4 files changed

+8
-2
lines changed

internal/storage/bucket/migrations/11-make-stateless/up.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,8 @@ select aggregate_objects(volumes_to_jsonb(volumes_with_asset))
629629
from get_all_account_volumes(_ledger, _account_address, _before := _before) volumes_with_asset
630630
$$ set search_path from current;
631631

632-
create temporary table tmp_volumes as
632+
drop table if exists tmp_volumes;
633+
create temporary table tmp_volumes on commit drop as
633634
select
634635
ledger,
635636
accounts_address,

internal/storage/bucket/migrations/17-moves-fill-transaction-id/up.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ do $$
55
begin
66
set search_path = '{{.Schema}}';
77

8+
drop table if exists transactions_ids;
89
create temporary table transactions_ids as
910
select row_number() over (order by transactions.seq) as row_number,
1011
moves.seq as moves_seq, transactions.id, transactions.seq as transactions_seq
@@ -37,6 +38,8 @@ do $$
3738

3839
perform pg_notify('migrations-{{ .Schema }}', 'continue: ' || _batch_size);
3940
end loop;
41+
42+
drop table transactions_ids;
4043
end
4144
$$
4245
language plpgsql;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ do $$
1818
execute _vsql;
1919
end loop;
2020

21+
drop table if exists logs_transactions;
2122
create temporary table logs_transactions as
2223
select row_number() over (order by ledger, id) as row_number, ledger, date, (data->'transaction'->>'id')::bigint as transaction_id
2324
from logs

internal/storage/bucket/migrations/20-accounts-volumes-fill-history/up.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ do $$
55
begin
66
set search_path = '{{.Schema}}';
77

8-
create temporary table tmp_volumes as
8+
drop table if exists tmp_volumes;
9+
create temporary table tmp_volumes on commit drop as
910
select distinct on (ledger, accounts_address, asset)
1011
ledger,
1112
accounts_address,

0 commit comments

Comments
 (0)