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

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

      add :snmp_device_id, references(:snmp_devices, type: :binary_id, on_delete: :delete_all),
        null: false

      add :sensor_type, :string, null: false
      add :sensor_index, :string, null: false
      add :sensor_oid, :string, null: false
      add :sensor_descr, :string
      add :sensor_unit, :string
      add :sensor_divisor, :integer, default: 1, null: false
      add :monitored, :boolean, default: true, null: false
      add :last_value, :float
      add :last_checked_at, :utc_datetime

      timestamps(type: :utc_datetime)
    end

    create index(:snmp_sensors, [:snmp_device_id])
    create unique_index(:snmp_sensors, [:snmp_device_id, :sensor_index])
    create index(:snmp_sensors, [:sensor_type])
  end
end
