defmodule Berrypod.Repo.Migrations.AddProductsListingIndexes do
  use Ecto.Migration

  def change do
    # Composite covering index for the main listing query:
    # WHERE visible = 1 AND status = 'active' ORDER BY inserted_at DESC
    # Replaces the individual visible + status indexes for this pattern
    # and eliminates the TEMP B-TREE sort SQLite was doing.
    create index(:products, [:visible, :status, :inserted_at])

    # Filtered listing by category (second most common query pattern)
    create index(:products, [:visible, :status, :category])
  end
end
