defmodule Microwaveprop.Repo.Migrations.CreateIemreObservationsAndAddIemreQueued do
  use Ecto.Migration

  def change do
    create table(:iemre_observations, primary_key: false) do
      add :id, :binary_id, primary_key: true
      add :lat, :float, null: false
      add :lon, :float, null: false
      add :date, :date, null: false
      add :hourly, {:array, :map}, default: []

      timestamps(type: :utc_datetime)
    end

    create unique_index(:iemre_observations, [:lat, :lon, :date])

    alter table(:qsos) do
      add :iemre_queued, :boolean, default: false, null: false
    end

    execute "UPDATE qsos SET iemre_queued = false", "SELECT 1"

    create index(:qsos, [:iemre_queued], where: "iemre_queued = false")
  end
end
