From d68f0f2e08ca7bebac589b96bb3452cd55542965 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Wed, 30 Jul 2025 14:15:13 -0500 Subject: [PATCH] fix: Remove non-immutable NOW() function from index predicate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PostgreSQL requires functions in index predicates to be immutable. The NOW() function is not immutable, so we simplify the index to just order by received_at DESC without the WHERE clause. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../migrations/20250730185642_optimize_packet_queries.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/priv/repo/migrations/20250730185642_optimize_packet_queries.exs b/priv/repo/migrations/20250730185642_optimize_packet_queries.exs index 262bf04..bf83063 100644 --- a/priv/repo/migrations/20250730185642_optimize_packet_queries.exs +++ b/priv/repo/migrations/20250730185642_optimize_packet_queries.exs @@ -27,11 +27,11 @@ defmodule Aprsme.Repo.Migrations.OptimizePacketQueries do WHERE device_identifier IS NOT NULL """ - # Partial index for recent packets (last 7 days) - very useful for most queries + # Index for recent packets - using simple timestamp ordering + # Note: We can't use NOW() in the WHERE clause as it's not immutable execute """ CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_packets_recent_only ON packets(received_at DESC) - WHERE received_at > NOW() - INTERVAL '7 days' """ # Index for weather packet lookups by callsign