Add database indexes for weather data queries

- Add partial index on temperature column for weather stations
- Add compound index on received_at + temperature for time-based queries
- Add sender + temperature index for station-specific weather queries
- Add individual indexes on humidity, pressure, and wind_speed
- All indexes use WHERE clause to only include non-null values

These indexes will significantly improve performance for:
- Finding weather stations on the map
- Weather history queries
- Weather data filtering

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Graham McIntire 2025-07-21 14:07:08 -05:00
parent 1e51d58af5
commit 095289d6f0
No known key found for this signature in database

View file

@ -0,0 +1,26 @@
defmodule Aprsme.Repo.Migrations.AddWeatherIndexes do
use Ecto.Migration
def up do
# Index for finding stations with weather data
create index(:packets, [:temperature], where: "temperature IS NOT NULL")
# Compound index for time-based weather queries
create index(:packets, [:received_at, :temperature], where: "temperature IS NOT NULL")
# Additional weather-related indexes for common queries
create index(:packets, [:sender, :temperature], where: "temperature IS NOT NULL")
create index(:packets, [:humidity], where: "humidity IS NOT NULL")
create index(:packets, [:pressure], where: "pressure IS NOT NULL")
create index(:packets, [:wind_speed], where: "wind_speed IS NOT NULL")
end
def down do
drop index(:packets, [:temperature])
drop index(:packets, [:received_at, :temperature])
drop index(:packets, [:sender, :temperature])
drop index(:packets, [:humidity])
drop index(:packets, [:pressure])
drop index(:packets, [:wind_speed])
end
end