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

  def change do
    create table(:device_firmware_history, 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 :old_version, :string
      add :new_version, :string, null: false
      add :detected_at, :utc_datetime, null: false
      add :detection_method, :string

      timestamps(type: :utc_datetime, updated_at: false)
    end

    create index(:device_firmware_history, [:snmp_device_id, :detected_at])
    create index(:device_firmware_history, [:detected_at])
  end
end
