Fix alerts page by migrating old equipment_* alert types to device_*

The Alert schema was updated to use :device_down and :device_up enum values,
but existing database records still had 'equipment_down' and 'equipment_up' values.

Added migration to update all existing alert records to use the new naming
convention.
This commit is contained in:
Graham McIntire 2026-01-17 17:15:18 -06:00
parent a6fb2ef833
commit 412086d7ec
No known key found for this signature in database

View file

@ -0,0 +1,15 @@
defmodule Towerops.Repo.Migrations.UpdateAlertTypesEquipmentToDevice do
use Ecto.Migration
def up do
# Update existing alert records from old "equipment_*" naming to "device_*" naming
execute("UPDATE alerts SET alert_type = 'device_down' WHERE alert_type = 'equipment_down'")
execute("UPDATE alerts SET alert_type = 'device_up' WHERE alert_type = 'equipment_up'")
end
def down do
# Revert back to old naming if needed
execute("UPDATE alerts SET alert_type = 'equipment_down' WHERE alert_type = 'device_down'")
execute("UPDATE alerts SET alert_type = 'equipment_up' WHERE alert_type = 'device_up'")
end
end