defmodule Towerops.Repo.Migrations.CreateAgentAssignments do
  use Ecto.Migration

  def change do
    create table(:agent_assignments, primary_key: false) do
      add :id, :binary_id, primary_key: true
      add :enabled, :boolean, default: true, null: false

      add :agent_token_id,
          references(:agent_tokens, type: :binary_id, on_delete: :delete_all),
          null: false

      add :equipment_id,
          references(:equipment, type: :binary_id, on_delete: :delete_all),
          null: false

      timestamps(type: :utc_datetime)
    end

    create index(:agent_assignments, [:agent_token_id])
    create unique_index(:agent_assignments, [:equipment_id])
    create index(:agent_assignments, [:enabled])
  end
end
