diff --git a/apps/explorer/priv/repo/migrations/20181106152300_add_nonce_to_addresses.exs b/apps/explorer/priv/repo/migrations/20181106152300_add_nonce_to_addresses.exs new file mode 100644 index 0000000000..b6fd4f1594 --- /dev/null +++ b/apps/explorer/priv/repo/migrations/20181106152300_add_nonce_to_addresses.exs @@ -0,0 +1,31 @@ +defmodule Explorer.Repo.Migrations.AddNonceToAddresses do + use Ecto.Migration + + def up do + # Add nonce + alter table(:addresses) do + add(:nonce, :integer) + end + + # Populate nonce field from transactions table + # Commented out due to running time concerns + # execute(""" + # WITH t AS ( + # SELECT from_address_hash AS hash, MAX(nonce) AS nonce + # FROM transactions + # GROUP BY hash + # ) + # UPDATE addresses AS a + # SET nonce = t.nonce + # FROM t + # WHERE a.hash = t.hash + # """) + end + + def down do + # Remove nonce + alter table(:addresses) do + remove(:nonce) + end + end +end diff --git a/apps/explorer/priv/repo/migrations/201811061523_add_nonce_to_addresses.exs b/apps/explorer/priv/repo/migrations/201811061523_add_nonce_to_addresses.exs deleted file mode 100644 index cbdfe4b1b9..0000000000 --- a/apps/explorer/priv/repo/migrations/201811061523_add_nonce_to_addresses.exs +++ /dev/null @@ -1,30 +0,0 @@ -defmodule Explorer.Repo.Migrations.AddNonceToAddresses do - use Ecto.Migration - - def up do - # Add nonce - alter table(:addresses) do - add(:nonce, :integer) - end - - # Populate nonce field from transactions table - execute(""" - WITH t AS ( - SELECT from_address_hash AS hash, MAX(nonce) AS nonce - FROM transactions - GROUP BY hash - ) - UPDATE addresses AS a - SET nonce = t.nonce - FROM t - WHERE a.hash = t.hash - """) - end - - def down do - # Remove nonce - alter table(:addresses) do - remove(:nonce) - end - end -end