optimize migrations

This commit is contained in:
Graham McIntire 2025-07-11 13:06:49 -05:00
parent 1b428cbf78
commit 6a97ba7e45
No known key found for this signature in database
2 changed files with 19 additions and 9 deletions

View file

@ -12,18 +12,9 @@ defmodule Aprsme.Repo.Migrations.OptimizeMapQueries do
create_if_not_exists index(:packets, [:symbol_table_id, :symbol_code, :received_at])
create_if_not_exists index(:packets, [:device_identifier])
create_if_not_exists index(:packets, [:region, :has_position, :received_at])
# Add partial index for weather packets (this is valid)
execute """
CREATE INDEX CONCURRENTLY IF NOT EXISTS packets_weather_idx
ON packets (received_at DESC)
WHERE data_type = 'weather'
OR (symbol_table_id = '/' AND symbol_code = '_')
"""
end
def down do
execute "DROP INDEX IF EXISTS packets_weather_idx"
drop index(:packets, [:region, :has_position, :received_at])
drop index(:packets, [:device_identifier])
drop index(:packets, [:symbol_table_id, :symbol_code, :received_at])

View file

@ -0,0 +1,19 @@
defmodule Aprsme.Repo.Migrations.AddWeatherPacketsIndex do
use Ecto.Migration
@disable_ddl_transaction true
@disable_migration_lock true
def up do
# Add partial index for weather packets using CONCURRENTLY for better performance
execute """
CREATE INDEX CONCURRENTLY IF NOT EXISTS packets_weather_idx
ON packets (received_at DESC)
WHERE data_type = 'weather'
OR (symbol_table_id = '/' AND symbol_code = '_')
"""
end
def down do
execute "DROP INDEX IF EXISTS packets_weather_idx"
end
end