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

  def change do
    create table(:preseem_device_baselines, primary_key: false) do
      add :id, :binary_id, primary_key: true

      add :preseem_access_point_id,
          references(:preseem_access_points, type: :binary_id, on_delete: :delete_all),
          null: false

      add :metric_name, :string, null: false
      add :period, :string, null: false
      add :mean, :float
      add :stddev, :float
      add :p5, :float
      add :p95, :float
      add :sample_count, :integer
      add :computed_at, :utc_datetime, null: false
    end

    create index(:preseem_device_baselines, [:preseem_access_point_id])

    create unique_index(
             :preseem_device_baselines,
             [:preseem_access_point_id, :metric_name, :period],
             name: :preseem_device_baselines_ap_metric_period_idx
           )
  end
end
