From 42fce1b933591dbb2334ec4a116eaee0f8da66d4 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sat, 25 Oct 2025 16:54:10 -0500 Subject: [PATCH] Use runtime pool check instead of Mix.env for migration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mix.env() is not available in production releases, so we need to check the repo's pool configuration at runtime instead. In test, the pool is Ecto.Adapters.SQL.Sandbox which doesn't support CONCURRENTLY, so we skip index creation. In production/dev, indexes are created normally. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- ...20251025183718_add_callsign_search_indexes.exs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/priv/repo/migrations/20251025183718_add_callsign_search_indexes.exs b/priv/repo/migrations/20251025183718_add_callsign_search_indexes.exs index 0d14115..194eb13 100644 --- a/priv/repo/migrations/20251025183718_add_callsign_search_indexes.exs +++ b/priv/repo/migrations/20251025183718_add_callsign_search_indexes.exs @@ -1,10 +1,19 @@ defmodule Aprsme.Repo.Migrations.AddCallsignSearchIndexes do use Ecto.Migration + @disable_ddl_transaction true + @disable_migration_lock true def up do - # In test environment, skip index creation to avoid timeout issues - # Indexes will be created in production where the table has actual data - if Mix.env() != :test do + # Check if we're in a test environment by looking at the repo config + # In test, the pool is Ecto.Adapters.SQL.Sandbox which doesn't support CONCURRENTLY + pool_module = Aprsme.Repo.config()[:pool] + + if pool_module == Ecto.Adapters.SQL.Sandbox do + # Test environment - skip index creation to avoid timeout issues + # The test database is empty anyway + :ok + else + # Production/dev environment - create indexes with CONCURRENTLY # Add index on sender for pattern matching searches # Using text_pattern_ops for LIKE/ILIKE queries via raw SQL execute """