From da5b319ea8f10c6dc23b8f7c20a62772f4cb8a0d Mon Sep 17 00:00:00 2001 From: Geoffrey Ragot Date: Mon, 16 Dec 2024 15:31:47 +0100 Subject: [PATCH] fix: too many loops while running migrations --- .../migrations/18-transactions-fill-inserted-at/up.sql | 2 +- .../bucket/migrations/19-transactions-fill-pcv/up.sql | 8 ++++++-- .../migrations/20-accounts-volumes-fill-history/up.sql | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) 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 fdc93ea71..c87d6ec9a 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 @@ -24,7 +24,7 @@ do $$ perform pg_notify('migrations-{{ .Schema }}', 'init: ' || _count); - for i in 0.._count by _batch_size loop + for i in 0.._count-1 by _batch_size loop -- disable triggers set session_replication_role = replica; diff --git a/internal/storage/bucket/migrations/19-transactions-fill-pcv/up.sql b/internal/storage/bucket/migrations/19-transactions-fill-pcv/up.sql index d3cf97488..0c2d9d944 100644 --- a/internal/storage/bucket/migrations/19-transactions-fill-pcv/up.sql +++ b/internal/storage/bucket/migrations/19-transactions-fill-pcv/up.sql @@ -22,10 +22,14 @@ do $$ ) moves group by transactions_id; - perform pg_notify('migrations-{{ .Schema }}', 'init: ' || (select count(*) from moves_view)); - create index moves_view_idx on moves_view(transactions_id); + if (select count(*) from moves_view) = 0 then + return; + end if; + + perform pg_notify('migrations-{{ .Schema }}', 'init: ' || (select count(*) from moves_view)); + -- disable triggers set session_replication_role = replica; 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 56083891f..6817d885e 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 @@ -31,7 +31,7 @@ do $$ raise info '_count: %', _count; - for i in 0.._count by _batch_size loop + for i in 0.._count-1 by _batch_size loop with _rows as ( select * from tmp_volumes