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

  def change do
    create table(:snmp_mac_addresses, 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)
      add :mac_address, :string, null: false
      add :vlan_id, :integer
      add :port_index, :integer
      add :entry_status, :string
      add :last_seen_at, :utc_datetime, null: false

      timestamps(type: :utc_datetime)
    end

    create index(:snmp_mac_addresses, [:device_id])
    create index(:snmp_mac_addresses, [:interface_id])
    create index(:snmp_mac_addresses, [:mac_address])
    create unique_index(:snmp_mac_addresses, [:device_id, :mac_address, :vlan_id])
  end
end
