optimize migrations
This commit is contained in:
parent
1b428cbf78
commit
6a97ba7e45
2 changed files with 19 additions and 9 deletions
|
|
@ -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, [:symbol_table_id, :symbol_code, :received_at])
|
||||||
create_if_not_exists index(:packets, [:device_identifier])
|
create_if_not_exists index(:packets, [:device_identifier])
|
||||||
create_if_not_exists index(:packets, [:region, :has_position, :received_at])
|
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
|
end
|
||||||
|
|
||||||
def down do
|
def down do
|
||||||
execute "DROP INDEX IF EXISTS packets_weather_idx"
|
|
||||||
drop index(:packets, [:region, :has_position, :received_at])
|
drop index(:packets, [:region, :has_position, :received_at])
|
||||||
drop index(:packets, [:device_identifier])
|
drop index(:packets, [:device_identifier])
|
||||||
drop index(:packets, [:symbol_table_id, :symbol_code, :received_at])
|
drop index(:packets, [:symbol_table_id, :symbol_code, :received_at])
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
Loading…
Add table
Reference in a new issue