From d3baf2ca8b93e366e260b0f24fdfbbe25077e841 Mon Sep 17 00:00:00 2001 From: Geoffrey Ragot Date: Fri, 6 Feb 2026 23:40:55 +0100 Subject: [PATCH] fix: potentially orphan temporary tables --- internal/storage/bucket/migrations/11-make-stateless/up.sql | 3 ++- .../bucket/migrations/17-moves-fill-transaction-id/up.sql | 3 +++ .../bucket/migrations/18-transactions-fill-inserted-at/up.sql | 1 + .../bucket/migrations/20-accounts-volumes-fill-history/up.sql | 3 ++- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/storage/bucket/migrations/11-make-stateless/up.sql b/internal/storage/bucket/migrations/11-make-stateless/up.sql index dbd131a07..0fe49aec3 100644 --- a/internal/storage/bucket/migrations/11-make-stateless/up.sql +++ b/internal/storage/bucket/migrations/11-make-stateless/up.sql @@ -629,7 +629,8 @@ select aggregate_objects(volumes_to_jsonb(volumes_with_asset)) from get_all_account_volumes(_ledger, _account_address, _before := _before) volumes_with_asset $$ set search_path from current; -create temporary table tmp_volumes as +drop table if exists tmp_volumes; +create temporary table tmp_volumes on commit drop as select ledger, accounts_address, diff --git a/internal/storage/bucket/migrations/17-moves-fill-transaction-id/up.sql b/internal/storage/bucket/migrations/17-moves-fill-transaction-id/up.sql index 4cc07c019..b5c6f5fad 100644 --- a/internal/storage/bucket/migrations/17-moves-fill-transaction-id/up.sql +++ b/internal/storage/bucket/migrations/17-moves-fill-transaction-id/up.sql @@ -5,6 +5,7 @@ do $$ begin set search_path = '{{.Schema}}'; + drop table if exists transactions_ids; create temporary table transactions_ids as select row_number() over (order by transactions.seq) as row_number, moves.seq as moves_seq, transactions.id, transactions.seq as transactions_seq @@ -37,6 +38,8 @@ do $$ perform pg_notify('migrations-{{ .Schema }}', 'continue: ' || _batch_size); end loop; + + drop table transactions_ids; end $$ language plpgsql; \ No newline at end of file diff --git a/internal/storage/bucket/migrations/18-transactions-fill-inserted-at/up.sql b/internal/storage/bucket/migrations/18-transactions-fill-inserted-at/up.sql index 44fe01505..65068f169 100644 --- a/internal/storage/bucket/migrations/18-transactions-fill-inserted-at/up.sql +++ b/internal/storage/bucket/migrations/18-transactions-fill-inserted-at/up.sql @@ -18,6 +18,7 @@ do $$ execute _vsql; end loop; + drop table if exists logs_transactions; create temporary table logs_transactions as select row_number() over (order by ledger, id) as row_number, ledger, date, (data->'transaction'->>'id')::bigint as transaction_id from logs diff --git a/internal/storage/bucket/migrations/20-accounts-volumes-fill-history/up.sql b/internal/storage/bucket/migrations/20-accounts-volumes-fill-history/up.sql index 6817d885e..dd7c12dd4 100644 --- a/internal/storage/bucket/migrations/20-accounts-volumes-fill-history/up.sql +++ b/internal/storage/bucket/migrations/20-accounts-volumes-fill-history/up.sql @@ -5,7 +5,8 @@ do $$ begin set search_path = '{{.Schema}}'; - create temporary table tmp_volumes as + drop table if exists tmp_volumes; + create temporary table tmp_volumes on commit drop as select distinct on (ledger, accounts_address, asset) ledger, accounts_address,