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, diff --git a/internal/storage/bucket/migrations/45-add-replica-identity/notes.yaml b/internal/storage/bucket/migrations/45-add-replica-identity/notes.yaml new file mode 100644 index 000000000..7d04705dd --- /dev/null +++ b/internal/storage/bucket/migrations/45-add-replica-identity/notes.yaml @@ -0,0 +1 @@ +name: Add replica identity on tables without primary key \ No newline at end of file diff --git a/internal/storage/bucket/migrations/45-add-replica-identity/up.sql b/internal/storage/bucket/migrations/45-add-replica-identity/up.sql new file mode 100644 index 000000000..c2ed2a963 --- /dev/null +++ b/internal/storage/bucket/migrations/45-add-replica-identity/up.sql @@ -0,0 +1,20 @@ +do $$ + declare + ledger record; + vsql varchar; + begin + set search_path = '{{ .Schema }}'; + + for ledger in select * from _system.ledgers where bucket = current_schema loop + vsql = 'ALTER TABLE transactions REPLICA IDENTITY USING INDEX transactions_ledger'; + execute vsql; + + vsql = 'ALTER TABLE accounts REPLICA IDENTITY USING INDEX accounts_ledger'; + execute vsql; + + vsql = 'ALTER TABLE logs REPLICA IDENTITY USING INDEX logs_ledger'; + execute vsql; + end loop; + end +$$; +