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

  def change do
    create table(:ip_blocks, primary_key: false) do
      add :id, :binary_id, primary_key: true
      add :ip_address, :string, null: false
      add :offense_count, :integer, null: false, default: 1
      add :banned_until, :utc_datetime
      add :last_violation_at, :utc_datetime, null: false
      add :reason, :text

      timestamps(type: :utc_datetime)
    end

    create unique_index(:ip_blocks, [:ip_address])
    create index(:ip_blocks, [:banned_until])
    create index(:ip_blocks, [:last_violation_at])
  end
end
