defmodule DaProductApp.Repo.Migrations.CreateTransactionEventChain do use Ecto.Migration def change do create table(:transaction_event_chain) do add :transaction_id, :bigint, null: false add :event_type, :string, null: false add :event_ref_table, :string, null: false add :event_ref_id, :bigint add :prev_event_id, :bigint add :payload, :text timestamps() end create index(:transaction_event_chain, [:transaction_id]) create index(:transaction_event_chain, [:transaction_id, :inserted_at]) create index(:transaction_event_chain, [:prev_event_id]) create constraint(:transaction_event_chain, :transaction_fk, check: "transaction_id IS NOT NULL") end end