add replaced_transaction update script

pull/1370/head
Ayrat Badykov 6 years ago
parent 20c7a1ba21
commit d3c7c8636f
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 13
      apps/explorer/priv/repo/migrations/20190124082812_add_index_on_transaction_nonce_and_from_address_hash.exs
  2. 23
      apps/explorer/priv/repo/migrations/scripts/update_replaced_transaction.sql

@ -9,19 +9,6 @@ defmodule Explorer.Repo.Migrations.AddIndexOnTransactionNonceAndFromAddressHash
def change do def change do
create(index(:transactions, [:nonce, :from_address_hash, :block_hash])) create(index(:transactions, [:nonce, :from_address_hash, :block_hash]))
# for replaced/dropeed transactions
create(index(:transactions, [:block_hash, :error])) create(index(:transactions, [:block_hash, :error]))
query = "UPDATE transactions SET error = 'dropped/replaced', status = 0 FROM transactions t1
INNER JOIN transactions t2
ON t1.from_address_hash = t2.from_address_hash AND t1.nonce = t2.nonce
WHERE t1.block_hash IS NULL AND t2.block_hash IS NOT NULL"
SQL.query!(
Repo,
query,
[],
timeout: @timeout
)
end end
end end

@ -0,0 +1,23 @@
DO $$
DECLARE
start_time TIMESTAMP WITHOUT TIME ZONE := clock_timestamp();
end_time TIMESTAMP WITHOUT TIME ZONE;
elapsed_time INTERVAL;
temp_start_time TIMESTAMP WITHOUT TIME ZONE;
temp_end_time TIMESTAMP WITHOUT TIME ZONE;
BEGIN
RAISE NOTICE 'Started at %', start_time;
temp_start_time := clock_timestamp();
UPDATE transactions SET error = 'dropped/replaced', status = 0 FROM transactions t1
INNER JOIN transactions t2
ON t1.from_address_hash = t2.from_address_hash AND t1.nonce = t2.nonce
WHERE t1.block_hash IS NULL AND t2.block_hash IS NOT NULL;
end_time := clock_timestamp();
elapsed_time := end_time - start_time;
RAISE NOTICE 'Ended at %s', end_time;
RAISE NOTICE 'Elapsed time: %', elapsed_time;
END $$;
Loading…
Cancel
Save