defmodule DaProductApp.Repo.Migrations.CreateTransactionsPhase2 do use Ecto.Migration def change do create table(:transactions) do add :org_txn_id, :string, null: false add :parent_qr_validation_id, references(:qr_validations, on_delete: :nilify_all) add :payer_addr, :string add :payee_addr, :string add :payee_mid, :string add :payer_bank_ref, :string add :foreign_amount, :decimal, precision: 18, scale: 6 add :foreign_currency, :string, size: 3 add :fx_rate, :decimal, precision: 18, scale: 8 add :markup_pct, :decimal, precision: 7, scale: 4 add :inr_amount, :decimal, precision: 18, scale: 2 add :ver_token, :string add :network_inst_id, :string add :current_state, :string, null: false, default: "initiated" add :status, :string, null: false, default: "pending" add :debit_secured_at, :utc_datetime add :credit_requested_at, :utc_datetime add :credit_completed_at, :utc_datetime timestamps() end create unique_index(:transactions, [:org_txn_id]) create index(:transactions, [:ver_token]) create index(:transactions, [:current_state]) create index(:transactions, [:status]) create table(:transaction_events) do add :transaction_id, references(:transactions, on_delete: :delete_all), null: false add :seq, :integer, null: false add :event_type, :string, null: false add :payload, :map add :prev_hash, :binary add :hash, :binary, null: false add :inserted_at, :utc_datetime, null: false end create unique_index(:transaction_events, [:transaction_id, :seq]) create index(:transaction_events, [:event_type]) end end