try to fix initial db migration

This commit is contained in:
Graham McIntire 2025-07-10 18:08:28 -05:00
parent 1a52bf4baf
commit 952cd40efe
No known key found for this signature in database
2 changed files with 23 additions and 1 deletions

View file

@ -5,8 +5,9 @@ defmodule Aprsme.Repo.Migrations.AddCountOptimizationIndex do
def up do
# Add a partial index on id that will be used for COUNT(*) queries
# This creates a small, fast index that PostgreSQL can use for counting
# Skip if already exists (from OptimizeInitialIndexCreation migration)
execute """
CREATE INDEX CONCURRENTLY IF NOT EXISTS packets_count_idx
CREATE INDEX IF NOT EXISTS packets_count_idx
ON packets (id)
WHERE id IS NOT NULL
"""

View file

@ -0,0 +1,21 @@
defmodule Aprsme.Repo.Migrations.OptimizeInitialIndexCreation do
use Ecto.Migration
@disable_ddl_transaction true
def up do
# Drop and recreate the count optimization index more efficiently
execute "DROP INDEX IF EXISTS packets_count_idx"
# Use a simpler approach - just create the index normally for initial setup
# The CONCURRENTLY option is mainly useful in production with live data
execute """
CREATE INDEX packets_count_idx
ON packets (id)
WHERE id IS NOT NULL
"""
end
def down do
execute "DROP INDEX IF EXISTS packets_count_idx"
end
end