From 6f6f1757ea132a235fffdd43c6aeb6dba4a77140 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Thu, 26 Mar 2026 11:01:53 -0500 Subject: [PATCH] fix: handle existing index in deduplicate_discovery_checks migration (#179) - Drop index if exists before creating to handle manual creation - Prevents duplicate_table error when index was created manually Reviewed-on: https://git.mcintire.me/graham/towerops-web/pulls/179 --- .../migrations/20260325215632_deduplicate_discovery_checks.exs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/priv/repo/migrations/20260325215632_deduplicate_discovery_checks.exs b/priv/repo/migrations/20260325215632_deduplicate_discovery_checks.exs index f1a2a7c6..2298b64e 100644 --- a/priv/repo/migrations/20260325215632_deduplicate_discovery_checks.exs +++ b/priv/repo/migrations/20260325215632_deduplicate_discovery_checks.exs @@ -33,6 +33,9 @@ defmodule Towerops.Repo.Migrations.DeduplicateDiscoveryChecks do # Prevent future duplicates for auto-discovered checks. # Use concurrently: true to avoid locking table during index creation. + # Drop first if it exists (may have been created manually) + execute("DROP INDEX IF EXISTS checks_device_type_source_unique_index") + create( unique_index(:checks, [:device_id, :check_type, :source_id], where: "source_type = 'auto_discovery' AND source_id IS NOT NULL",