defmodule Microwaveprop.Repo.Migrations.CreateContactEdits do
  use Ecto.Migration

  def change do
    create table(:contact_edits, primary_key: false) do
      add :id, :binary_id, primary_key: true

      add :contact_id, references(:contacts, type: :binary_id, on_delete: :delete_all),
        null: false

      add :user_id, references(:users, type: :binary_id, on_delete: :delete_all), null: false
      add :proposed_changes, :map, null: false
      add :status, :string, null: false, default: "pending"
      add :admin_note, :string
      add :reviewed_by_id, references(:users, type: :binary_id, on_delete: :nilify_all)
      add :reviewed_at, :utc_datetime

      timestamps(type: :utc_datetime)
    end

    create index(:contact_edits, [:contact_id])
    create index(:contact_edits, [:user_id])
    create index(:contact_edits, [:status])
  end
end
