Blockchain explorer for Ethereum based network and a tool for inspecting and analyzing EVM based blockchains.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
blockscout/apps/explorer/priv/repo/migrations/20181107164103_eip6.exs

41 lines
1.2 KiB

defmodule Explorer.Repo.Migrations.EIP6 do
@moduledoc """
Use `priv/repo/migrations/scripts/20181107164103_eip6.sql` to migrate data and validate constraint.
```sh
mix ecto.migrate
psql -d $DATABASE -a -f priv/repo/migrations/scripts/20181107164103_eip6.sql
```
"""
use Ecto.Migration
def up do
execute("ALTER TABLE internal_transactions DROP CONSTRAINT suicide_has_from_and_to_address_hashes")
# `NOT VALID` skips checking pre-existing rows. Use `priv/repo/migrations/scripts/20181107164103_eip6.sql` to
# migrate data and validate constraints
execute("""
ALTER TABLE internal_transactions
ADD CONSTRAINT selfdestruct_has_from_and_to_address
CHECK (type != 'selfdestruct' OR (from_address_hash IS NOT NULL AND gas IS NULL AND to_address_hash IS NOT NULL))
NOT VALID
""")
end
def down do
execute("ALTER TABLE internal_transactions DROP CONSTRAINT selfdestruct_has_from_and_to_address_hashes")
create(
constraint(
:internal_transactions,
:suicide_has_from_and_to_address_hashes,
check: """
type != 'suicide' OR
(from_address_hash IS NOT NULL AND gas IS NULL AND to_address_hash IS NOT NULL)
"""
)
)
end
end