Current section

Files

Jump to
txbox priv templates migrations 2_create_txbox_mapi_responses.exs.eex
Raw

priv/templates/migrations/2_create_txbox_mapi_responses.exs.eex

defmodule <%= module_prefix %>.Repo.Migrations.CreateTxBoxMapiResponses do
use Ecto.Migration
def change do
# Create the Txbox MAPI Responses table
create table(:txbox_mapi_responses, primary_key: false) do
add :id, :binary_id, primary_key: true
add :type, :string
add :payload, :map
add :public_key, :string
add :signature, :string
add :verified, :boolean
add :tx_guid, references(:txbox_txns, type: :binary_id, on_delete: :delete_all)
timestamps(type: :utc_datetime_usec, updated_at: false)
end
# Add indexes
create index(:txbox_mapi_responses, [:tx_guid])
create index(:txbox_mapi_responses, [:inserted_at])
# Make adjustments to Txbox tx table
rename table(:txbox_txns), :id, to: :guid
alter table(:txbox_txns) do
remove :block_hash, :string
remove :mapi_attempt, :integer
remove :mapi_attempted_at, :utc_datetime
remove :mapi_completed_at, :utc_datetime
remove :status, :map
add :state, :string
end
create index(:txbox_txns, [:state])
# Set default state for existing txns
if direction() == :up do
flush()
Txbox.Transactions.repo().update_all(Txbox.Transactions.Tx, set: [state: "pending"])
end
end
end