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 c87d6ec9a..440a588e9 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 @@ -1,12 +1,21 @@ do $$ declare + _ledger record; + _vsql text; _batch_size integer := 1000; _date timestamp without time zone; _count integer := 0; begin - --todo: take explicit advisory lock to avoid concurrent migrations when the service is killed set search_path = '{{.Schema}}'; + -- cannot disable triggers at session level on Azure Postgres with no superuser privileges. + -- so we modify the trigger acting on transaction update to be triggered only if the metadata column is updated. + -- by the way, it's a good move to not trigger the update_transaction_metadata_history function on every update if not necessary. + for _ledger in select * from _system.ledgers where bucket = current_schema loop + _vsql = 'create or replace trigger "update_transaction_metadata_history_' || _ledger.id || '" after update of metadata on "transactions" for each row when (new.ledger = ''' || _ledger.name || ''') execute procedure update_transaction_metadata_history()'; + execute _vsql; + end loop; + -- select the date where the "11-make-stateless" migration has been applied select tstamp into _date from _system.goose_db_version @@ -25,9 +34,6 @@ do $$ perform pg_notify('migrations-{{ .Schema }}', 'init: ' || _count); for i in 0.._count-1 by _batch_size loop - -- disable triggers - set session_replication_role = replica; - with _rows as ( select * from logs_transactions @@ -40,9 +46,6 @@ do $$ from _rows where transactions.ledger = _rows.ledger and transactions.id = _rows.transaction_id; - -- enable triggers - set session_replication_role = default; - commit; perform pg_notify('migrations-{{ .Schema }}', 'continue: ' || _batch_size); 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 0c2d9d944..126ec836d 100644 --- a/internal/storage/bucket/migrations/19-transactions-fill-pcv/up.sql +++ b/internal/storage/bucket/migrations/19-transactions-fill-pcv/up.sql @@ -30,9 +30,6 @@ do $$ perform pg_notify('migrations-{{ .Schema }}', 'init: ' || (select count(*) from moves_view)); - -- disable triggers - set session_replication_role = replica; - loop with data as ( select transactions_id, volumes @@ -54,9 +51,6 @@ do $$ commit; end loop; - -- enable triggers - set session_replication_role = default; - drop table if exists moves_view; alter table transactions