towerops/lib/towerops/config_changes/config_change_event.ex
Graham McIntie 9e7ee5099d refactor: fix all credo strict issues, format all code, fix broken routes
- Fix broken route paths in dashboard (/discovery, /subscribers/trace, /config-changes)
- Fix insights empty state settings link (org-scoped route)
- Add underscores to all 86400 literals across 6 files
- Alphabetize aliases in search.ex and agent_channel.ex
- Extract changelog parser helper to reduce nesting
- Extract dashboard impact calculation to reduce nesting
- Refactor agent_channel config change detection (pattern match, extract function)
- Combine double Enum.reject into single call in trace.ex
- Fix line length in trace.ex search query
- Replace length/1 > 0 with != [] in trace_live
- Run mix format on all files
2026-02-13 19:34:40 -06:00

46 lines
1.3 KiB
Elixir

defmodule Towerops.ConfigChanges.ConfigChangeEvent do
@moduledoc """
Schema for config change events linking MikroTik backup diffs to time windows.
"""
use Ecto.Schema
import Ecto.Changeset
alias Towerops.Devices.MikrotikBackup
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "config_change_events" do
field :changed_at, :utc_datetime
field :diff_summary, :string
field :sections_changed, {:array, :string}, default: []
field :change_size, :integer, default: 0
belongs_to :device, Towerops.Devices.Device
belongs_to :organization, Towerops.Organizations.Organization
belongs_to :backup_before, MikrotikBackup
belongs_to :backup_after, MikrotikBackup
timestamps(type: :utc_datetime, updated_at: false)
end
def changeset(event, attrs) do
event
|> cast(attrs, [
:device_id,
:organization_id,
:backup_before_id,
:backup_after_id,
:changed_at,
:diff_summary,
:sections_changed,
:change_size
])
|> validate_required([:device_id, :organization_id, :changed_at])
|> foreign_key_constraint(:device_id)
|> foreign_key_constraint(:organization_id)
|> foreign_key_constraint(:backup_before_id)
|> foreign_key_constraint(:backup_after_id)
end
end