diff --git a/priv/repo/migrations/20250704174406_optimize_map_queries.exs b/priv/repo/migrations/20250704174406_optimize_map_queries.exs index 40c1870..6a0f8d7 100644 --- a/priv/repo/migrations/20250704174406_optimize_map_queries.exs +++ b/priv/repo/migrations/20250704174406_optimize_map_queries.exs @@ -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]) diff --git a/priv/repo/migrations/20250711180558_add_weather_packets_index.exs b/priv/repo/migrations/20250711180558_add_weather_packets_index.exs new file mode 100644 index 0000000..6a06540 --- /dev/null +++ b/priv/repo/migrations/20250711180558_add_weather_packets_index.exs @@ -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