43 lines
1.6 KiB
Elixir
43 lines
1.6 KiB
Elixir
defmodule Towerops.Repo.Migrations.DropUnusedCheckIndexes do
|
|
use Ecto.Migration
|
|
|
|
@disable_ddl_transaction true
|
|
@disable_migration_lock true
|
|
|
|
# These indexes have had 0 scans since stats reset (2026-03-08):
|
|
#
|
|
# - checks_source_type_index: superseded by the composite
|
|
# checks_source_type_source_id_index which covers all source_type queries
|
|
#
|
|
# - checks_enabled_index: queries that filter by enabled also filter by
|
|
# device_id or organization_id first, so the device_id/org index is used
|
|
#
|
|
# - checks_device_type_source_unique_index: unique partial index on
|
|
# (device_id, check_type, source_id) for auto_discovery rows; 0 scans
|
|
# since recreated in 20260325215632. NOTE: removes DB-level uniqueness
|
|
# enforcement for auto-discovery checks (Check changeset still validates).
|
|
|
|
def up do
|
|
execute "DROP INDEX CONCURRENTLY IF EXISTS checks_source_type_index"
|
|
execute "DROP INDEX CONCURRENTLY IF EXISTS checks_enabled_index"
|
|
execute "DROP INDEX CONCURRENTLY IF EXISTS checks_device_type_source_unique_index"
|
|
end
|
|
|
|
def down do
|
|
create_if_not_exists index(:checks, [:source_type],
|
|
name: :checks_source_type_index,
|
|
concurrently: true
|
|
)
|
|
|
|
create_if_not_exists index(:checks, [:enabled],
|
|
name: :checks_enabled_index,
|
|
concurrently: true
|
|
)
|
|
|
|
execute """
|
|
CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS checks_device_type_source_unique_index
|
|
ON checks (device_id, check_type, source_id)
|
|
WHERE source_type = 'auto_discovery' AND source_id IS NOT NULL
|
|
"""
|
|
end
|
|
end
|