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

  def change do
    create table(:snmp_storage, 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 :storage_index, :integer, null: false
      add :storage_type, :string, null: false
      add :description, :string
      add :device_name, :string
      add :total_bytes, :bigint
      add :used_bytes, :bigint
      add :allocation_units, :integer
      add :last_checked_at, :utc_datetime
      add :metadata, :map, default: %{}

      timestamps(type: :utc_datetime)
    end

    create index(:snmp_storage, [:snmp_device_id])
    create unique_index(:snmp_storage, [:snmp_device_id, :storage_index])
    create index(:snmp_storage, [:storage_type])
  end
end
