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

  def up do
    create table(:snmp_arp_entries, primary_key: false) do
      add :id, :binary_id, primary_key: true

      add :device_id, references(:devices, type: :binary_id, on_delete: :delete_all), null: false

      add :interface_id, references(:snmp_interfaces, type: :binary_id, on_delete: :delete_all),
        null: true

      add :ip_address, :string, null: false
      add :mac_address, :string, null: false
      add :entry_type, :string
      add :if_index, :integer
      add :last_seen_at, :utc_datetime, null: false

      timestamps(type: :utc_datetime)
    end

    create index(:snmp_arp_entries, [:device_id])
    create index(:snmp_arp_entries, [:device_id, :ip_address])
    create index(:snmp_arp_entries, [:mac_address])
    create unique_index(:snmp_arp_entries, [:device_id, :ip_address, :mac_address])
  end

  def down do
    drop table(:snmp_arp_entries)
  end
end
