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

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

      add :snmp_interface_id,
          references(:snmp_interfaces, type: :binary_id, on_delete: :delete_all),
          null: false

      add :ip_address, :string, null: false
      add :subnet_mask, :string
      add :prefix_length, :integer
      add :ip_type, :string, null: false, default: "ipv4"
      add :is_primary, :boolean, default: false
      add :last_checked_at, :utc_datetime
      add :metadata, :map, default: %{}

      timestamps(type: :utc_datetime)
    end

    create index(:snmp_ip_addresses, [:snmp_interface_id])
    create unique_index(:snmp_ip_addresses, [:snmp_interface_id, :ip_address])
    create index(:snmp_ip_addresses, [:ip_type])
    create index(:snmp_ip_addresses, [:is_primary])
  end
end
