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

  def change do
    alter table(:checks) do
      # Track whether this check was auto-created from SNMP discovery or manually created
      add :source_type, :string

      # Reference to the source entity (sensor_id, interface_id, processor_id, storage_id)
      # Polymorphic foreign key - not enforced at DB level
      add :source_id, :binary_id
    end

    create index(:checks, [:source_type])
    create index(:checks, [:source_id])
    # Composite index for quickly finding checks by their source
    create index(:checks, [:source_type, :source_id])
  end
end
