defmodule DaProductApp.Repo.Migrations.CreateNetworkHealthEvents do use Ecto.Migration def change do create table(:network_health_events) do add :network_name, :string, null: false add :previous_status, :string, null: true # null for initial status add :current_status, :string, null: false add :status_changed_at, :utc_datetime, null: false add :error_reason, :text, null: true add :error_details, :map, null: true add :check_duration_ms, :integer, null: true add :consecutive_failures, :integer, default: 0 add :consecutive_successes, :integer, default: 0 add :network_config, :map, null: true # Snapshot of network config at time of event add :metadata, :map, null: true # Additional context data timestamps() end # Explicitly add AUTO_INCREMENT for MySQL execute "ALTER TABLE network_health_events MODIFY id BIGINT AUTO_INCREMENT" create index(:network_health_events, [:network_name]) create index(:network_health_events, [:current_status]) create index(:network_health_events, [:status_changed_at]) create index(:network_health_events, [:network_name, :status_changed_at]) # Index for finding latest status per network create index(:network_health_events, [:network_name, :inserted_at]) end end