towerops/priv/repo/migrations/20260121163706_create_snmp_physical_entities.exs
Graham McIntire 45ddcdac80
feat: add physical inventory discovery (Phase 1.4)
- Create snmp_physical_entities table with migration
- Add PhysicalEntity schema with entity_class validation
- Support parent/child hierarchy via parent_entity_id
- Implement discover_physical_entities/1 in Base profile
- Discover chassis, modules, PSUs, fans from ENTITY-MIB
- Map entity class integers to string names
- Add 10 schema tests and 4 discovery tests
- Fix flaky AlertNotifier test with unique names and mailbox clearing
2026-01-21 10:46:27 -06:00

37 lines
1.3 KiB
Elixir

defmodule Towerops.Repo.Migrations.CreateSnmpPhysicalEntities do
use Ecto.Migration
def change do
create table(:snmp_physical_entities, 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 :entity_index, :integer, null: false
add :entity_class, :string, null: false
add :description, :string
add :model_name, :string
add :serial_number, :string
add :firmware_revision, :string
add :hardware_revision, :string
add :manufacturer_name, :string
add :position, :integer
add :last_checked_at, :utc_datetime
add :metadata, :map, default: %{}
# Self-referencing parent relationship for hierarchy
add :parent_entity_id,
references(:snmp_physical_entities, type: :binary_id, on_delete: :nilify_all)
timestamps(type: :utc_datetime)
end
create index(:snmp_physical_entities, [:snmp_device_id])
create unique_index(:snmp_physical_entities, [:snmp_device_id, :entity_index])
create index(:snmp_physical_entities, [:entity_class])
create index(:snmp_physical_entities, [:parent_entity_id])
create index(:snmp_physical_entities, [:serial_number])
end
end